|
Page 1 of 1
|
[ 3 posts ] |
|
| Author |
Message |
|
Mr. Roboto
Rookie
Joined: Thu Mar 05, 2009 11:46 am Posts: 2
|
 Time's not on my side
I've been having a problem using the timer in my program. I'm trying to have my robot run for 10 seconds, moving forward during the first 5 (but stoping if the front bumper is touched) and moving backward during the last 5 (but stoping if the back bumper is touched). I'm using ROBOTC for IFI 1.40. The robot looks for the bumpers to be touched, and won't end the while loop dependant on time until they are. Here's my code:  |  |  |  | Code: #pragma config(Sensor, in1, flim, sensorTouch) #pragma config(Sensor, in2, blim, sensorTouch) #pragma config(Sensor, in3, Rencode, sensorRotation) #pragma config(Sensor, in4, Lencode, sensorRotation) #pragma config(Sensor, in5, bateye, sensorSONAR, int1) #pragma config(Sensor, in6, bbump, sensorTouch) #pragma config(Sensor, in7, fbump, sensorTouch) #pragma config(Motor, port1, arm, tmotorNormal) #pragma config(Motor, port2, rm, tmotorNormal) #pragma config(Motor, port3, lm, tmotorNormal) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main() { bMotorReflected[rm] = 1; SensorValue[Rencode] = 0; SensorValue[Lencode] = 0; ClearTimer(T1);
while(time10[T1] < 500) { while(SensorValue[fbump] == 0) { motor[rm] = 60; motor[lm] = 60; } motor[rm] = 0; motor[lm] = 0; } while((time10[T1] >= 500) && (time10[T1] <= 1000)) { while((SensorValue[bbump] == 0)) { motor[rm] = -60; motor[lm] = -60; } motor[rm] = 0; motor[lm] = 0; } }
|  |  |  |  |
I tried having each while statement check the time; though this works, it seems too cumbersome to be the best solution. Any help with this problem would be greatly appreciated.
|
| Fri Mar 06, 2009 11:35 am |
|
 |
|
fizxguy
Rookie
Joined: Fri Feb 06, 2009 11:43 am Posts: 11
|
 Re: Time's not on my side
Well, I am no expert. But it would seem to me that you should use IF-Else statements rather than while loops to run the button check. For example
while(time10[T1] < 500) { if(sensorValue[fbump==0] { motor[rm] = 60; motor[lm] = 60; } else { motor[rm] = 0; motor[lm] = 0; } }
The same would be true for your NEXT 5 seconds. Try it! I am thinking it will work!
Ken
|
| Sun Mar 08, 2009 5:15 pm |
|
 |
|
Mr. Roboto
Rookie
Joined: Thu Mar 05, 2009 11:46 am Posts: 2
|
 Re: Time's not on my side
That sort of works, but the touch sensor has to stay depressed. If what it bumps falls over or is moved a bit, this would be a problem. To get around it, here's what I did:  |  |  |  | Code: #pragma config(Sensor, in1, flim, sensorTouch) #pragma config(Sensor, in2, blim, sensorTouch) #pragma config(Sensor, in3, Rencode, sensorRotation) #pragma config(Sensor, in4, Lencode, sensorRotation) #pragma config(Sensor, in5, bateye, sensorSONAR, int1) #pragma config(Sensor, in6, bbump, sensorTouch) #pragma config(Sensor, in7, fbump, sensorTouch) #pragma config(Motor, port1, arm, tmotorNormal) #pragma config(Motor, port2, rm, tmotorNormal) #pragma config(Motor, port3, lm, tmotorNormal) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main() { bMotorReflected[rm] = 1; SensorValue[Rencode] = 0; SensorValue[Lencode] = 0; ClearTimer(T1);
int stp = 0; while(time10[T1] < 500) { if(stp == 0) { motor[rm] = 60; motor[lm] = 60; if(SensorValue[fbump] != 0) { stp = 1; } } else { motor[rm] = 0; motor[lm] = 0; } }
int hammertime = 0; while((time10[T1] >= 500) && (time10[T1] <= 1000)) { if(hammertime == 0) { motor[rm] = -60; motor[lm] = -60; if(SensorValue[bbump] != 0) { hammertime = 1; } } else { motor[rm] = 0; motor[lm] = 0; } } } |  |  |  |  |
Thanks for the suggestions!
|
| Tue Mar 10, 2009 11:01 am |
|
|
|
Page 1 of 1
|
[ 3 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 2 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
|
|