NAO实验5

基础实验 亮灯

通过NAO脚上的Left Bumper 和 Right Bumper 实现 眼镜LED颜色的显示

中级实验:状态转换

有限状态机(FSM)

状态 条件 动作

实验

状态机

 其中,Ears on eye 具体为:

这是一个有限状态机,

      4个状态 : 包括(耳朵开和眼睛颜色A),(耳朵开和眼睛颜色B),(耳朵关和眼睛颜色A)以及(耳朵关和眼睛颜色B)

      条件和动作为: 当Left Bumper时 switch color

                                当Right Bumper时 switch ear

中级实验:监测感官

软件Monitor主要是监测NAO的传感器数据和摄像头,目前用的是虚拟机器人,无法监测虚拟机器人...

高级实验:好点子

使用NAO头上三个按钮切换八个眼睛LED颜色状态

其中,Eye Light Blend的代码为:

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)
        self.leds = ALProxy("ALLeds")
        self.blue = True
        self.red = False
        self.green = False

    def onLoad(self):
        #put initialization code here
        self.done = False

    def onUnload(self):
        #put clean-up code here
        self.done = True

    def onInput_onStart(self):
        while(not self.done):
            #self.onStopped() #activate the output of the box
            color = 0
            if self.blue:
                color = color | 0x0000FF
            if self.green:
                color = color | 0x00FF00
            if self.red:
                color = color | 0xFF0000
            self.leds.fadeRGB("FaceLeds", color, 0.1)

    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

    def onInput_red(self):
        self.red = not self.red

    def onInput_green(self):
        self.green = not self.green

    def onInput_blue(self):
        self.blue = not self.blue

高级实验:魔镜魔镜

将一只手臂做出的动作映射到另外一只手臂

其中,Mirror Joint的代码为:

import time

class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)
        self.motion = ALProxy("ALMotion")
        self.done = False
        self.stiff = ['RShoulderPitch', 'RShoulderRoll', 'RElbowYaw', 'RElbowRoll']
        self.unstiff = ['LShoulderPitch', 'LShoulderRoll', 'LElbowYaw', 'LElbowRoll']
        self.origStiffness = self.motion.getStiffnesses(self.unstiff)

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

    def onUnload(self):
        #put clean-up code here
        self.done = True
        self.motion.setStiffnesses(self.unstiff, self.origStiffness)

    def onInput_onStart(self):
        #self.onStopped() #activate the output of the box
        self.motion.setStiffnesses(self.unstiff, 0.0)
        self.done = False
        while(not self.done):
            vals = self.motion.getAngles(self.unstiff, True)
            vals[1] = -vals[1]
            vals[2] = -vals[2]
            vals[3] = -vals[3]
            self.motion.setAngles(self.stiff, vals, 0.5)
            time.sleep(0.1)

    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、付费专栏及课程。

余额充值