pythoncontrollernao-robotwebotsnaos-project

Webots NAO controller sequence not working


I am using the NAO_demo_python controller of the latest version of webots on linux (ubuntu 18) to flash leds and open/close the hands.

However only the last part of the sequences are executed, and not in a single simulation run.

e.g. if i ask to just open the hand and light the leds, after 1 run the lights will be on and after 5 runs of the main while loop it will be opened -reaaallly slowly-. However if i ask lit leds, open hand then close hand unlit leds then the simulation will only close hand and unlit leds. The code should be working, it is on another person's computer. In case you want it here it is (it's really basic, it's a slight modification of nao-demo-python.py):

def run(self):
    while robot.step(self.timeStep) != -1:
        self.setAllLedsColor(0xff0000) #red leds on
        self.setHandsAngle(0.96)   #open hand
        #rospy.sleep(5)  #originally i am to use webots and nao with ros
        print("done") #to check how many runs are made
        self.setHandsAngle(0.0) #close hand
        self.setAllLedsColor(0x000000) #red leds off

Also, something that may be interesting: if i ask to open close the hand N times and each time print something, all the prints will be printed at once and the simulation time jump from 0:0:0 to 0:0:20 after each main loop run (+20 at each run), else, even if the simulation runs the time doesn't flow, it jumps.

I tried to update my drivers, to take off all shadows and stuff from the simulation, as webots advices. No can do. I couldn't find something on Softbank, i can't find an active forum concerning nao and webots anymore...

I have an i5 9th gen and a GTX1050Ti.

May the problem be that the simulation time isn't 1.0x? but at most 0.05x? (after taking off shadows, effect of lights, all objects, using 1 thread etc, as explained here: https://www.cyberbotics.com/doc/guide/speed-performance)

SUMMARY: Only the last sequence of the controller is executed, and if it's a motion it takes several main loops before being fully executed. Meanwhile the time jumps from 0 to +20s after each main loop run.

May someone help me out to make all the sequence work on simulation please :)


Solution

  • all the prints will be printed at once

    Only the last sequence of the controller is executed

    It sounds like the setHandsAngle function might be asynchronous (doesn't wait for the hand to move to that point before running the next piece of code)? This could be responsible for at least some of the problems you're experiencing. In this case the rospy.sleep(5) should be replaced with robot.step(5000), so the simulator has time to move the hand before sending the next command.