NAO实验6

基础实验 手臂与头部

整体流程图:

其中,Go to position StandInit的Block由右侧的姿势库拖拽出,而Robot dance的Block类型为时间轴

Dance Block 具体行为层:

中级实验 完成机器人舞

在基础实验的基础上完成.

这两个实验最重要的是知道行为层可以将各个行为分开,并且在不影响其他行为下,改变某一个行为.

高级任务 绕圈走

其中,Walk Python的代码为:

import math
import time

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)
        self.motionProxy = ALProxy("ALMotion")
        
    def simplifyAngle(self, theta):
        while(theta > math.pi):
            theta -= 2*math.pi
        while(theta < -math.pi):
            theta += 2*math.pi
        return theta
        
    def updateTheta(self, previousTheta, theta):
        nextTheta = self.motionProxy.getRobotPosition(False)[2]
        theta += self.simplifyAngle(nextTheta - previousTheta)
        return (theta, nextTheta)

    def onLoad(self):
        #put initialization code here
        pass

    def onUnload(self):
        #put clean-up code here
        pass

    def onInput_onStart(self):
        #self.onStopped() #activate the output of the box
        self.motionProxy.setWalkArmsEnabled(True, True)
        globalTheta = self.motionProxy.getRobotPosition(False)[2]
        theta = 0
        rotationSpeed = 0.25   #range from -1 to 1
        
        #Walk in a circle
        while(abs(theta) < 2*math.pi):
            #Update the rotation odometry
            (theta, globalTheta) = self.updateTheta(globalTheta, theta)
            #Walk in an arc
            self.motionProxy.setWalkTargetVelocity(0.5, 0.0, rotationSpeed, 1.0)
            #wait for some time
            time.sleep(0.1)
        
        self.motionProxy.setWalkTargetVelocity(0.0, 0.0, 0.0, 1.0)
        
        self.onStopped() #~ activate output of the box
        

    def onInput_onStop(self):
        self.onUnload() #it is recommended to reuse the clean-up as the box is stopped
        self.onStopped() #activate the output of the box

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值