Getting correct rotations for servo in real time

Hi frnds :),
I am a new guy in this ,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

// delay(2500);


void loop()
mymotors = i%3;

ibyte =0;





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.

Please follow the guidelines and post 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 8)

ok... thanx for ur reply.. :) 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.. :) :) :)

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 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.

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.