I am using a LSM303 sensor to compute a heading and I want to turn my robot to a heading.
I have the simple code here:
int mag;
mag = compass.heading((LSM303::vector){0,-1,0});; //read the angle of the robot
Serial.println(mag);
while (mag != angle){
//while it isn't the desired angle turn and continue to update the robot angle
trex.write(0xE9);
trex.write(90);
trex.write(90);
mag = compass.heading((LSM303::vector){0,-1,0});; //read the angle of the robot
}
In a function called with a speed and angle (heading), the trex part tells the motor controller to turn on a point and the while loop should test for when the desired heading is reached. However, testing using a couple of instances of Serial.println(mag);
I have determined that once inside the while loop, mag never changes which just means the robot turns indefinitely.
I have no idea why this would happen. Perhaps someone here does?
Thanks.
mag = compass.heading((LSM303::vector){0,-1,0});;
by itself and then move the compass and run it again it performs correctly and the heading changes as expected. $\endgroup$ – mark mcmurray May 2 '13 at 21:43