Go Down

Topic: Control robotic arm using arduino and kinect (Read 7621 times) previous topic - next topic

dimis90

Aug 21, 2014, 04:38 pm Last Edit: Aug 25, 2014, 03:42 pm by dimis90 Reason: 1
Hi everyone i just made an account in this forum...please excuse me if my English is kinda bad or i don't follow forum rules...

I am trying to control a robotic arm via kinect and arduino duemilanove using serial port of arduino....so far i have succeed to control one servomotor of arm but when i try to control two servomotor's i cant control it at all and i believe it is because i don't fully understand how serial port works...for the programing of kinect  i use Microsoft 2010 C# express and for the arduino i use the environment that this site provide us the code of arduino is the following...

P.S. the project is that through kinect that seeing my movement of my body to transfer it to robotic arm through arduino serial port


Code: [Select]
#include <math.h>
#include <Servo.h>
int i=0;
int j=0;
int powc=1;
byte RIGHT[20];
byte LEFT[20];
double angleR=0;
double angleL=0;
int aposR=0;
int aposL=0;
int mpoR;
int mpoL;
Servo a;
Servo b;

void setup()
{                
// Turn the Serial Protocol ON
 Serial.begin(9600);
 a.attach(9);
 b.attach(8);
}

void loop() {
  /*  check if data has been sent from the computer: */
 while (Serial.available() > 0) {
     
   RIGHT[i]=Serial.read();
   if(RIGHT[i]=='a')
   {
   aposR=i;
   for(int c=0; c<aposR; c++ )
   {
     angleR=angleR+(RIGHT[aposR-c-1] - '0') * powc;
     powc=powc*10;
   
   }
 
   powc=1;
   
   
   
   }
   LEFT[j]=Serial.read();
   if(LEFT[j]=='b')
   {
     aposL=j;
     for (int t=0; t<aposL;t++)
     {
       angleL=angleL+(LEFT[aposL-t-1]- '0')*powc;
       powc=powc*10;
     }
   }
   powc=1;
     
   
 
 
 
 
   if(RIGHT[i]=='m')
   {
   mpoR=i;
   int motor=RIGHT[mpoR-1] -'0';
   if (motor==1)
   {a.write(angleR);}
    Serial.print(angleR);
    Serial.print(" degrees on motor ");
    Serial.print(motor);
    Serial.print(" ");
       Serial.println();
       i=0;
       RIGHT[i]='/0';
       angleR=0;
       
       
   }
   if(LEFT[j]=='m')
   {
     mpoL=j;
     int motor=LEFT[mpoL-1] -'0';
     if (motor==2)
     {b.write(angleL);}
     Serial.print(angleL);
     Serial.print(" degrees on motor ");
     Serial.print(motor);
     Serial.print(" ");
     Serial.println();
     j=0;
     LEFT[j]='/0';
     angleL=0;
   }

i++;
j++;
}
}



And the part of the code in C# that i am sending in the serial port of arduino is this


Code: [Select]
int right= GetJointAngle(skeleton.Joints[JointType.ShoulderRight], skeleton.Joints[JointType.ElbowRight], skeleton.Joints[JointType.WristRight]);
                           PixelDepth.Text = string.Format("Angle Right hand {0}",right);
                           canvasSkeleton.Children.Add(CreateFigure(skeleton, userBrush, joints));
                           string a = right.ToString();
                           port.Write(a);
                           port.WriteLine("a1m");  
   this is when i move my right arm
[/b]
So far is good but when i try add code so i can move at the same time my right and my left hand to control 2 servomotor each the arm is doing random things....any help why is this happening ??

The code for the movement of my left hand is the following

Code: [Select]
int left = GetAngle(skeleton.Joints[JointType.ShoulderLeft], skeleton.Joints[JointType.ElbowLeft], skeleton.Joints[JointType.WristLeft]);
                           PixelDepth.Text = string.Format("Angle Left hand {0}", left);
                           canvasSkeleton.Children.Add(CreateFigure(skeleton, userBrush, joints));
                           string b = left.ToString();
                           port.Write(b);
                           port.WriteLine("b2m");





PaulS

Quote
and i believe it is because i don't fully understand how serial port works

Probably. Hard to tell from your mangled code.

  b.attach(8);
You attached the servo to the happy face pin?

There are guidelines at the top of each forum that discuss how to post code. Read them, and try again.
The art of getting good answers lies in asking good questions.

dimis90

this is b.attach( 8 ); and affords the digital pins of arduino 8 and 9 ok i will see it how i should i

zoomkat

Quote
so far i have succeed to control one servomotor of arm but when i try to control two servomotor's i cant control it at all and i believe it is because i don't fully understand how serial port works.


What are you using for servo power? Most multi servo issues arise from an inadequate power supply for the servos. Trying to power servos from the arduino generally doesn't work.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

dimis90

I don't any power supply only the power that arduino provides through my pc...maybe its not enough ?

zoomkat


I don't any power supply only the power that arduino provides through my pc...maybe its not enough ?


Servos need external power supplies generally wired like below.


Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

dimis90

Thank you for the quick reply's...i will let you know if this was after all the problem

dimis90

#7
Aug 25, 2014, 03:40 pm Last Edit: Aug 25, 2014, 03:48 pm by dimis90 Reason: 1


I don't any power supply only the power that arduino provides through my pc...maybe its not enough ?


Servos need external power supplies generally wired like below.





It seems that the power was not the problem can you check my code? in this part

Code: [Select]
void loop() {
  /*  check if data has been sent from the computer: */
 while (Serial.available() > 0) {
     
   RIGHT[i]=Serial.read();
   if(RIGHT[i]=='a')
   {
   aposR=i;
   for(int c=0; c<aposR; c++ )
   {
     angleR=angleR+(RIGHT[aposR-c-1] - '0') * powc;
     powc=powc*10;
   
   }
 
   powc=1;
   
   
   
   }
   LEFT[j]=Serial.read();        ***
   if(LEFT[j]=='b')
   {
     aposL=j;
     for (int t=0; t<aposL;t++)
     {
       angleL=angleL+(LEFT[aposL-t-1]- '0')*powc;
       powc=powc*10;
     }
   }
   powc=1;


when i put  LEFT[j]=Serial.read();  servo's just stop working any idea why or maybe can you explain how serial port on arduino duemilanove works ?

P.S. Anything you don't understand about the code ask me

PaulS

When there is serial data to read, read one character, and store it in RIGHT. Then, read the next character, even if there isn't one, and store it in LEFT. Does that really make sense?
The art of getting good answers lies in asking good questions.

dimis90


When there is serial data to read, read one character, and store it in RIGHT. Then, read the next character, even if there isn't one, and store it in LEFT. Does that really make sense?


So you are saying that this line "LEFT[j]=Serial.read();" is completely useless ?

PaulS

Quote
So you are saying that this line "LEFT[j]=Serial.read();" is completely useless ?

No. But, you need to KNOW whether you are reading the RIGHT value or the LEFT value.

If you want to send two values for RIGHT and LEFT, such as 123 and 45, I seriously doubt that you send data like "14253". So, why are you reading values as though they were interspersed?
The art of getting good answers lies in asking good questions.

dimis90

I will try it as you said...Also can you tell me how can i see what serial port receives so i would be able to figure out the way that it receives data. I cant see by the serial monitor because when i run the code the serial port is in use and for that does not let me see what data is receiving 

dimis90

anyone knows how can I see what serial port of arduino is receiving ? I can't use serial monitor because port is already in use when i run the code so is there another way to see what is receiving ?

PaulS


anyone knows how can I see what serial port of arduino is receiving ? I can't use serial monitor because port is already in use when i run the code so is there another way to see what is receiving ?

The application that is sending data to the Arduino needs to have a way of reading data that the Arduino sends. If it does, you are out of luck.

You could, of course, use the Serial Monitor application to send data to the Arduino in the format that you think that application is sending the data. Make the Arduino deal with the known format. If the Arduino then deals with the unknown format data in the same way, then you were correct in guessing what the application is sending. If not, you weren't. So, you make another guess.
The art of getting good answers lies in asking good questions.

dimis90



anyone knows how can I see what serial port of arduino is receiving ? I can't use serial monitor because port is already in use when i run the code so is there another way to see what is receiving ?

The application that is sending data to the Arduino needs to have a way of reading data that the Arduino sends. If it does, you are out of luck.

You could, of course, use the Serial Monitor application to send data to the Arduino in the format that you think that application is sending the data. Make the Arduino deal with the known format. If the Arduino then deals with the unknown format data in the same way, then you were correct in guessing what the application is sending. If not, you weren't. So, you make another guess.
I kinda lost you. Could you please simplify it ?

Go Up