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!


Published at

Tags: Java,Inverse Kinematics,Robot

Luke Alderton

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 Richardcax on MVC forms in Umbraco
23 Sep 2018, 18:31 PM
By Normanambug on MVC forms in Umbraco
19 Sep 2018, 04:42 AM
By BabloPridi on MVC forms in Umbraco
17 Sep 2018, 09:23 AM
By hario on MVC forms in Umbraco
12 Sep 2018, 02:41 AM
By Jasonced on MVC forms in Umbraco
11 Sep 2018, 12:17 PM
By VadimProSEO on MVC forms in Umbraco
10 Sep 2018, 14:52 PM
By vennnile on MVC forms in Umbraco
8 Sep 2018, 05:49 AM
By xaipheira on MVC forms in Umbraco
5 Sep 2018, 10:30 AM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development