Inverse Kinematic for a single leg
boehm-e opened this issue · 7 comments
Hi,
I'm trying to create a small robot which has the same disposition of servos.
I'm struggling with the 3DOF IK (2d works), so I tried to implement yours (for now with javascript for testing).
I transpiled your Python code to Javascript, created a simple leg simulation in Three.js, and i tried to call you function leg_explicit_inverse_kinematics with custom x,y,z values :
i changed
(x, y, z) = r_body_foot
to
x=... y=..., z=...
It outputs me 3 angles, but when I put them in my leg simulation, it goes to a wrong x,y,z location.
My Parameters :
ABDUCTION_OFFSET = 4
LEG_L1 = 9.2
LEG_L2 = 10
--> the simulation : you can see at the bottom, I call pupperIk(19.2, 0, 4); which should place the arm straight, but it outputs : [98.11, -81.89, -89.99] which put my feet to the wrong location (obviously).
--> My implementation of you IK in Js is correct : i have compared my js result to you python results.
--> does it have something to do with the r_body_foot variable ?
What I would like to know, is how to use your formula to do IK of one leg independently of any other legs (the coxa being the origin ?) ?
Thank you :)
And here is the IK as a gist
I can take a closer look at this later if you’re still having issues, but here’s my initial thoughts:
I do think you may be misunderstanding what the r_body_foot variable is. In our code it is the Cartesian coordinates of the foot with respect to the top of the first link. x is how far forward the foot is. y is how far to the right it is. And z is how far down the leg extends.
So in order for your leg to point straight down you would use (0, 0, 19.2). (Note that this is a singularity, and our code will clip the the value going into arccos to prevent full extension)
One last thing I would be cautious about when applying our inverse kinematics to your leg: our servo for the lower link does not rotate with the top link. Because of this you may need to add/subtract the angle of the top link to get the angle you need for that servo.
I can take a closer look at this later if you’re still having issues, but here’s my initial thoughts:
I do think you may be misunderstanding what the r_body_foot variable is. In our code it is the Cartesian coordinates of the foot with respect to the top of the first link. x is how far forward the foot is. y is how far to the right it is. And z is how far down the leg extends.
So in order for your leg to point straight down you would use (0, 0, 19.2). (Note that this is a singularity, and our code will clip the the value going into arccos to prevent full extension)
One last thing I would be cautious about when applying our inverse kinematics to your leg: our servo for the lower link does not rotate with the top link. Because of this you may need to add/subtract the angle of the top link to get the angle you need for that servo.
Oh ! Thank you @CrazyAZ (i'm new to IK, and robotics in general)
So I updated the codepen
I see that my axis are messed up x) for now I dont know why, but I will investigate.
What I wonder is why I can't seems to control "how far to the right" the foot is;
In the codepen, I do pupperIk(i, 6, 4); i >-10<10 which means (to my weird coordinate system ;)) that the robot feet is constantly at 4cm to the right, is constantly at 6cm down and the foot is far from -10cm to 10cm. This works really well.
My issue is when I try to change the distance from the feet to the right --> If I change from 4cm to let's say 6cm the fit start to move at a weird angle and not at a straight line like the 4cm.
Working with 4cm offset
Not working with 6cm offset
It does seems that this position is possible for my configuration, do you know what i'm doing wrong ?
Thank you again :)
I took a look at your simulations, and I think this may be the result of a bug in your rendering. It appears that your simulation is not rotating the coxa around the correct axis.
As you can see from this picture, the coxa is pointed off-axis, resulting in an angled path for the foot. Instead, from this view the coxa should be pointed straight down and be rotating up out of the screen.
@CrazyAZ ,
First, thank you very much, you are really helpfull :)
So I updated the code to fix the coxa's rotation (as I understand it).
Here is the update codepen , I just changed the line 46 : now the gamma rotates over the z angle (before it was the x).
So now everything seems to work : I can move over x,y and z axis.
BUT it is strange --> In your video and ny looking at your model, it dont seems to follow this axis of rotation :/ , mine does not, it rotates as in my previous codepens. Tell me if i'm not clear x)
--> My leg has exactly the same joints as in this video
It's a bit hard for me to tell which axis is which in the codepen, so it might be that it is actually the angle of the femur which is off by 90 degrees. I believe we define an angle of 0 degrees to be pointing straight down, so if you have 0 as horizontal that could be what is causing the issue.