View unanswered posts | View active topics It is currently Wed Oct 22, 2014 5:40 pm






Reply to topic  [ 3 posts ] 
Line Runner Issues 
Author Message
Rookie

Joined: Wed Feb 19, 2014 3:07 pm
Posts: 6
Post Line Runner Issues
Hi all,
I think I put together a program that will accomplish the task, but it doesn't. I have tried putting variables into a global context but no effect. I have tweaked the threshold number on the light sensor but it either causes robot to go forward till failure or when it see the red line, go backward and fall off the board. I looked at another code from a person called Jill. It seems that we have somewhat the same idea, but I am not understanding her usage of the variable "lastseen". (Hers works by the way, once the suggestion to use wait1Msec(750) is implemented to make the wheels cross the line as well as the sensor). Mine is the same in that I am using function calls, so I must be doing something wrong in how I am using the variables count and target. Any help would be appreciated. When I use the debugging windows when I run the program - the varialbe values don't appear locally and don't increase in value globally. Obviously I messed up somewhere but I am not seeing it.
Thanks
Jim LovellFord
james_lovellford@enumclaw.wednet.edu
#pragma config(Sensor, S1, touchSensor, sensorTouch)
#pragma config(Sensor, S2, compassSensor, sensorVirtualCompass)
#pragma config(Sensor, S3, lightSensor, sensorLightActive)
#pragma config(Sensor, S4, sonarSensor, sensorSONAR)
#pragma config(Motor, motorA, gripperMotor, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorB, rightMotor, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, leftMotor, tmotorNormal, PIDControl, encoder)
int target = 0;
int count = 0;
void Forward(int target)
{
int count = 0;
while(count<target)
{
motor(motorB) = 75;
motor(motorC) = 75;

if(sensorValue(lightSensor)<59)
{
count = count + 1;
}
}
}
void Reverse(int target)
{
int count = 0;
while(count<target)
{
motor(motorB) = -75;
motor(motorC) = -75;
wait1Msec(750);
if(sensorValue(lightSensor)<59)
{
count = count + 1;
}
}
}
task main()
{
wait1Msec(2000);
Forward(2);
Reverse(2);
Forward(3);
Reverse(3);
Forward(4);
Reverse(4);

}


Thu Feb 20, 2014 5:01 pm
Profile
Expert
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 137
Post Re: Line Runner Issues
Well, when going forward, your robot is quickly going to see however many lines it is supposed to because you have nothing preventing it from counting multiple times when it is over one line. I would suggest storing the value the light sensor sees in a variable, so that you can compare the new value the next time the loop executes with the previous value. That way, you can program it so that it only counts each line once as it passes over it. (This is much more sure-fire than using a wait1Msec() command.)

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://cof7468.weebly.com/.


Thu Feb 20, 2014 5:29 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Post Re: Line Runner Issues
BurningLights wrote:
[...] This is much more sure-fire than using a wait1Msec() command.

BurningLights,
The kind of method you describe would be more robust, but I think using time-based delay is sufficient in this case.


Jim,
The code worked for me once I moved the call to wait1Msec(750) in Reverse() into the if statement so that the wait only occurs after the robot sees a line. I also added the same wait statement into the if statement in Forward().

Here's the code with those modifications:

Code:
#pragma config(Sensor, S1, touchSensor, sensorTouch)
#pragma config(Sensor, S2, compassSensor, sensorVirtualCompass)
#pragma config(Sensor, S3, lightSensor, sensorLightActive)
#pragma config(Sensor, S4, sonarSensor, sensorSONAR)
#pragma config(Motor, motorA, gripperMotor, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorB, rightMotor, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, leftMotor, tmotorNormal, PIDControl, encoder)
int target = 0;
int count = 0;
void Forward(int target)
{
   int count = 0;
   while(count<target)
   {
      motor(motorB) = 75;
      motor(motorC) = 75;

      if(sensorValue(lightSensor)<59)
      {
         count = count + 1;
         wait1Msec(750);
      }
   }
}
void Reverse(int target)
{
   int count = 0;
   while(count<target)
   {
      motor(motorB) = -75;
      motor(motorC) = -75;
      if(sensorValue(lightSensor)<59)
      {
         count = count + 1;
         wait1Msec(750);
      }
   }
}
task main()
{
   wait1Msec(2000);
   Forward(2);
   Reverse(2);
   Forward(3);
   Reverse(3);
   Forward(4);
   Reverse(4);
}


Best,
--Ryan

_________________
Ryan Cahoon
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT


Thu Feb 20, 2014 5:45 pm
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.