|
Page 1 of 1
|
[ 3 posts ] |
|
| Author |
Message |
|
bradford
Rookie
Joined: Wed Mar 04, 2009 9:48 am Posts: 1
|
 programming help
I am having trouble getting the program to end when the timer expires. I want the robot to stop once the 5 seconds is up no matter where it is in the program. The program below is not working. It seems to be ignoring the timer altogether. Any suggestions?
#pragma config(Sensor, in1, downLimit, sensorTouch) #pragma config(Sensor, in2, rightEncoder, sensorQuadEncoder, int5) #pragma config(Sensor, in3, leftEncoder, sensorQuadEncoder, int6) #pragma config(Sensor, in4, upLimit, sensorTouch) #pragma config(Sensor, in5, sonarSensor, sensorSONAR, int1) #pragma config(Sensor, in6, Touch, sensorTouch) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// power level set at 30 void moveStraight()
{ if(SensorValue[leftEncoder] > SensorValue[rightEncoder]) { motor[port3] = 25; motor[port2] = 30; } if(SensorValue[rightEncoder] > SensorValue[leftEncoder]) { motor[port3] = 30; motor[port2] = 25; } if(SensorValue[leftEncoder] == SensorValue[rightEncoder]) { motor[port3] = 30; motor[port2] = 30; } }
task main() { wait1Msec(2000); bMotorReflected[port2] = 1; //Reflects the direction of the motor on port2 ClearTimer(T4); int i = 0;
while(time10[T4] < 500 && i < 1) { if(time10[T4] < 500) { while(SensorValue[downLimit] == 0) { motor[port6] = -31; //move arm down to limit switch } }
if(time10[T4] < 500) { SensorValue[leftEncoder] = 0; SensorValue[rightEncoder] = 0; while(SensorValue[sonarSensor] >= 3 || SensorValue[sonarSensor] <= 0) { moveStraight(); } motor[port3] = 0; motor[port2] = 0; wait1Msec(250); }
if(time10[T4] < 500) { while(SensorValue[upLimit] == 0) { motor[port6] = 31; } } i++; } motor[port3] = 0; motor[port2] = 0; motor[port6] = 0; }
|
| Wed Mar 04, 2009 10:01 am |
|
 |
|
fryfrog
Rookie
Joined: Sat Aug 30, 2008 2:25 am Posts: 25
|
 Re: programming help
I'm not the best at visually decoding and debugging, I usually have to compile and test on a bot. I think your problem is with the while loop, right outside of it you set i to 0. Your while loop says "while i'm less than 500 seconds and also while i is less than 1" At the end of your first loop, you increment i by 1 and i is no longer less than 1. I think 
|
| Fri Mar 20, 2009 12:39 am |
|
 |
|
fryfrog
Rookie
Joined: Sat Aug 30, 2008 2:25 am Posts: 25
|
 Re: programming help
Also, I think the "if" portion of the following is redundant, you should not need that. The while loop will run so fast, that you'll catch 5 seconds very quickly. Also, you are going to get stuck in those while loops when the value is met (maybe you mean to do this).
|
| Fri Mar 20, 2009 12:41 am |
|
|
|
Page 1 of 1
|
[ 3 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 4 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|