Monday, December 11, 2017
Home » Flowstone Workshop » Flowstone Workshop 9

Flowstone Workshop 9

Flowstone-HeaderProgramming a Biped with IK

Welcome to the FlowStone Workshop number 9, where we give a beginner’s guide to computer programming using the FlowStone graphical programming language. In this issue we are going to look at programming a robotic Biped using Inverse Kinematics (IK).

WHAT IS A BIPED?  

A Biped by definition is a two legged robot; they come in various guises from simple to complex. The level of complexity is usually defined in Degrees of Freedom (DOF), which relate to how many joints (or articulating servos) the Biped has. For this article we are going to use the ‘Biped BRAT’ from LynxMotion, which is one of the simplest. It only has 3 DOF per leg and therefore is one of the easiest bipeds to program. Some of the more sophisticated Bipeds have 6 DOF per leg like the ‘Biped Scout,’ also from LynxMotion.

FLOWSTONE WORKSHOP 9-3

BIPED BRAT REVISITED  

The LynxMotion Biped BRAT was the very first Robot I ever tried to program many moons ago, and to be honest it was not as easy as I had hoped. The main issue with walking robots is that they are like babies when you first start programming them; they keep falling over all of the time! If you are new to robotics then I would recommend a robot arm as your first step, and then move onto walking robots once you have cut your teeth. On the other hand walking robots are very rewarding as they are a real challenge, and are very appealing to we humans, as we like the idea of making something in the image of ourselves.

When I first programmed the BRAT I used forward kinematics and managed to make the BRAT walk but very clumsily, this was for the BRAT vs. Alien Arm article (+video, May-June 2011 Robot). The programming was done by painstakingly moving each joint in FlowStone and recording its position in an array of movements until I had captured one complete stride. This sequence was then just looped to make the BRAT walk (see BRAT Sequencer V1). For this article we are going to go to the next level and use Inverse Kinematics to make the BRAT walk with a little more elegance.

WHAT IS INVERSE KINEMATICS?  

We covered IK or Inverse Kinematics in the last issue’s Hexapod arti- cle but just in case you missed it: IK is the Math behind robotic movement. In simple terms it is the calculation, for example, of the  angles required for each of a robot’s arm or leg joints in order for it to move to a specific position in 2D space.

FLOWSTONE WORKSHOP 9-2
Version 1 of the BRAT Sequencer – Forward Kinematics.
FLOWSTONE WORKSHOP 9-4
The LynxMotion Biped BRAT.

FIRST, THE SIMULATION 

As with most of the recent articles I’ve written for Robot, I always find it quicker in the long run to first create a graphical simulation of what it is that I’m trying to control, so with the BRAT this was no exception. I used some of the FlowStone code from last month’s Hexapod to make a two legged graphical model that I could move on the screen. At the core of this is some Ruby code that drew the shapes on the screen and enabled me to animate them using the FlowStone IK module. The first thing to achieve was to make the BRAT crouch up and down and not fall over. Then make it rock side to side to a point where one foot was off the floor.

FLOWSTONE WORKSHOP 9-5
The simulation of the BRAT in FlowStone

The big difference using IK is that instead of having to move each servo individually to position the leg, you just give it an x,y co-ordinate of where you want it to go and the IK does the rest, making the sequencing of the movement much quicker and more natural to program.

FLOWSTONE WORKSHOP 9-6
LynxMotion SC-32 servo controller.

In order to control our BRAT we used the Xbox games controller connected to the PC, since FlowStone already had a module for this it makes a very convenient robot controller. I mapped the two legs to the left and right thumb joysticks and the feet to the left and right triggers.

CONNECTING THE BRAT  

Once we were happy that the simulation was working ok, it was time to connect the real thing. One thing to be careful of with robots that use RC type servos, is that if you get it wrong you can easily burn out a servo. So, to help prevent this we added a ‘KILL Switch’ on the software front panel so if the robot wasn’t matching the simulation position we could quickly kill the whole robot to save the servos.

The SC-32 servo controller that comes with the BRAT has a simple protocol where you have a servo number followed by its position in ms.

FLOWSTONE WORKSHOP 9-8
SC-32 data String.
FLOWSTONE WORKSHOP 9-9
Ruby Script to convert degrees into servo positions.

Here you can see the whole string that goes out to the board (SC-32 Data String). The IK algorithm outputs angles for each joint in degrees so we need to convert these into servo commands for the LynxMotion SC-32 board.

To do this we used a little Ruby code to convert the degrees into the servo data, before we added the servo number etc. Having Ruby inside FlowStone is very useful because if you ever need to drop into code it’s just there, and your code can be as large or as small as you want, then once finished it can be made into a reusable module. We used seven of these toServo modules six for the legs, and one for the Turret servo option we had on our BRAT.

This Ruby module takes the input in degrees and multiplies it by a scale factor (9), before adding it to 1500 which is the centre position of the servo. Typically servos are centred at 1500ms, -45° at 1250ms, and +45° at 1750ms. You may have to play with the scale factor to match your exact servos as brands differ.

We also added a calibration window to our software to fine-tune each individual joint to null out any minor errors introduced during the build. See the finished software GUI with the leg and feet simulation, turret servo slider, and comport settings. Plus that all important ‘Kill Switch’!

FLOWSTONE WORKSHOP 9-10
The finished program complete with user interface.
FLOWSTONE WORKSHOP 9-12
The Biped is titled over to stand on one foot.
FLOWSTONE WORKSHOP 9-7
Commanding BRAT legs as viewed in Flowstone.

LET’S ROCK!  

In order to walk there were two main movements we needed, first was to get the Biped to rock over onto one foot so that the leg was free to move, and the second was to then move the legs themselves. In order to make our BRAT rock over onto one foot it needed a little help from the other foot, so we made the sup- porting foot rock over and the other foot push a little to get things going. To do this we used a little mixing to add a little push when- ever a supporting foot rocked over. This can be seen in the close up image of the Biped’s feet.

Now we have everything to make our Biped walk by using the Xbox controller to actually control the limbs in real-time. This is very different to playing a pre-made sequence as you are physically controlling the robot and making it walk! It takes a little practice to get the hang of it but it is very rewarding when it all works.

CONCLUSION

Programming walking robots of any type instead of using pre-made sequences is a real challenge, but by adding Inverse Kinematics it is not impossible. It really makes you appreciate how sophisticated we humans are, and how complex our joints are compared to even the most advanced robots. Programming this Biped BRAT is literally the first step in walking robotics and well worth it if you take up the challenge! As always the source code files are available on the DSPRobotics examples page.

Lynxmotion was recently acquired by Robotshop, www.robotshop.com. The Lynxmotion family of products is a great addition to an impressive inventory of robotics products in every category at Robotshop.—the editors

Links  
DSP Robotics,  www.dsprobotics.com
RobotShop,  www.robotshop.com
Lynxmotion, www.lynxmotion.com

Leave a Reply

Your email address will not be published. Required fields are marked *