Suppose we have an inverse kinematics problem, i.e., we want to determine the joint angles of a robotic arm to reach a desired end-effector position and orientation. We can formulate this as finding the roots of a function that measures the error between the desired end-effector configuration and the actual one achieved by a specified set of joint angles.
We can define a function f that takes the joint angles q as input and returns a vector of errors e = f(q) representing the differences between the desired pose and the actual pose, in the x, y, z, and orientation components. For instance, considering a cartesian end-effector position and a quaternion-based orientation, we can write:
main.m396 chars13 lines
Here, qd
and pd
denote the desired position and orientation, respectively, and forward_kinematics(q)
is a function that computes the forward kinematics of the robotic arm based on the joint angles q
.
Once we have defined the function f
, we can use any root-finding or optimization algorithm in MATLAB to solve for the joint angles that minimize the error. For example, we can use the fminsearch
function to find the minimum of the norm squared of the error vector:
main.m97 chars3 lines
Here, fminsearch
takes as input an anonymous function that computes the norm squared of the error vector for a given set of joint angles q
, and returns the optimal set of joint angles q
that minimizes this quantity.
gistlibby LogSnag