Hi,
if ForearmLength == ArmLength all works
but if not i got some error (the biger the difference the bigger the error).
(for some software to control servo device using ssc32 or others serial controler)
In the picture the arm should touch the mouse at all times(using IK to get angle and then FK to get the points and draw the arm.)
Im using this ik code
[code]
public void SetXYZ(double XVal, double YVal, double ZVal, double WristTableVal)
{
//Inverse Kinematic Tcp to axis.
double ShoulderLength = RLArm.BaseRadius;
double ShoulderHeight = RLArm.TableHeight + RLArm.BaseHeight;
double FingersLength = Math.Sqrt(Math.Pow(XVal, 2) + Math.Pow(ZVal, 2));
double WristHeight = YVal - Math.Sin(Radians(WristTableVal)) * RLArm.HandLength;
double WristLength = FingersLength - Math.Cos(Radians(WristTableVal)) * RLArm.HandLength;
double SEWOpening = Math.Sqrt(Math.Pow(WristHeight - ShoulderHeight, 2) + Math.Pow(WristLength - ShoulderLength, 2));
double SEWOpeningPercent = SEWOpening / (RLArm.ForearmLength + RLArm.ArmLength);
double BasePosition = Degrees(Math.Atan2(ZVal, XVal));
double ElbowPosition = Degrees(Math.Acos((Math.Pow(RLArm.ForearmLength, 2) + Math.Pow(RLArm.ArmLength, 2) - Math.Pow(SEWOpening, 2)) / (2 * RLArm.ForearmLength * RLArm.ArmLength))) - RLArm.ShoulderNeutralAngle;
double ShoulderPosition = RLArm.ShoulderNeutralAngle - Degrees(Math.Atan2(WristLength - ShoulderLength, WristHeight - ShoulderHeight) +
Math.Acos((Math.Pow(RLArm.ForearmLength, 2) - Math.Pow(RLArm.ArmLength, 2) + Math.Pow(SEWOpening, 2)) / (2 * RLArm.ForearmLength * SEWOpening))) - ElbowPosition;
double WristPosition = WristTableVal - (ShoulderPosition + ElbowPosition + RLArm.ShoulderNeutralAngle + RLArm.ElbowNeutralAngle + RLArm.WristNeutralAngle);
Console.WriteLine("IK Base: {0}, Elbow: {1}, Shoulder:{2}, Wrist: {3}, X: {4}, Y:{5}, Z:{6}, WristTable: {7}",
BasePosition, ElbowPosition,
ShoulderPosition, WristPosition,
XVal, YVal, ZVal, WristTableVal);
//TODO log out of range to console
if(SEWOpeningPercent > 1)
return;
try {
//Use local so to not trigger update too many times.
this.ax_Base.Position = BasePosition;
this.ax_Elbow.Position = ElbowPosition;
this.ax_Shoulder.Position = ShoulderPosition;
this.ax_Wrist.Position = WristPosition;
} catch (ArgumentOutOfRangeException) {
//TODO log out of range to console
Console.WriteLine("IK Out of range");
}
}[/code]