View unanswered posts | View active topics It is currently Sat Feb 23, 2019 12:57 am

Reply to topic  [ 2 posts ] 
Encoders locked in While Loop - Should PID be used? 
Author Message

Joined: Sat Mar 05, 2011 7:55 pm
Posts: 3
Post Encoders locked in While Loop - Should PID be used?
I have been having Tetrix encoder issues. When I use the sample code to move to an encoder position, sometimes the motors will appear to reach their location, but will not exit from the While loop. They will stop, but not drop out of the loop and the program is hung. I do NOT have PID enabled. I have added delay in the loop and the EndTimeSlice() function call, but it still does not work most of the time. I can hear the motors hum when they get in this state as if they have not quite reached their position. If I then push the robot just a little bit, the program will continue. If I enable PID, then I do not have this problem. In other posts, I see it is recommended not to use PID. It appears I need do need to use PID or my program is getting hung. I have tried this on three different motors/encoders and it happens about 50% of the time. I have used many different power levels, too, but still cannot get it to work most of the time. Should I be having this problem? PID does take a little longer to execute, since it slows down the motor as it gets closer to the set point.

Any suggestions?

//clear the TETRIX encoders for the motors specified
nMotorEncoder[motorD] = 0;
nMotorEncoder[motorE] = 0;
wait1Msec(200); // not sure if I need this

while (nMotorEncoder[motorD] < Encoder_Ticks)
//turn both motors on at specified percent power
motor[motorD] = 50;
motor[MotorE] = 50;

//turn both motors off
motor[Motor1] = 0;
motor[Motor2] = 0;

Thu Apr 07, 2011 5:00 pm
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: Encoders locked in While Loop - Should PID be used?
Please show us your pragmas. From your description, your PID seemed to be enabled. Also, you should remove the EndTimeSlice() call in the while loop.

Thu Apr 07, 2011 8:28 pm
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.