henriksod / Fabrik2DArduino

A fast forward- and inverse kinematics solver for Arduino based on the FABRIK algorithm. The solver supports up to 4 DOF.
MIT License
99 stars 25 forks source link

Can the initial joint attached to the plane be offset along the plane? #47

Closed KroogerFx closed 4 weeks ago

KroogerFx commented 2 months ago

Hello,

I am trying to adapt this library to drive a robot leg. image

Is there a way to include an offset (red line) from where the first joint attaches to the base rotation?

I have tried changing the values of the joint x, y, and the z value of the chain but can't get a solution.

henriksod commented 2 months ago

Hi! Sorry for late reply. I will look into this sometime this week and get back to you.

henriksod commented 2 months ago

Just a quick thought, what if you put the origin of the leg on the end of the red line? Or am I misunderstanding the picture? Would be nice to understand the axis of rotation for each joint.

henriksod commented 2 months ago

Okay reading the title I assume the first joint of the leg is attached at a point offset from the rotation vector of the base joint.

henriksod commented 2 months ago

Looking into it a bit, I think that the red line could be considered its own arm where the the joint connecting it to the next arm has a fixed angle. This can be solved by adding angular constraints to the joints. As a matter of fact the paper addresses this: http://www.andreasaristidou.com/publications/papers/FABRIK.pdf pp. 249

I will look into it a bit how we can do this with the current implementation. I was planning to do a full revamp of the library at some point, but adding this should not be too difficult to accomplish.

KroogerFx commented 2 months ago

Hello,

Thank you for the reply.

"Okay reading the title I assume the first joint of the leg is attached at a point offset from the rotation vector of the base joint."

Yes this is correct, this would cause the location of the first joint to change coordinates while the base is rotating rather than staying in the same location.

"I think that the red line could be considered its own arm where the the joint connecting it to the next arm has a fixed angle. This can be solved by adding angular constraints to the joints."

This should work but how can I constrain the joints?

It appears the properties of the joint are dynamic and the solver will change them accordingly

// Joint struct typedef struct { float x = 0; // x position of joint relative to origin float y = 0; // y position of joint relative to origin float angle = 0; // angle of joint } Joint;

Is there a way to constrain the first joint angle? That would act as the red offset line.

Thank You

henriksod commented 1 month ago

Hi, I merged a pull request where I added joint constraints. Please clone the master branch and try it and let me know how it goes.

https://github.com/henriksod/Fabrik2DArduino/pull/49

henriksod commented 1 month ago

Here is an example how to use it:

int success = 0;
int lengths_4_joints[] = {200, 200, 200};
Fabrik2D::AngularConstraint angular_constraints[3] = {
    Fabrik2D::AngularConstraint{-M_PI / 2.0, -M_PI / 2.0},
    Fabrik2D::AngularConstraint{-2.0 * M_PI, 2.0 * M_PI},
    Fabrik2D::AngularConstraint{-2.0 * M_PI, 2.0 * M_PI}};

Fabrik2D fabrik2D(4, lengths_4_joints, angular_constraints, 1);
success = fabrik2D.solve2(100, 100, 100, lengths_4_joints);