Go Down

Topic: Robot Arm 6 degrees of freedom servo and c# (Read 1 time) previous topic - next topic

Hey all hoping u like my project and try to help me

I made a robotic arm with 6 DOF i am using arduino MEGA as my control unit and i am giving the angles to my motors using a c# program
i can connect both the c# and the arduino programs together through normal serial  but the problem is that the program i made on c# working with 6 threads and every milli second ((or anything near)the angles of the motors must be changed and the other thing is that i need to differentiate between the angles so i thought of sending the angles with a symbol like: 160s for shoulder and 130e for elbow
but i don't know how the arduino will understand a string of more than one character and how can i tell my arduino to differentiate between numbers and alphabetical letters
i thought of sending an array of angles with commas(,) between each angle and to tell the arduino that the first angle is for the shoulder the second is for the elbow and so on
so which is better or is there any better answer
and the most needed and appreciated thing is to tell me example of a code that i can make as i'm a beginner programmer 
Thnx a lot

Graynomad

Quote
i thought of sending an array of angles with commas(,) between each angle and to tell the arduino that the first angle is for the shoulder the second is for the elbow and so on

That sounds reasonable, you can save the characters then parse the string when it's finished. Use two special characters (say < and >) to delimit the package so you know when it starts and stops.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

ajofscott

#2
Apr 25, 2012, 03:50 am Last Edit: Apr 25, 2012, 03:54 am by ajofscott Reason: 1
In my milling machine control I use a string to recieve the serial transmission then convert it to a character array after an end of transmission char is recieved. The numerical data is sent in hexadecimal ensuring that no valid numerical data gets misinterpreted as an end of transmission.
From the charracter array I have fixed byte positions for the beginning of each field. A user function reads characters then converts the hex char to its hex numerical counterpart and concates the group of chars one at a time into the appropriate byte locations. See below:
My command resembles MA 01FA 2EE7 *
I have up to 55 characters including whitespace allocated. The whitespace is a human reading aide and has no bearing on fetching the field data.
Code: [Select]

String HexToInt = "0123456789ABCDEFX";
//The 'X' is included so that I can get a return value indicating an ignored field.

int Chex(char symbol)
{
 int temp;
 temp = HexToInt.indexOf(symbol);
 if(temp==16)
   {
     return -1; //An ignored field
   }
 else
   {
     return temp;
   }
}
int GetValueFromString(char * buffer, int offset)
 {
   int temp;
   int j;
   int Ignored;
   for(j=0; j<=3; j++)
     {
        temp = Chex(buffer[ j + offset])
        if(temp==-1)
          {
             Ignored = -1;
          }
     }
   if(Ignored != -1)
     {
       temp = Chex(buffer[ offset]) * 4096;
       temp = temp + Chex(buffer[1 + offset]) * 256;
       temp = temp + Chex(buffer[2 + offset]) * 16;
       temp = temp + Chex(buffer[3 + offset]);
       return temp;
      }
    else
      {
        return '/0';
      }
  }

Go Up