Pages: [1]   Go Down
Author Topic: Getting correct rotations for servo in real time  (Read 644 times)
0 Members and 1 Guest are viewing this topic.
India
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi frnds  smiley,
I am a new guy in this field.so ,i really need a help.

I am doing a project on online object tracking.I have made a 3 dof robot with 3 servos attached.Using simulink and matlab , i am able to get the co-ordinates of any moving object and convert it to angles for rotation of the servo motors in the robot joints.Servos are controlled using arduino uno.

While i am using the example sweep program in arduino, the motors are rotating perfectly,ie, 30 deg for 30 deg. But while doing real time tracking,ie, angle values are continuously sent, the motors are not rotating as expected. 3 angles are there. output from matlab is as in the sequnce.angle 1, angle2,angle3 for base , middle and gun.(robot,s 3 joints).they are send in that sequence.but,whatever changes in angular values occur,they wil rotate only in some specified 2 or 3 angles for any output value.

I dont know what to do.Can anybody please help me, I am nearing the end of my project work and hav to make it correct as soon as possible.Please do respond
i wil paste my arduino command here


#include <Servo.h>
int ibyte;
int mymotors=0;
int i=0;
Servo gun; //AT 9
Servo middle;//AT 10
Servo base;// AT 11


void setup()
{
  gun.attach(9);  // attaches the servo on pin 9 to the servo object
  middle.attach(10);
  base.attach(11);

  Serial.begin(9600);
//  delay(2500);
 
  }

void loop()
{
 mymotors = i%3;
 if(Serial.available())
 
  {
  ibyte =0;
  //Serial.listen()
  if(mymotors==0)
  {
    ibyte=Serial.read();
    base.write(ibyte);
    delay(500);
    //base.write(90);

   
    //Serial.write(ibyte);
    }
   
 if(mymotors==1)
  {
    ibyte=Serial.read();
    middle.write(ibyte);
    delay(500);
   //middle.write(70);

  }
 
 if(mymotors==2)
  {
    ibyte=Serial.read();
    gun.write(ibyte);
    delay(500);
  //gun.write(90);

  }
      i = i+1;

  }
}


ALso, please do tell me..is there any specific code or something in arduino that can make the robot go to its home position.
Logged

0
Offline Offline
Shannon Member
****
Karma: 207
Posts: 12200
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please follow the guidelines and post code
Code:
// as code, like this - use the # button

Also you provide no concrete details of any of the kit - which servos, what robot, etc etc...  Try to imagine
that your posting is our only source of information about the problem you have smiley-cool
Logged

[ I won't respond to messages, use the forum please ]

India
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok...
thanx for ur reply.. smiley
i am developing a sentry robot.3 dof robot.
I am ardiuno uno board.servomotors used are RKI-1211.i am using a HD cam as image capturing device.this captured video is processed for object tracking using simulink.the obtained co-ordinates of the object in simulink are called using matlab.This matlab file also includes commands for communicating with arduino.Matlab transfers the values to arduino as i said earlier and the uno script does the rest.the uno script i have posted.
what else do u need to know...

The sentry robot needs to get the object position and orient to that position online.but while operating online,I am not getting corect rotational values but ,when i am manually inputing a vlaue,its rotation is correct.
thats the problem..if u can help..please do.. smiley smiley smiley
Logged

Offline Offline
Faraday Member
**
Karma: 62
Posts: 3031
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your code does not make a lot of sense.   I could not follow how you expect the serial reading to work.

You should not be doing a serial.read() if there is no byte available.  I would do the reading in one place
in the loop   and then do whatever you are supposed to do with the servo.   Your logic may be correct
but it is very hard to tell.
Logged

New Jersey
Online Online
Faraday Member
**
Karma: 67
Posts: 3702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your modulus arithmetic looks like it's going to give you trouble. The i variable will quickly overflow into negative territory and while it is there, nothing will be read or acted upon. Rather than incrementing for ever, use modulus to keep it in the range you want.
Logged

Pages: [1]   Go Up
Jump to: