Inverse Kinematics using JavaFX for Robotics

As in many of my previous posts, you might have noticed that I've been building a robot. Yes before you say 'but you're taking ages to make it!', I know, there are many excuses I could use but I won't bother, I wouldn't be fooling anyone, I've just been putting Inverse Kinematics off because it's a beast that not many people can tame.

So (with the excuses out of the way) you can easily implement a basic setup in Java that works well enough for almost any implementation. See Mikes blog post about an Inverse Kinematics library he developed. If you copy the Bone and Skeleton .java files from the GitHub page and put them into your Java application, you'll be able to set up a basic bone structure for almost any type of robot.

The robot I'm developing happens to be a biped as seen on its project page and this means that I have to build two legs and control them as such. See m leg definitions below:

// Skeleton
public Skeleton skeleton;

// Torso
public final Bone torso = new Bone(80, 90);

// Left leg bones
Bone leftUpperLeg = new Bone(6.5d, 90);
Bone leftLowerLeg = new Bone(7.4d, 90);
Bone leftFoot = new Bone(7.4d, 90);

// Right leg bones
Bone rightUpperLeg = new Bone(6.5d, 90);
Bone rightLowerLeg = new Bone(7.4d, 90);
Bone rightFoot = new Bone(7.4d, 90);

// Definition of lower legs


// Connect legs to torso

// Creating the skeleton
skeleton = new Skeleton();

From then, it's simply a matter of getting the angle from the bone and setting that to the servo. Whilst I won't go into depths about the servo implementation, I will say that I have a function that converts an angle to a value within the servo range, so I can say setServoAngle(90) and it will set the servo to 1600. You can get the angle of the bone using the getRotate method, example implementation below:

leftHipX.setAngle(leftUpperLeg.getRotate(), 100);

The script mentioned above will also allow you to output a visual, something like the image below. Since my robot is only a pair of legs at the moment, it looks a bit odd, but it's useful, trust me.

JavaFX Inverse Kinematics Visual

If you have any questions/suggestions, please do post a comment and I'll reply as soon as I can!

Published at

Tags: Java,Inverse Kinematics,Robot

Luke Alderton


Post a comment
Sit tight...
We're adding your comment.
Thank you.
Your comment has been added.
There's been a problem.
Please try again later.
Share with
Latest Comments
By Helenpaups on MVC forms in Umbraco
23 May 2018, 16:48 PM
By Helenpaups on MVC forms in Umbraco
23 May 2018, 13:46 PM
By AkikoTax on MVC forms in Umbraco
20 May 2018, 06:41 AM
By Klaus on MVC forms in Umbraco
17 May 2018, 10:47 AM
By Archie on MVC forms in Umbraco
16 May 2018, 18:52 PM
By w on JQuery Unobtrusive Validation for dynamically created elements
11 May 2018, 02:00 AM
By Luke on Umbraco using Global.asax to handle events before the Request Handler.
27 Apr 2018, 18:28 PM
By Janine Gardiola on Umbraco using Global.asax to handle events before the Request Handler.
26 Apr 2018, 11:18 AM
App Development
Game Development
Web Development