Welcome to Robot Rebels, an online robot maker community.

Register today to post your projects, ask questions, share knowledge and meet like-minded people from around the world.

The Community

Author Topic: Commissioning a Nano Leg Module  (Read 444 times)


  • Member
  • ****
  • B
  • Posts: 13
Commissioning a Nano Leg Module
« on: November 28, 2017, 11:42:31 AM »

•   For each motor rotation is calibrated in degrees and the origin is set.

•   A gait pattern and lookup strings are calculated using an IK macro.

•   Setpoints are sent to each module and actual angles are reported back and shown on screen.

•   Graphs of actual angle versus theoretical show good correlation.

•   A short video was made of the modules under test.

I make extensive use of Excel spreadsheets to minimise the drudgery of these processes. However, as Erco has made me realise, not everyone has the means of running the program so only screenshots will be shown here. With care you can obtain a legitimate second-hand CD and key for around £10.


Commissioning is perhaps the most tedious part of robot building. After the construction of the body and limbs, fitting the servos and wiring up all the electronics it still won’t move until instructed. Strictly the next stages are calibration and then gait pattern generation - but often these two get combined.

As an example, I once used a TV remote to address each of 12 servos in turn to position them by entering a number 75-255. Each ‘posture’ was painstakingly recorded and added to so that a sequence of moves could be performed. All went well until a motor failed and had to be replaced. The bot then moved with a limp!

It is easy to spend a lot of time building up the patterns of movement and this work should not have to be redone if the physical parameters change. So we have to define a common interface suited to the bot and its special needs, and then generate the movement instructions for that interface.

Depending on the microprocessor capabilities it may be possible to do this with standard pulse width controlled servos. That number 75-255 suggests 180 degrees, but they are not degrees, and 0 is not defined either. Calibration may involve sending pulse widths within the 10µS ‘boundaries’ to convert real degrees to servo position.


Using a Nano to control four motors in a leg module makes the calibration process simpler. With the 12 volt power turned off, the motors can be turned by hand and their angular position shown on the console. The feedback pot has stabilised 5V across it and the wiper connects to an analogue input. Without dismantling the bot it may be sufficient to hold a protractor against each motor whilst turning it and noting the ADC values.

However, it is much more accurate to disconnect each joint in turn, and fit onto the motor spline a protractor fixed to a servo horn. I use part of a CD case marked indelibly with 15-degree segments. Turning the motor with this attachment, the values 0-1023 displayed for each segment are entered directly into a spreadsheet sharing the screen. It doesn’t matter where the measurements start, just note the value every 15 degrees.

Spreadsheets have a lot of features to help with calibration. First the entries are graphed to show the non-linearity of the pot. This is a gentle curve so a real kink is probably an entry error.

Next Excel can fit a trendline to the graph and display its equation in a text box. This is a second order polynomial in the form y = ax2 + bx + c. We can then copy the three coefficients from the text box and paste them into cells for further calculation. The leg Nano now has the ability to translate from ADC pot values into degrees. Reconnecting the motor to the joint we can note the ADC value at a reference point, eg when the knee is straight. Enter this value and the spreadsheet will convert to degrees-of-offset for the translation.

*Cal3.JPG (38.26 kB . 684x330 - viewed 100 times)

Note that each motor angular calibration will not need to be repeated and is held on record in the spreadsheet documentation. If re-positioned on the spline, only the reference value may need to change.

When the leg data is complete, the spreadsheet helpfully provides all the CSV strings for pasting across to the Arduino code. No pencil required!

*Cal4.JPG (62.62 kB . 812x415 - viewed 96 times)
Here are two such leg modules, combined to form the hind part of a quadruped and weighing 600g. It will be fitted with training wheels to test movement but first it is hoisted onto a stand for the rotational measurements.

Hind Part.jpg
*Hind Part.jpg (72.28 kB . 1000x562 - viewed 99 times)

Digitigrades like cats, dogs and even birds walk on their fingers and toes. The foot is lengthened so the heel appears to be a wrong facing knee. In nature the increased leg length gives a higher top speed and the Z-shaped leg folds up nicely to let the trailing foot move forward over rough terrain.

Starting at the heel (H), zero degrees is when the foot is in line with the tibia. The construction here is rigid and the motors are blocky so 135 degrees is the most it can rotate. Similarly for the knee (K).

Third motor up is the main forward/backward drive and I think of it as pitch at the hip (P). Animals are narrow across the hips and suspending this main motor under the chassis mounted motor keeps all in line one above the other. 60 degrees is when the femur is vertical, zero will be close to the body.

The chassis motor is mounted 40 degrees to the horizontal. This combines the roll and rotate functions at the hip (R). Performance changes with geometry so it is not perfect but does save a drive motor. 60 degrees is when the bot would walk straight ahead, moving the limb outwards to the side would increase the reported angle. The other leg limits movement here so there is a less usable range.

Gait Pattern Generation

This subject has been covered separately before. Here is the Excel IK macro running a creep walk - where only one leg is off the ground at a time. This means each leg must spend only 25% of the cycle time in returning to the start position.

*Xgait2.gif (195.98 kB . 705x392 - viewed 103 times)

The input to the calculation is just the position of the toe in 20 frames. So when y = 0 the toe is on the ground. To the left or right of the hip is given by the x value.
*Toe.JPG (9.4 kB . 400x128 - viewed 99 times)

The macro button calculates all the angles needed to have the toe at the target positions in all the frames. The second hind leg is shown here running 50% out of phase. The forelegs are also shown using a slightly different IK calculation but phased in the usual sequence used by all quadrupeds.

This is offline Inverse Kinematics. It is not necessary to provide every motor angle – just feed in the ‘toe pattern’ and the spreadsheet will sort the answers.


The i2c master sends setpoint angles as four bytes to each i2c slave module. The master can also read back the actual current positions as determined from the ADC values.  Excel can cope with the 3200 values obtained below and show the walk data for any motor. A major difference between input and output can highlight a sticking gearbox for example.

*Tele.JPG (22.64 kB . 449x239 - viewed 53 times)

This is a comparison of the heel and pitch motors of one leg. The staircase effect is because the setpoint data is repeated four times to control the speed. The motors follow in time as best they can. A change of slope shows a variation of speed under load but the overall result is that the motors can keep up.


The hind leg modules are attached to a ‘bits box’ containing the i2c master, 1000 mAH 3C lipo and 5V UBEC. The training wheels are heavily weighted to maintain stability. All up weight is now 1.3kg so the motors have real work to do.

The four-legged gait is incomplete here, the front legs will provide additional drive at all times.


Copying computer-generated angles into Arduino code and executing the expected movement is encouraging. However, using widely spaced training wheels does mask all problems of balance. The inset to the moving Excel graph shows the theoretical ‘triangle of support’ as the gait progresses. Marginally unstable in only a couple of frames the bot should stand safely in most of the poses. But as soon as a dozen motors start to move then the centre of mass will change and momentum and external disturbances will upset the balance.

Further development will need 3D IK to position the toes laterally; the unusual setting of the roll/rotate motor will make for interesting trigonometry. Then the IK calculation must move into the bot itself so it can respond dynamically to input from an IMU or other sensors.


* Search

* Recent Topics

SoloLearn by Bajdi
[March 16, 2018, 10:15:14 AM]

Tiny function generator by ossipee
[March 14, 2018, 05:03:05 PM]

MKS GEN L Servo Issue by jinx
[March 06, 2018, 03:58:34 AM]

ROS Breakthrough by maelh
[March 05, 2018, 08:15:40 PM]

Post your last purchase. by Impala
[March 05, 2018, 02:47:58 PM]

MKS Gen L 1.0 by jinx
[March 04, 2018, 08:41:28 AM]

Robots & Lasers by ZeroMax
[February 23, 2018, 07:58:33 PM]

Hello from HITBOT - a young robot arm team by jinx
[February 22, 2018, 02:26:52 AM]

Assemble by Santiago
[February 06, 2018, 02:40:47 AM]

Ebot SL by erco
[January 30, 2018, 07:51:34 PM]

Simple One-Servo Walker by erco
[January 28, 2018, 09:00:22 PM]

Bob's gone Wood by erco
[January 28, 2018, 08:57:31 PM]

Welcome to the model section by jinx
[January 20, 2018, 10:11:40 AM]

syncthing - true p2p directory sync by mogul
[January 18, 2018, 03:21:49 PM]

Youtube by Impala
[January 18, 2018, 01:36:26 PM]

* Recent Posts

Re: SoloLearn by Bajdi
[March 16, 2018, 10:15:14 AM]

Tiny function generator by ossipee
[March 14, 2018, 05:03:05 PM]

SoloLearn by jinx
[March 09, 2018, 06:52:23 AM]

Re: MKS GEN L Servo Issue by jinx
[March 06, 2018, 03:58:34 AM]

Re: ROS Breakthrough by maelh
[March 05, 2018, 08:15:40 PM]

Re: MKS GEN L Servo Issue by Smashley
[March 05, 2018, 05:59:36 PM]

Re: MKS GEN L Servo Issue by huwmcgregor
[March 05, 2018, 05:14:39 PM]

Re: Post your last purchase. by Impala
[March 05, 2018, 02:47:58 PM]

Re: Post your last purchase. by ossipee
[March 05, 2018, 10:52:56 AM]

Re: Post your last purchase. by Impala
[March 04, 2018, 10:27:22 PM]

Re: Post your last purchase. by ZeroMax
[March 04, 2018, 09:00:27 PM]

Re: Post your last purchase. by jinx
[March 04, 2018, 08:48:25 AM]

Re: MKS Gen L 1.0 by jinx
[March 04, 2018, 08:41:28 AM]

Re: Post your last purchase. by Impala
[March 04, 2018, 08:23:48 AM]

Re: MKS Gen L 1.0 by cristi.istrate
[March 04, 2018, 07:48:59 AM]