0

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 :)

2 Answers2

1

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.

Community
  • 1
  • 1
Dominic D
  • 1,778
  • 2
  • 5
  • 12
  • I used rospy.sleep without success (even with insanely long wait). However i didn't know of robot.step which works!!! Thank you! Now the actions are fully executed. Could it be a problem of wrong synchronization between Ros and webots? – my_name_is_D May 09 '20 at 09:10
  • 1
    Thanks to @David Mansolino for the info about using `robot.step()` to pause. Yes, basically the simulation will only advance when you call `robot.step()`. Ideally, a better workflow would be to sense when the hand gets to the goal location, and only then continue with the code. Something like `while handNotAtGoalAngle(): robot.step(self.timeStep)`. You can find more info about timestepping (particularly synchronisation) [here](https://github.com/cyberbotics/webots/blob/master/docs/reference/robot.md). – Dominic D May 09 '20 at 11:07
  • Thank you very much for this helpful link! However if motion.isOver() would indeed be optimal (but it seems moving hand isn't a motion but a robot movement?) i can't use it. I don't know how to check the completion of the movement! Could you tell me more about it? – my_name_is_D May 10 '20 at 11:35
  • I'm not sure specifically (do have have a link to the webots pepper API you're using?). But are you able to get the position of the hands through a function, or is there a sensor for it? In that case you would just wait until the position of the hand gets within a certain tolerance of the goal you have set. – Dominic D May 10 '20 at 11:48
  • 1
    I found out I can create a motion with `self.OpenHand = Motion('../namefile.motion')` then to open the end you need to use `LPhalanx1` (to 8) and same with other hand. Then you can call the motion and check if the motion is over with `isOver()`. Just found out the phalanges name now (by chance, i can't find a full list of all NAO motors on webots!). I'm using webots API for the moment, the NAO API doesn't seem to be recognized by webots (python SDK)! – my_name_is_D May 10 '20 at 13:18
0

Thank to your indications, this works:

self.CloseHand = Motion('../../motions/closeHand.motion') 

def startMotion(self, motion): 

    if self.currentlyPlaying: #interrupt current motion 
        self.currentlyPlaying.stop() 

    motion.play() #start new motion 
    self.currentlyPlaying = motion 


self.startMotion(self.CloseHand) 
while not self.CloseHand.isOver(): 
    robot.step(self.timeStep)

And in the CloseHand.motion :

#WEBOTS_MOTION,V1.0,LPhalanx1,RphalanxN (until 9)
00:00:000,Pose1,0.00,0.00 etc

with 00:00:000 the moment of execution and 0.00 the angle of the hand (phalanx by phalanx).

THANK you very much! I couldn't have realized that without your advice.

The synchronization webots/ros is still unresolved but the issue of my initial question is. Thank you!