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

Line Runner
http://www.robotc.net/forums/viewtopic.php?f=55&t=6179
Page 1 of 1

Author:  jillmobley [ Sun Jul 07, 2013 10:19 am ]
Post subject:  Line Runner

This code seems to complete the assigned task, but the challenge does not show complete.
Any assistance is appreciated!



#pragma config(StandardModel, "Virtual Worlds NXT")
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/* Virtual Worlds Configuration (Type - Name):
Motor Port A: NXT Motor - gripperMotor
Motor Port B: NXT Motor - rightMotor
Motor Port C: NXT Motor - leftMotor
Sensor Port 1: Touch Sensor - touch
Sensor Port 2: Compass Sensor - compass
Sensor Port 3: Light Sensor - light
Sensor Port 4: Sonar Sensor - sonar
*/



int countValue;
int lastSeen;

void forwardlines(int numLines)
{
lastSeen = 1;
countValue = 0;

while(countValue < numLines)
{
if (SensorValue(light) < 75)
{
motor[motorC]= 50;
motor[motorB]= 50;

if(lastSeen == 1)
{
countValue = countValue + 1;
lastSeen = 0;
}
}

else
{
motor[motorC]= 50;
motor[motorB]= 50;
lastSeen = 1;
}
}
}

void reverse(int numLines)
{
lastSeen = 1;
countValue = 0;

while(countValue < numLines)
{
if (SensorValue(light) < 75)
{
motor[motorC]= -50;
motor[motorB]= -50;

if(lastSeen == 1)
{
countValue = countValue + 1;
lastSeen = 0;
}
}

else
{
motor[motorC]= -50;
motor[motorB]= -50;
lastSeen = 1;
}
}
}

task main()
{
forwardlines(2);
reverse(2);
forwardlines(3);
reverse(3);
forwardlines(4);
reverse(4);
forwardlines(5);
reverse(5);
forwardlines(6);
reverse(6);
}

Attachments:
line runner.c [1.38 KiB]
Downloaded 546 times

Author:  rcahoon [ Sun Jul 07, 2013 8:16 pm ]
Post subject:  Re: Line Runner

Hi Jill,
When I ran your code, the robot didn't actually touch the last line in each forward movement (it broke the plane, but the wheels didn't touch). The green highlight shows which line the robot should touch next and will disappear once this has been accomplished. The problem is that the light sensor is placed in front of the wheels. The easiest fix was to add a 500 millisecond delay to the end of your forward function, so that the robot will continue forward for another half second, which was enough to make the robot actually touch the lines with its wheels.

Cheers,
--Ryan

Author:  jillmobley [ Sun Jul 07, 2013 10:51 pm ]
Post subject:  Re: Line Runner

Thank you! I will try this.

Jill

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