View unanswered posts | View active topics It is currently Fri Nov 22, 2019 11:34 am






Reply to topic  [ 7 posts ] 
Encoder program won't stop when it's supposed to 
Author Message
Rookie

Joined: Wed Oct 08, 2014 2:50 pm
Posts: 5
Post Encoder program won't stop when it's supposed to
I am new to teaching ROBOTC, so I am sorry if this question is silly. A student of mine wrote a program that's meant to use shaft encoders to control distance. He wrote and successfully compiled the program. However, when he downloaded it to the robot, the program ran and ran without stopping. I can't seem to spot the error because I'm new at this as well. I've included his program below. Any help would be greatly appreciated :-)

task main ()
{
SensorValue[rightEncoder] = 0;
SensorValue[leftEncoder} = 0;

while(SensorValue[rightEncoder] < 687)
{
motor[rightMotor] = 63;
motor[leftMotor] = 63;
}

}


Wed Oct 08, 2014 2:58 pm
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post Re: Encoder program won't stop when it's supposed to
There are a couple things that could be going on here:
1) It is possible that the encoder count is decreasing instead of increasing.
2) The commands to shut the motors off needs to be added before the last brace.
Good luck


Thu Oct 09, 2014 12:19 pm
Profile
Rookie

Joined: Wed Oct 08, 2014 2:50 pm
Posts: 5
Post Re: Encoder program won't stop when it's supposed to
Thanks for your answer! I had thought about your first suggestion, but if the robot is moving forward, shouldn't the numbers count up? Also, I didn't think you had to program the motors to stop. I thought they would stop on their own once the value of the encoder was reached.


Thu Oct 09, 2014 12:38 pm
Profile
Rookie

Joined: Wed Feb 24, 2010 11:51 pm
Posts: 31
Post Re: Encoder program won't stop when it's supposed to
Also, as a matter of style, it's not necessary to keep setting the motor[] values inside the while loop. You'll typically want to turn the motors on once, then wait for the encoder, then turn the motors off. Like this:
Code:
motor[rightMotor] = 63;
motor[leftMotor] = 63;

while(SensorValue[rightEncoder] < 687)
{
}

motor[rightMotor] = 0;
motor[leftMotor] = 0;


Terry

_________________
Vex & FLL Coach and robotics instructor


Thu Oct 09, 2014 12:41 pm
Profile
Rookie

Joined: Wed Feb 24, 2010 11:51 pm
Posts: 31
Post Re: Encoder program won't stop when it's supposed to
aeichelberger wrote:
Thanks for your answer! I had thought about your first suggestion, but if the robot is moving forward, shouldn't the numbers count up? Also, I didn't think you had to program the motors to stop. I thought they would stop on their own once the value of the encoder was reached.


The sign of the direction of the encoder is independent from the sign of the direction of the motor. You can typically control this in the Motor and Sensors setup if you want them to match, but not always. If a 2-wire motor's cable is flipped where it's plugged in, that will invert the direction of the motor in the same way that the "reverse" checkbox does in the Motor and Sensors setup.

motors will never stop on their own. They will remember whatever value you last set into them. That's why you only have to turn them on once before waiting for the encoder to count up. You then have to tell them to stop by assigning 0.

Granted, all motors should stop when the program ends as a safety feature, but it's considered good form to stop them on purpose before exiting from the main task.

Terry

_________________
Vex & FLL Coach and robotics instructor


Thu Oct 09, 2014 12:49 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post Re: Encoder program won't stop when it's supposed to
aeichelberger wrote:
Thanks for your answer! I had thought about your first suggestion, but if the robot is moving forward, shouldn't the numbers count up? Also, I didn't think you had to program the motors to stop. I thought they would stop on their own once the value of the encoder was reached.


Quick note on this; if you are using the Optical Shaft Encoders (and not the Integrated Motor Encoders), then the polarity of the encoders (and if they increment/decrement when turned in a 'forward' direction) is going to be determined by the order that the encoder's wires are plugged into the Cortex. Optical Shaft Encoders use a two wire input system, and the two wires must be in sequential ports in order to work properly in ROBOTC.

If an Optical Encoder is decrementing (counting down) while the motor is moving in the forward direction, try flipping the ports that the wires are plugged into. For instance, if you are encountering this issue and the wires are plugged into ports 5 and 6, take the wire from 6 and plug it into 5, and the wire from 5 into 6. This should flip the polarity and resolve the issue for you.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.


Thu Oct 09, 2014 1:10 pm
Profile
Rookie

Joined: Wed Oct 08, 2014 2:50 pm
Posts: 5
Post Re: Encoder program won't stop when it's supposed to
Flipping the ports worked! Thanks so much for the tip!
-Amanda


Thu Oct 09, 2014 2:41 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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.