tomstewart89 / Geometry

An Arduino library for representing where things are in relation to other things in 3D space
MIT License
75 stars 11 forks source link

Inverse kinematics? #15

Closed yaxu closed 2 years ago

yaxu commented 2 years ago

Hi, I'm new to robotics but would like to use the Geometry library to control my dynamixel ax12a servos. i'd like to calculate and set the pose to put the end effector in a particular x/y/z position (why is this called the end effector pose and not the nose pose?). I see there is documentation for how to describe a chain of servos, and an inverse dynamics example, but I think I need to do inverse kinematics rather than dynamics. However I'm not a mathematician and am at a bit of a loss to work out how to approach this. Any pointers much appreciated!

tomstewart89 commented 2 years ago

Hey @yaxu, thanks for your interest in my library! I'd be happy to give you some pointers.

Firstly, what you're looking for is indeed inverse kinematics which unfortunately is a little bit trickier than inverse dynamics. You might be able to come up with an closed form solution but that really depends on the way you set up your mechanism and how many servos you're using.

Failing that, you can use a numeric solution where you use the Newton-Raphson method (or something similar) to solve for a set of joint angles that minimise the distance between the end effector position and your target position. I actually had some code for that in this repo a while ago, you can find it here - it's pretty inefficient and it won't compile with the latest version of this library but it might be a handy example. This medium article seems to describe the same thing so you can check that out for a more detailed explanation.

On the other hand if you want to go full-commit then I'd really recommend reading chapter 6 of this book: Modern Robotics Mechanics, Planning, and Control, it involves a bit of math but it's a great read.

Hope that helps!

yaxu commented 2 years ago

Thanks for the pointers @tomstewart89, I'll see what I can wrap my head around!