0

だから私はPythonのコードを持っていて、それをNAO(Aldebaran Robotics)で動作させようとしています

import time
class MyClass(GeneratedClass):
    def __init__(self):
        GeneratedClass.__init__(self)
        self.motion = ALProxy("ALMotion")
        self.maxTour = 3
        self.reponse = False

    def onLoad(self):
        #~ puts code for box initialization here
        self.tournerDroite()
        time.sleep(5)
        #detect ball
        self.tournerCentre()
        time.sleep(5)
         #detect ball
        self.turnLeft()
         #detect ball
        #self.notInCenter()
        #self.redBall()
        pass

    def onUnload(self):
        #~ puts code for box cleanup here
        pass

    def onInput_onStart(self, ):
        #~ self.onStopped() #~ activate output of the box
        pass

    def onInput_onStop(self):
        self.onUnload() #~ it is recommanded to call onUnload of this box in a onStop method, as the code written in onUnload is used to stop the box as well
        pass

    def turnRight(self):
        self.motion.setStiffnesses("HeadYaw", 0)
        self.motion.setAngles("HeadYaw", -0.5, 0.05)
        self.motion.setStiffnesses("HeadYaw", 1)
        pass
    def turnLeft(self):
        self.motion.setStiffnesses("HeadYaw", 0)
        self.motion.setAngles("HeadYaw", 0.5, 0.05)
        self.motion.setStiffnesses("HeadYaw", 1)
        pass
    def turnCenter(self):
        self.motion.setStiffnesses("HeadYaw", 0)
        self.motion.setAngles("HeadYaw", 0, 0.05)
        self.motion.setStiffnesses("HeadYaw", 1)
        pass

    def notInCenter(self):
        if(self.motion.getAngles("HeadYaw", True) != 0):
            self.turnCenter()
            return True
        else:
            return False
        pass

    def redBall(self):
        while self.reponse == False:
            self.turnRight()
            time.sleep(5)
            #detect ball

            self.turnCenter()
            time.sleep(5)
             #detect ball
            self.turnLeft()
             #detect ball
        pass

問題は、onLoad()では、ロボットの回転が頭を右、中央、左の順になっていることですが、を使用するとredBall()、そうではなく、右と中央を回転して前後に移動します。

4

2 に答える 2

0

setStiffnesses を逆の方法で使用しているようです: 0 はモーターから電力を取り除き、1 は電力を設定します。

そのため: self.motion.setStiffnesses("HeadYaw", 0) self.motion.setAngles("HeadYaw", -0.5, 0.05) self.motion.setStiffnesses("HeadYaw", 1)

電源を切ってから頭を回しますが、電源がないので何もしないで、電源を設定します => 何もしません

于 2013-05-29T08:27:37.187 に答える
0

time.sleep(5)の後self.turnLeft()にあるはずredBallです。

turnLeft を呼び出すと、ループはすぐに続行され、turnRight が再度呼び出されます。つまり、左に曲がる時間がありません。そのため、右と中央のターンは行いますが、左へのターンは行いません。

于 2012-04-04T13:51:19.930 に答える