NAO race

Can you program a simulated NAO robot in Python to achieve a world record performance on a 10 meters race?

If so, you may be able to win a trip to Hawaii... Register now at contest.theconstructsim.com.

You can try to program the robot in Python from here.

Also it is possible to run this NAO race simulation directly in Webots from this Webots project file: nao_race.zip. Please note that you will need a license of Webots (the 30 day trial license may be used for this) and you will have to compile the race_stopwatch C controller to enable the stopwatch.

How to make the NAO robot walk faster?

If you look at the Python program controlling the NAO robot, you will see that this program simply plays a motion file called forward.motion:

  def run(self):
    walk = Motion('forward.motion')
    walk.setLoop(True)
    walk.play()
    while True:
      if walk.getTime() == 1360:
        walk.setTime(360)
      if self.step(self.timeStep) == -1:
        break

The motion lasts 1360 milliseconds (1,36 seconds) and is divided in two parts: the first part lasts 360 ms and moves the robot from the initial position to the pose corresponding to the beginning of the walk cycle. The second part is the walk cycle which lasts 1000 ms and should be repeated forever. Therefore the controller will check when the motion is over (motion time reaches 1360 ms) and it will restart the walk cycle of the motion, i.e., it will reset the motion time to 360 ms, so that a new walk cycle is started. This will be repeated again and again, so that the robot will walk forever.

The motion file contains the joint positions (in radians) for each articulation of the legs which are used in the walking motion:

#WEBOTS_MOTION

V1.0

LHipRoll

LHipPitch

LKneePitch

LAnklePitch

LAnkleRoll

RHipRoll

RHipPitch

RKneePitch

RAnklePitch

RAnkleRoll

00:00:000

0

-0.034

-0.518

1.047

-0.529

0.034

-0.034

-0.518

1.047

-0.529

0.034

00:00:040

1

-0.044

-0.516

1.045

-0.53

0.044

-0.044

-0.516

1.045

-0.53

0.044

00:00:080

2

-0.063

-0.51

1.041

-0.531

0.063

-0.063

-0.51

1.041

-0.531

0.063

00:00:120

3

-0.08

-0.505

1.036

-0.531

0.08

-0.08

-0.505

1.036

-0.531

0.08

00:00:160

4

-0.101

-0.498

1.029

-0.531

0.101

-0.101

-0.498

1.029

-0.531

0.101

00:00:200

5

-0.136

-0.482

1.013

-0.531

0.136

-0.136

-0.482

1.013

-0.531

0.136

00:00:240

6

-0.157

-0.468

0.999

-0.531

0.157

-0.157

-0.468

0.999

-0.531

0.157

00:00:280

7

-0.173

-0.454

0.987

-0.533

0.173

-0.174

-0.459

0.996

-0.537

0.174

00:00:320

8

-0.15

-0.44

0.984

-0.544

0.19

-0.197

-0.52

1.119

-0.599

0.197

00:00:360

9

-0.144

-0.442

0.999

-0.557

0.196

-0.211

-0.605

1.244

-0.639

0.211

00:00:400

10

-0.146

-0.452

1.033

-0.582

0.198

-0.223

-0.743

1.374

-0.631

0.223

00:00:440

11

-0.142

-0.454

1.051

-0.597

0.195

-0.219

-0.803

1.378

-0.575

0.219

00:00:480

12

-0.134

-0.447

1.056

-0.609

0.187

-0.205

-0.815

1.313

-0.498

0.205

00:00:520

13

-0.121

-0.427

1.045

-0.618

0.174

-0.184

-0.777

1.202

-0.425

0.184

00:00:560

14

-0.128

-0.379

1.011

-0.632

0.145

-0.147

-0.678

1.037

-0.36

0.147

00:00:600

15

-0.119

-0.344

0.99

-0.646

0.119

-0.119

-0.634

1

-0.366

0.119

00:00:640

16

-0.065

-0.293

0.97

-0.677

0.065

-0.065

-0.604

1.022

-0.417

0.065

00:00:680

17

-0.019

-0.253

0.948

-0.696

0.019

-0.019

-0.579

1.033

-0.453

0.019

00:00:720

18

0.029

-0.204

0.913

-0.709

-0.029

0.029

-0.547

1.033

-0.486

-0.029

00:00:760

19

0.094

-0.124

0.838

-0.714

-0.094

0.094

-0.489

1.014

-0.525

-0.094

00:00:800

20

0.126

-0.096

0.828

-0.733

-0.126

0.12

-0.451

0.993

-0.542

-0.125

00:00:840

21

0.153

-0.142

0.934

-0.792

-0.153

0.108

-0.424

0.983

-0.559

-0.147

00:00:880

22

0.186

-0.337

1.196

-0.859

-0.186

0.117

-0.412

0.99

-0.578

-0.169

00:00:920

23

0.199

-0.508

1.335

-0.827

-0.199

0.124

-0.42

1.008

-0.589

-0.177

00:00:960

24

0.201

-0.661

1.384

-0.722

-0.201

0.126

-0.432

1.03

-0.599

-0.178

00:01:000

25

0.184

-0.763

1.278

-0.515

-0.184

0.117

-0.435

1.047

-0.612

-0.17

00:01:040

26

0.164

-0.739

1.148

-0.409

-0.164

0.105

-0.418

1.038

-0.62

-0.157

00:01:080

27

0.14

-0.683

1.039

-0.356

-0.14

0.122

-0.387

1.017

-0.63

-0.139

00:01:120

28

0.099

-0.628

1.006

-0.378

-0.099

0.099

-0.334

0.988

-0.654

-0.099

00:01:160

29

0.062

-0.608

1.022

-0.414

-0.062

0.062

-0.299

0.974

-0.675

-0.062

00:01:200

30

-0.007

-0.566

1.034

-0.468

0.007

-0.007

-0.233

0.935

-0.702

0.007

00:01:240

31

-0.055

-0.53

1.029

-0.499

0.055

-0.055

-0.181

0.892

-0.712

0.055

00:01:280

32

-0.095

-0.49

1.014

-0.524

0.095

-0.095

-0.126

0.839

-0.714

0.095

00:01:320

33

-0.121

-0.452

0.993

-0.541

0.126

-0.127

-0.097

0.83

-0.732

0.127

00:01:360

34

-0.105

-0.417

0.982

-0.565

0.157

-0.166

-0.194

1.018

-0.824

0.166


The forward.motion file can be opened in a spreadsheet software such a LibreOffice Calc or Excel, modified and saved again.

The nao_race.zip file contains a simplified motion file and corresponding Python controller allowing the NAO robot to achieve a better performance than the default controller provided on The Construct. It also contains a LibreOffice Calc file called forward.ods that makes it easier to vizualise and edit the motion file. The motion file was simplified by removing the first 15 poses (which are useless and prevent the robot from starting walking right away). Also the RHipYawPitch and LHipYawPitch joints were removed from the motion file as they are not used.

In order to further improve the walk speed, you can try to:

  • Further reduce the approach phase.
  • Change the time step of the motion file to make it faster (e.g., reduce the 40 milliseconds time step).
  • Modify the motion file values by hand.
  • Move the arms of the robot (in front to hit the finish sensor earlier or balancing to try to walk faster).
  • Create equations for each joint using the mathematical sinus function (or splines) that approximate the current trajectories. Then, you will be able to control each motor individually from the Python controller using your equations (you won't need the forward.motion file any more). Instead you will use directly the setPosition() method for each motor. This will allow you to fine tune the equations parameters to try to improve the motion.
  • Use the gyro and accelerometer of the robot to create a closed loop motion using advanced control techniques.
  • Use advanced research such as Zero Moment Point (ZMP), Central Pattern Generator (CPG), or Genetic Algorithms (GA) to create a faster walk.

Good luck !