ROBOTC.net forums
http://robotc.net/forums/

Time's not on my side
http://robotc.net/forums/viewtopic.php?f=11&t=1327
Page 1 of 1

Author:  Mr. Roboto [ Fri Mar 06, 2009 11:35 am ]
Post subject:  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.

Author:  fizxguy [ Sun Mar 08, 2009 5:15 pm ]
Post subject:  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

Author:  Mr. Roboto [ Tue Mar 10, 2009 11:01 am ]
Post subject:  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!

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/