Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is a program to find robotic arm inv kinematics.

My doubt is not in kinematics :-).

My program executes but always prints "position unacheivable", even for a known value, it does the same.

Here I have used radians for angles since thats what c understands.

Please tell me how to come across this or even tell me better method to implement this.

Thank you.
C++
 #include<stdio.h>
 #include<math.h>
 #include<conio.h>
 void main()
 {
   float a, b, c, d;
   int x = 0, y = 0, z = 0;
   int x1 = 0, y1 = 0, z1 = 0;
   int i = 0;

   printf("Enter X value: \n");
   scanf("%d", &x);
   printf("Enter Y value: \n");
   scanf("%d", &y);
   printf("Enter Z value: \n");
   scanf("%d", &z);

   for (a = -1.74 ; a <= 1.74 ; a = a + 0.02)
   {
     for (b = 0.0; b <= 3.14; b = b + 0.02)
     {
       for (c = -1.74; c <= 1.74; c = c + 0.02)
       {
         for (d = -0.784; d <= 0.784; d = d + 0.02)
         {
           x1 = (int)((11*cos(d+c+b+a)+11*cos(d+c+b-a)+12*cos(c+b+a)+12*cos(c+b-a)+9*cos(b+a)+9*cos(b-a))/2);
          if(x1 == x)
          {
            y1 = (int)((11*sin(d+c+b+a)-11*sin(d+c+b-a)+12*sin(c+b+a)-12*sin(c+b-a)+9*sin(b+a)-9*sin(b-a))/2);
            if(y1 == y)
            {
              z1 =  (int)(11*sin(d+c+b) + 12*sin(c+b) + 9*sin(b));
              if(z1 == z)
              {
                i = 1;
                goto status;
              }
            }
          }
        }
      }
    }
  }
  status:
  if(i == 0)
    printf("*****Positon unacheivable*****");
  else
    printf(" The joint angles for the desired positon are %d \t %d \t %d \t %d \n", a, b, c, d);
    getch();
}
Posted
Updated 27-Aug-12 19:49pm
v3
Comments
mbue 29-Aug-12 18:38pm    
This is a hint not a solution! Most common mistakes are the mixed usage of integer and floating point values. The most common errors base on rounding differences by a simple cast from double to int.
I see in your code alway on the left side: 11 or 12 or 9 these are int types. Most c compilers casts from right to left. Thats the function with cos and sin are always casted to int (left value). You should use 11.0*sin 12.0*sin and so on.
Regards.

1 solution

This is the proper formatted code of your inner most for loop:
C#
for (d = -0.784; d <= 0.784; d = d + 0.02)
{
	x1 = (int)((11*cos(d+c+b+a)+11*cos(d+c+b-a)+12*cos(c+b+a)+12*cos(c+b-a)+9*cos(b+a)+9*cos(b-a))/2);
	if(x1 == x)
	{
		y1 = (int)((11*sin(d+c+b+a)-11*sin(d+c+b-a)+12*sin(c+b+a)-12*sin(c+b-a)+9*sin(b+a)-9*sin(b-a))/2);
		if(y1 == y)
		{
			z1 =  (int)(11*sin(d+c+b) + 12*sin(c+b) + 9*sin(b));
			if(z1 == z)
			{
				i = 1;
				goto status;
			}
		}
	}
}

If you see, you modify i, only after 3 conditions are met, i.e. x1=x, y1=y, z1=z.
As long as any one of them are not same, i is never modified and you land up in the if condition that satisfies i=0

If you debug, you should find that i might not be getting reassigned to 1 from 0.
 
Share this answer
 
Comments
Member 9386932 28-Aug-12 1:25am    
but it has to satisfy all three conditions in order to take it for joint angles and also there are by theory, 70000 possible combinations of x,y,z for this arm...
Kuthuparakkal 28-Aug-12 1:45am    
Could you check if you are supplying x, y, and z as angle expressed in radians ?
Member 9386932 28-Aug-12 1:52am    
nop x, y and z arnt angles. they are points(integers). a, b, c, d are angles and yes they are expressed in radians coz c understands only radians not degrees.. do you know an alternative method for this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900