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
leftLowerLeg.getChildren().add(leftFoot);
rightLowerLeg.getChildren().add(rightFoot);

leftUpperLeg.getChildren().add(leftLowerLeg);
rightUpperLeg.getChildren().add(rightLowerLeg);

// Connect legs to torso
torso.getChildren().add(leftUpperLeg);
torso.getChildren().add(rightUpperLeg);

// Creating the skeleton
skeleton = new Skeleton();
skeleton.setTranslateX(0);
skeleton.setTranslateY(0);
torso.setSkeleton(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!


By Luke Alderton at 7 Jul 2015, 22:23 PM

Tags: Java,Inverse Kinematics,Robot

Comments

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
Tags
Latest Comments
By dipbleds on Raspberry Pi - Bluetooth using Bluecove on Raspbian
12 Dec 2017, 21:29 PM
By Ich on Replacing the Xamarin Header/Navigation bar with a custom view/template
26 Nov 2017, 17:11 PM
By Ravi Motha on My experience at Umbraco UK Festival 2017
12 Dec 2017, 08:39 AM
By Borges on How to add a Xamarin Forms Loading Screen/Overlay
7 Nov 2017, 19:11 PM
By Rutul Mehta on Auto/Custom height on Xamarin Forms WebView for Android and iOS
4 Nov 2017, 03:15 AM
By Pablo on Xamarin MasterDetailPage has large margin/padding at top
26 Oct 2017, 15:31 PM
By faiza on Using MaryTTS or OpenMary in Java
22 Oct 2017, 12:54 PM
By Nietoperz on Using MaryTTS or OpenMary in Java
29 Sep 2017, 14:34 PM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development