Reputation: 19
I am building a robotic arm with 6 DOF using arduino and 6 servo motors.
I made myself a Python interface using serial communication so that I can write: move_motor(angle1=45, angle2=37)
and the servo motors will move accordingly.
Now i am getting to the IK part, and I'm looking for a good package where you set the arm lengths, and then you can give it (x,y,z,theta)
and it will return you the angle for each motor.
Is there a good package available? Or at least something that i can play with for my needs?
Upvotes: 1
Views: 14256
Reputation: 369
As your problem is quite simple, I think the best for you is to solve the inverse kinematics (IK) problem by quadratic programming (QP). In Python, you can solve QPs in a few lines of code using e.g. the CVXOPT library (I published a tutorial with some code here). Also, I wrote is an example of IK solver in Python that uses CVXOPT as QP solver. It is more complex than the problem at hand, but you can take a look at it for inspiration.
The useful part is this function:
def compute_velocity(self, q, qd):
P = zeros(self.I.shape)
r = zeros(self.q_max.shape)
for obj in self.objectives:
J = obj.jacobian(q)
P += obj.weight * dot(J.T, J)
r += obj.weight * dot(-obj.velocity(q, qd).T, J)
if self.K_doflim is not None:
qd_max = minimum(self.qd_max, self.K_doflim * (self.q_max - q))
qd_min = maximum(self.qd_min, self.K_doflim * (self.q_min - q))
else:
qd_max = self.qd_max
qd_min = self.qd_min
G = vstack([+self.I, -self.I])
h = hstack([qd_max, -qd_min])
if self.constraints:
A = vstack([c.jacobian() for c in self.constraints])
b = hstack([c.velocity() for c in self.constraints])
return cvxopt_solve_qp(P, r, G, h, A, b)
return cvxopt_solve_qp(P, r, G, h)
It basically solves the global IK problem (finding a joint-angle vector 'q') by differential IK, that is to say, by computing a velocity 'qd' that drives the system toward the solution. It is essentially the idea behind the Levenberg-Marquardt algorithm.
Upvotes: 5