Log in

View Full Version : Autonomous calculations


Tz0m
20-02-2007, 12:52
How exactly can I implement my formula to calculate distance into my autonomous code? I want the robot to move forward while the distance is greater than a certain number. If I use a while loop the rc crashes and does nothing. This is the code I have so far:

while (autonomous_mode || p3_sw_trig == 1) /* DO NOT CHANGE! */
{
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */
{
Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */

// Start autonomous code

// call camera functions
Servo_Track();
Camera_Handler();
Tracking_Info_Terminal();

if (Get_Tracking_State() == CAMERA_ON_TARGET)
{
pwm13 = pwm14 = 104;
pwm15 = pwm16 = 150;
}
else if (Get_Tracking_State() == SEARCHING)
{
pwm13 = pwm14 = 150;
pwm15 = pwm16 = 104;
}

// End autonomous code

PWM(pwm13,pwm14,pwm15,pwm16);

Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
}

How can I build my code around this?

Alan Anderson
20-02-2007, 13:50
The User_Autonomous_Code() function is a while loop. Put your calculation in the middle of it, where it will be executed every time through the loop.

Do you want the calculation to be made only when the camera is locked on the light? If so, put it inside the first if.

bcieslak
20-02-2007, 13:50
We use the value of tilt servo to tell us when we want to stop. As we get closer to the light the camera must look up higher. Tilt servo value decreases the higher we look. When we get below a certain value we stop.

Determine different tilt servo values associated with different distances from the target to create a ranging system..OR create a formula to convert tilt servo value to distance from light.

BC

Mandi_|<o>|
20-02-2007, 14:26
We use the value of tilt servo to tell us when we want to stop. As we get closer to the light the camera must look up higher. Tilt servo value decreases the higher we look. When we get below a certain value we stop.

Determine different tilt servo values associated with different distances from the target to create a ranging system..OR create a formula to convert tilt servo value to distance from light.

BC


That's what I'm doing, the problem is, we made an auto-pan routine that takes us near the target, but sometimes we get there diagonally. We're still looking for the perfect routine, unfortunately it seems to be very far...

Tz0m
20-02-2007, 14:36
Thanks for the help. Just for testing, we tried using the tilt servo value to get it to stop. This is our code:

if (Get_Tracking_State() == CAMERA_ON_TARGET)
{
if ((int) TILT_SERVO < 170)
{
pwm13 = pwm14 = 104;
pwm15 = pwm16 = 157;
}
else if ((int) TILT_SERVO > 170)
{
pwm13 = pwm14 = pwm15 = pwm16 = 127;
}
}
else if (Get_Tracking_State() == SEARCHING)
{
pwm13 = pwm14 = pwm15 = pwm16 = 127;
}

However, the robot continues to drive forward. The camera seems to stop moving once we initiate autonomous mode. We have these three functions, Servo_Track(); Camera_Handler(); and Tracking_Info_Terminal();, called right after Getdata(&rxdata);.

Bomberofdoom
24-02-2007, 06:15
hmmm...mabye you should try with angles? take the calculation of the tilt angle from terminal.c and find what is your requested tilt angle where the robot will stop in your opinion and then do the tilt angle in relation to the distance(too far, go forward. too close, stop.).
Shouldn't be too complicated and it worked for us, but if you prefer to use your own function like that, I have no idea what the problem can be...:confused: