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 1008 times)


  • Member
  • ****
  • B
  • Posts: 15
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 169 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 168 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 173 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 183 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 169 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 127 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

Web TIme API - by Gareth
[December 07, 2018, 04:34:37 PM]

API Directory by Gareth
[December 06, 2018, 03:34:16 PM]

The Original Prusa I3 Mk3 by tinhead
[November 30, 2018, 02:49:52 PM]

Email notifications by CraigCox
[November 28, 2018, 10:26:06 PM]

And another one. by CraigCox
[November 28, 2018, 10:17:54 PM]

MKS Gen L 1.0 by jinx
[November 28, 2018, 02:23:50 AM]

This kids a freaking genius by ossipee
[November 21, 2018, 04:55:40 PM]

Time of Flight >>> Rounded Corners !!! by Gareth
[November 15, 2018, 03:21:51 PM]

Double_ing up the "Time of Flight" sensors by Gareth
[November 13, 2018, 04:05:02 AM]

Point cloud anyone !!! maybe 3D scanner by maelh
[November 11, 2018, 05:38:33 AM]

removable magnetic print surface by Gareth
[November 09, 2018, 10:53:45 AM]

Robot Cop by Valeriex
[November 07, 2018, 05:48:20 AM]

it's lukeyes by Valeriex
[November 07, 2018, 05:47:16 AM]

TOF gets a local DEBUG screen by Gareth
[November 07, 2018, 03:47:29 AM]

BlueTooth elves choose "BlueTeeth" by Gareth
[November 07, 2018, 03:40:19 AM]

* Recent Posts

Web TIme API - by Gareth
[December 07, 2018, 04:34:37 PM]

API Directory by Gareth
[December 06, 2018, 03:34:16 PM]

Re: The Original Prusa I3 Mk3 by tinhead
[November 30, 2018, 02:49:52 PM]

Re: The Original Prusa I3 Mk3 by Bajdi
[November 30, 2018, 02:26:48 PM]

Re: The Original Prusa I3 Mk3 by tinhead
[November 30, 2018, 04:38:53 AM]

Re: Email notifications by CraigCox
[November 28, 2018, 10:26:06 PM]

Re: And another one. by CraigCox
[November 28, 2018, 10:17:54 PM]

Re: MKS Gen L 1.0 by jinx
[November 28, 2018, 02:23:50 AM]

Re: MKS Gen L 1.0 by Prokktor
[November 27, 2018, 08:35:38 AM]

Re: The Original Prusa I3 Mk3 by tinhead
[November 26, 2018, 02:42:26 PM]

Re: The Original Prusa I3 Mk3 by jinx
[November 26, 2018, 02:24:05 PM]

Re: The Original Prusa I3 Mk3 by Bajdi
[November 25, 2018, 07:54:21 AM]

Re: The Original Prusa I3 Mk3 by tinhead
[November 25, 2018, 06:11:22 AM]

Re: The Original Prusa I3 Mk3 by Bajdi
[November 25, 2018, 04:40:31 AM]

The Original Prusa I3 Mk3 by tinhead
[November 24, 2018, 12:02:51 PM]