View unanswered posts | View active topics It is currently Fri Nov 21, 2014 8:13 pm






Reply to topic  [ 2 posts ] 
BasketBallDrill 
Author Message
Post BasketBallDrill
My program works to go forward to the first line and then reverses to return tot he start position. Then nothing.
I can not figure out what to do. help please.


task main() //Begin
{
wait1Msec(2000); // Robot waits for 2000 milliseconds before executing program
SensorValue[rightEncoder] = 0; SensorValue[leftEncoder] = 0;

//While the encoders have spun less than 3 rotations
while (SensorValue[rightEncoder] <720)
{
// Move forward at 3/4 power for 3 seconds
motor[rightMotor] = 95; // Motor on port2 is run at full (127) power forward
motor[leftMotor] = 95; // Motor on port3 is run at full (127) power forward
}

//Turn motor off and stop for 1/2 sec.
motor[rightMotor] = 0; motor[leftMotor] = 0; wait1Msec(500);

SensorValue[rightEncoder] = 0; SensorValue[leftEncoder] = 0;

//While the right encoder has spun lesss than 1 rotation
while(SensorValue[rightEncoder] < 720)
{
//Turn left
motor[rightMotor] = -95;
motor[leftMotor] = -95;
}
wait1Msec(500); //wait 1/2 sec

//Turn motor off and stop
motor[rightMotor] = 0; motor[leftMotor] = 0; wait1Msec(500);

/* The following code does not execute for some reason. **********************************************************/

SensorValue[rightEncoder] = 0; SensorValue[leftEncoder] = 0;
while (SensorValue[rightEncoder] < 1440)
{
// Move forward at 3/4 power
motor[rightMotor] = 95; // Motor on port2 is run at 3/4 power forward
motor[leftMotor] = 95; // Motor on port3 is run at 3/4 power forward
}

}// End of Program


Tue Jun 25, 2013 2:26 pm
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 609
Post Re: BasketBallDrill
Code:
SensorValue[rightEncoder] = 0; SensorValue[leftEncoder] = 0;

//While the right encoder has spun lesss than 1 rotation
while(SensorValue[rightEncoder] < 720)
{
//Turn left
motor[rightMotor] = -95;
motor[leftMotor] = -95;
}


This is where the problem lies. Let's look at it step by step.

1) First we clear the encoders assigning 0 values to the left and right encoders. No problem here.
2) Next, we want to keep running the loop while the value of the right encoder is less than 720. We've used this before, so it should work here as well, right?
3) Finally, we keep our motors moving at a power level of negative 95 until the encoder counts reach a positive 720...Uh oh.

Remember, when you turn on your motors on in a negative direction, the encoders will count in a negative direction. So if you start with an encoder count of zero, and start counting in a negative direction from there, when will you reach the positive 720 value?

Now that we know what the problem is, how can we fix this? :)

_________________
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


Tue Jun 25, 2013 3:01 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.