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

Share with
Tags
Latest Comments
By Mark Gentry on Windows Server 2019 - Change product key does nothing
20 Aug 2021, 03:30 AM
By Cathy on In-Place Upgrade for a Windows Server domain controller
31 Jul 2021, 18:28 PM
By Mr. Greymatter on Raspberry Pi - Running Java app on Raspbian
16 Feb 2021, 07:35 AM
By Mikko Seittenranta on Xamarin Forms multiple instances of same app open
16 Feb 2021, 04:34 AM
By Andrew on Auto/Custom height on Xamarin Forms WebView for Android and iOS
22 Jan 2021, 22:15 PM
By Nick on Raspberry Pi - Running Java app on Raspbian
14 Oct 2020, 19:37 PM
By Ivan on Fixed: Value cannot be null Parameter Name: source
15 Sep 2020, 19:47 PM
By Anand on Raspberry Pi - Bluetooth using Bluecove on Raspbian
7 Sep 2020, 16:53 PM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development