While experimenting with the OpenCV Machine Learning Library, I tried to make an example to learn the inverse kinematics of a 2D, 2 link arm using decision trees. The forward kinematics code looks like this:
const float Link1 = 1;
const float Link2 = 2;
CvPoint2D32f forwardKinematics(float alpha, float beta)
{
CvPoint2D32f ret;
// Simple 2D, 2 link kinematic chain
ret.x = Link1 * std::cos(alpha) + Link2 * std::cos(alpha - beta);
ret.y = Link1 * std::sin(alpha) + Link2 * std::sin(alpha - beta);
return ret;
}
I generate a random set of 1000 (XY -> alpha) and (XY -> beta) pairs, and then use that data to train two decision tree models in OpenCV (one for alpha, one for beta). Then I use the models to predict joint angles for a given XY position.
It seems like it sometimes gets the right answer, but is wildly inconsistent. I understand that inverse kinematic problems like this have multiple solutions, but some of the answers I get back are just wrong.
Is this a reasonable thing to try to do, or will it never work? Are there other learning algorithms that would be better suited to this kind of problem than decision trees?