View Full Version : programing the vex optical shaft encoder
youngWilliam14
08-11-2007, 13:21
i'm having a small problem w/ optical shaft encoders on the vex swervebot i'm building. the encoders tell the rc how far the drive pods have turned.
in the program, i start all the encoders, and have them retrive to variables. once the vairables reach a the right value, the pods stop turning, then i reset the variables when the pods need to turn back.
my problem is that i allign all the pods, but when i test the program, they don't all turn the same amount, so they're off when they come back. i think it might be how i set up the motors to run.
can anyone help me fix this? i'm including a copy of my code
JamesBrown
08-11-2007, 16:42
I may be able to help, however I think we need to know a little more about your bot, for example does one motor turn all of the pods or do they turn seperately, also how much different is the amount that the encoders report and how much different is the amount that the actual pods turn.
I tried to look at your code but the file formats are .bds and .ecp which I don't recognize at all, I assume you are using easy C but is there any way you can give us .c or just txt files?
youngWilliam14
08-11-2007, 22:33
umm, i'm not sure. the pods turn on separate motors, but all the encoders are mounted exactly the same
charrisTTI
09-11-2007, 10:50
your program assumes that all the motors go exactly the same speed and stop/start immediately.
you need to take inertia of your system into account.
looks like a typo for the compare value of rot_encoder2: rot_encoder2 < 2 should probably be rot_encoder2 < 20 (in several places)
try evaluating each encoder value separately and turn the corresponding motor off when that encoder reaches the desired value.
you may also need to accelerate and decelerate the motors rather than just a hard stop and start to reduce overshoot.
youngWilliam14
09-11-2007, 13:32
thanks, i just copy/paseted that part of the code ^.^;
how do i get the motors to accelerate/decellerate? i don't have to put in a bunch of blocks stepping up to the speed i want, do i?
youngWilliam14
09-11-2007, 14:04
ok now i have another problem:
while (swerve == 0)
{
Tank4 (0 , 2 , 2 , 3 , 4 , 1 , 2 , 1 , 0 , 1 , 0);
swerve = GetRxInput (1 , 5);
}
the variable 'swerve' is set to 0 when i press the lower ch. 5 button. i'm still holding the button down when i get to this part of the code, but it skips the while loop and goes right to trying to turn the wheels back to zero. does anyone know why the loop gets skipped, even though the value of 'swerve' is still 0? the only reason why the program gets to that point is because it's allredy checked to see if the button is being pressed
JamesBrown
09-11-2007, 14:15
ok now i have another problem:
while (swerve == 0)
{
Tank4 (0 , 2 , 2 , 3 , 4 , 1 , 2 , 1 , 0 , 1 , 0);
swerve = GetRxInput (1 , 5);
}
the variable 'swerve' is set to 0 when i press the lower ch. 5 button. i'm still holding the button down when i get to this part of the code, but it skips the while loop and goes right to trying to turn the wheels back to zero. does anyone know why the loop gets skipped, even though the value of 'swerve' is still 0? the only reason why the program gets to that point is because it's allredy checked to see if the button is being pressed
Can you post the code that comes right before this loop? the syntax of the loop looks fine so if it is actually missing the loop the problem is probably occurring before it reaches it. To test this put a printf right before the loop, one right in the loop and one after the loop this will let you know whether the problem is the code not stepping into the loop or if the problem occurs somewhere else.
I still can't read the rest of your code since I don't have EasyC on my laptop but it sounds like you are just driving the motors until you get to a certain number of pulses from the encoder then stopping them. If this is the case you may be able to get (read as will get) better results if you use PID control (or any of many other control algorithms) there is a code paper on here that outlines how to do it, I'll find it and edit this post with a link as soon as I can.
James
http://www.chiefdelphi.com/media/papers/1823 - That is a good reference to get you started on PID control if you have never used it before.
youngWilliam14
09-11-2007, 14:23
ok, i put in print statements before, in, and after the loop. before the loop, 'swerve' is zero. the first time though the loop, it's still zero, but the second time through it says 127!?!? so it quits the loop.
***EDIT***
i forgot to say that the print statement in the loop is AFTER it checks for the button
JamesBrown
10-11-2007, 14:53
ok, i put in print statements before, in, and after the loop. before the loop, 'swerve' is zero. the first time though the loop, it's still zero, but the second time through it says 127!?!? so it quits the loop.
***EDIT***
i forgot to say that the print statement in the loop is AFTER it checks for the button
Assuming swerve is defined as a char then that makes sense, it should equal 127 if the button is pushed.
youngWilliam14
10-11-2007, 19:53
Assuming swerve is defined as a char then that makes sense, it should equal 127 if the button is pushed.
ok, i'll try that. it's defined as an integer right now
youngWilliam14
11-11-2007, 16:16
defining it as character made the program not record the value, but i fixed the loop thing
i still need a way to get evrything to turn the same amount though
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.