View unanswered posts | View active topics It is currently Wed Apr 16, 2014 1:35 am






Reply to topic  [ 2 posts ] 
labyrinth 
Author Message
Rookie

Joined: Wed Jul 10, 2013 12:50 pm
Posts: 1
Post labyrinth
I am having a problem with the right turn in labyrinth.
[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)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*+++++++++++++++++++++++++++++++++++++++++++++| Notes |++++++++++++++++++++++++++++++++++++++++++++++
Forward for Distance with Encoders

This program instructs the robot to move forward for 5 rotations of the left shaft encoder.
There is a two second pause at the beginning of the program.

The used for feedback should be cleared just before it starts counting using the
"nMotorEncoder(encoder) = 0;". This helps ensure consistancy.

Robot Model(s): NXT REMBOT

[I/O Port] [Name] [Type] [Description]
Motor Port 2 rightMotor NXT Motor Right side motor
Motor Port 3 leftMotor NXT Motor Left side motor

----------------------------------------------------------------------------------------------------*/


//+++++++++++++++++++++++++++++++++++++++++++++| MAIN |+++++++++++++++++++++++++++++++++++++++++++++++
task main()
{
wait1Msec(2000); // 2 Second Delay

//Clear Encoders
nMotorEncoder[rightMotor] = 0;
nMotorEncoder[leftMotor] = 0;

while(nMotorEncoder[leftMotor] < 1220) // While less than 5 rotations on the leftEncoder...
{
//...Move Forward
motor[rightMotor] = 50;
motor[leftMotor] = 50;
}

wait1Msec(2000); //Robot waits for 2000 milliseconds before executing program

nMotorEncoder[rightMotor] = 0; //Set the encoder so that it starts counting at 0

while(nMotorEncoder(rightMotor) < 180) //While rightEncoder has counted less than 1800 counts
{
//Turn Left
motor[rightMotor] = 100; //Motor on motorB is run at full (100) power forward
motor[leftMotor] = -100; //Motor on motorC is run at full (-100) power reverse
}

nMotorEncoder[leftMotor] = 0; //Set the encoder so that it starts counting at 0

//Clear Encoders
nMotorEncoder[rightMotor] = 0;
nMotorEncoder[leftMotor] = 0;

while(nMotorEncoder[leftMotor] < 1050) // While less than 5 rotations on the leftEncoder...
{
//...Move Forward
motor[rightMotor] = 50;
motor[leftMotor] = 50;
}

wait1Msec(2000); //Robot waits for 2000 milliseconds before executing program

nMotorEncoder[leftMotor] = 0; //Set the encoder so that it starts counting at 0

while(nMotorEncoder(leftMotor) < 60) //While leftEncoder has counted less than 1800 counts
{
//Turn Right
motor[rightMotor] = -100; //Motor on motorB is run at full (-100) power reverse
motor[leftMotor] = 100; //Motor on motorC is run at full (100) power forward

nMotorEncoder[rightMotor] =0; //Set the encoder to 0
nMotorEncoder[leftMotor] = 0;

}

wait1Msec(2000); //Robot waits for 2000 milliseconds before executing program][/code]


Wed Jul 10, 2013 1:13 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 533
Post Re: labyrinth
Quote:
nMotorEncoder[rightMotor] = 0; //Set the encoder so that it starts counting at 0

while(nMotorEncoder(rightMotor) < 180) //While rightEncoder has counted less than 1800 counts
{
//Turn Left
motor[rightMotor] = 100; //Motor on motorB is run at full (100) power forward
motor[leftMotor] = -100; //Motor on motorC is run at full (-100) power reverse
}


I've bolded the two parts that you will need to look at; when coding, sometimes that smallest typo can cause big problems.

Edit: Looking through the rest of your program, I see that you are using somewhat small (less than 100) encoder count values for your while loops. Remember, the encoder counts the 'ticks' that the shaft rotates, *not* degrees that the robot is turning.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Wed Jul 10, 2013 1:23 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.