Arduino Forum

Topics => Robotics => Topic started by: dimis90 on Aug 21, 2014, 04:38 pm

Title: Control robotic arm using arduino and kinect
Post by: dimis90 on Aug 21, 2014, 04:38 pm
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");




Title: Re: Control robotic arm using arduino and kinect
Post by: PaulS on Aug 21, 2014, 05:55 pm
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.
Title: Re: Control robotic arm using arduino and kinect
Post by: dimis90 on Aug 21, 2014, 06:31 pm
this is b.attach( 8 ); and affords the digital pins of arduino 8 and 9 ok i will see it how i should i
Title: Re: Control robotic arm using arduino and kinect
Post by: zoomkat on Aug 22, 2014, 03:36 am
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.
Title: Re: Control robotic arm using arduino and kinect
Post by: dimis90 on Aug 22, 2014, 09:48 am
I don't any power supply only the power that arduino provides through my pc...maybe its not enough ?
Title: Re: Control robotic arm using arduino and kinect
Post by: zoomkat on Aug 22, 2014, 05:56 pm

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.

(http://web.comporium.net/~shb/pix/servo-wire.jpg)
Title: Re: Control robotic arm using arduino and kinect
Post by: dimis90 on Aug 23, 2014, 02:13 pm
Thank you for the quick reply's...i will let you know if this was after all the problem
Title: Re: Control robotic arm using arduino and kinect
Post by: dimis90 on Aug 25, 2014, 03:40 pm


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.

(http://web.comporium.net/~shb/pix/servo-wire.jpg)



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
Title: Re: Control robotic arm using arduino and kinect
Post by: PaulS on Aug 25, 2014, 03:44 pm
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?
Title: Re: Control robotic arm using arduino and kinect
Post by: dimis90 on Aug 25, 2014, 03:54 pm

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 ?
Title: Re: Control robotic arm using arduino and kinect
Post by: PaulS on Aug 26, 2014, 12:48 pm
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?
Title: Re: Control robotic arm using arduino and kinect
Post by: dimis90 on Aug 27, 2014, 11:22 am
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 
Title: Re: Control robotic arm using arduino and kinect
Post by: dimis90 on Aug 28, 2014, 02:11 pm
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 ?
Title: Re: Control robotic arm using arduino and kinect
Post by: PaulS on Aug 28, 2014, 03:48 pm

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.
Title: Re: Control robotic arm using arduino and kinect
Post by: dimis90 on Aug 28, 2014, 04:03 pm


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 ?
Title: Re: Control robotic arm using arduino and kinect
Post by: PaulS on Aug 29, 2014, 12:59 pm
Quote
Could you please simplify it ?

I can't see how.

Does the application that is sending data to the Arduino have the capability to receive data from the Arduino and display it to you?
Title: Re: Control robotic arm using arduino and kinect
Post by: dimis90 on Aug 29, 2014, 01:15 pm

Quote
Could you please simplify it ?

I can't see how.

Does the application that is sending data to the Arduino have the capability to receive data from the Arduino and display it to you?
The application is only sending not receiving. Arduino is only receiving and do some calculations  all i want is to see what arduino is receiving but i can't do it through serial monitor because the port is in use when i am running the code from c# so i am asking you is there another way to see how can i see what arduino is receiving?
Title: Re: Control robotic arm using arduino and kinect
Post by: PaulS on Aug 29, 2014, 04:46 pm
Quote
so i am asking you is there another way to see how can i see what arduino is receiving?

Without additional hardware, no.
Title: Re: Control robotic arm using arduino and kinect
Post by: zoomkat on Aug 29, 2014, 05:32 pm
There is serial port monitoring software available that will run on the pc and capture the transactions occurring on the serial port. In the past i used a program called portmon to monitor serial communications.

https://www.google.com/search?as_q=serial+port+monitor&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=&as_occt=any&safe=images&tbs=&as_filetype=&as_rights=&gws_rd=ssl
Title: Re: Control robotic arm using arduino and kinect
Post by: dimis90 on Aug 31, 2014, 10:18 am
PaulS thank you for your time and zoomkat this program really did the trick thank you too