View unanswered posts | View active topics It is currently Sun Dec 21, 2014 4:54 am






Reply to topic  [ 3 posts ] 
Time's not on my side 
Author Message
Rookie

Joined: Thu Mar 05, 2009 11:46 am
Posts: 2
Post 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
Profile
Rookie

Joined: Fri Feb 06, 2009 11:43 am
Posts: 11
Post 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
Profile
Rookie

Joined: Thu Mar 05, 2009 11:46 am
Posts: 2
Post 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.