Trouble updating LASER_POINTS position
Shane from United States  [10 posts]
13 year
The goal of this code is to get the coordinates represented by COG_X and COG_Y which represent a moving person and get the coordinates from the Laser_Spot module represented by LASER_POINTS. A laser point is picked up by the Laser_Spot module and the laser is attached to two servo-motors for horizontal and vertical motion. The idea is to have the laser track a moving person by moving the servos to the position of COG. This is done by the following cScript code:

int cogX = getVariable("COG_X");
int cogY = getVariable("COG_Y");
int laser[2];                                //array to contain laser point coordinates
int SERVO_VALUE_X=1000;        
int SERVO_VALUE_Y=1000;
int x = 1000/640; //value of PWM to move a servo 1 pixel
int y = 1000/480;

laser_x = getArrayVariable("LASER_POINTS",laser,1);  //insert x cooridinate      
                                                                             // of laser position into                                                                                          //                                                                          //laser_x
laser_y = getArrayVariable("LASER_POINTS",laser,2); // same as above for y

if (laser[0] < cogX) //if laser point x coordinate is less the COG x coordinate
                            //move right

    setVariable ("SERVO_VALUE_X",SERVO_VALUE_X);
else if (laser[0] > cogX) //if laser point x coordinate is greater than COG      //                                //coordinate move left

    setVariable ("SERVO_VALUE_X",SERVO_VALUE_X);

if (laser[1] < cogY)  //same as above for y
    setVariable ("SERVO_VALUE_Y",SERVO_VALUE_Y);
else if (laser[1] > cogY) //same as above for y
    setVariable ("SERVO_VALUE_Y",SERVO_VALUE_Y);

The problem that is occurring right now is the SERVO_VALUE_X and SERVO_VALUE_Y values stay at the values 1001 for x and 1002 for y.
Any help with this problem would be appreciated.

Thank you

Anonymous 13 year
Couple of things were wrong with this script. The main one is the call to getArrayVariable. The values are placed in the array 'laser' with the third number being the max size of that array (otherwise you may cause an out of bounds error) and is NOT the index to a value. Once called (and call it only ONCE) both x and y should be in laser[0] and laser[1] respectively.

Try the attached and see if that works better.


Shane from United States  [10 posts] 13 year
Thanks for the response. I know the script came out looking a little funky from when i copied and pasted the code. I fixed the problem by using getVariable("LASER_POINTS:0") and getVariable("LASER_POINTS:1") to get out the x and y coordinates respectively of the laser point.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index