View unanswered posts | View active topics It is currently Wed Aug 20, 2014 3:10 am






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

Joined: Sat May 25, 2013 6:01 pm
Posts: 10
Post 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 235 times
Sun Jul 07, 2013 10:19 am
Profile
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Post 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

_________________
Ryan Cahoon
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT


Sun Jul 07, 2013 8:16 pm
Profile
Rookie

Joined: Sat May 25, 2013 6:01 pm
Posts: 10
Post Re: Line Runner
Thank you! I will try this.

Jill


Sun Jul 07, 2013 10:51 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 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

Search for:
Jump to:  



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