![]() |
encoder vs. motor
I have a robot with a mechanical encoder attatched to an arm with a motor to lift the arm.
the encoder is at 50 resolution the arm motor is attatched to pwm_02 the encoder is attatched to rc_dig_in06 I calculated that the encoder will "click" or turn on and off 10.7 times for the distance I need.(the encoder is 50 resolution). basically I need the source so the motor attatched to pwm_02 will stop once the encoder "ticks" 10.7 (or eleven) times. Please keep it simple. I don't have time to go through a tutorial right now. thank you so much for the help. oh yeah, it would be nice If I could have the arm lift at the touch of a trigger on a joystick attatched to p1_sw_trig. and have the arm go back down at the touch of the trigger again. does the operator interface controller provide a way to simply shut everything down immediately in the event of a disaster? please help. thanks, Stephen |
Re: encoder vs. motor
Stephen,
I think it would be best for you to attempt to write this code yourself. It is very simple (count to 11)... If you post your code, I'm sure that one of us will critique it for you before you load it into a robot. Regards, Mike |
Re: encoder vs. motor
can you look at this and tell me if you see any errors.
Code:
//the encoder is at 50 resolution |
Re: encoder vs. motor
Quote:
"encoder" needs to be static or a global, so it retains it's value from call to call. The check on rc_dig_in06 will increment "encoder" more often than every "tick" "encoder" might shoot right past 11 and keep going. But first what model encoder are you using? |
Re: encoder vs. motor
Quote:
|
Re: encoder vs. motor
Quote:
A good start. First of all, you have not initialized your counter (maybe this is done in your actual code... I don't know). Second, what happens the next time through the loop? I'm assuming that you will want to perform this maneuver again and again (once again, I may be mistaken). For now, I will assume that this is a one shot deal... Here is what I think will happen: When the encoder hits 11, the arm is turned off but the encoder micro-switch is still "closed". The count will increase to 12 and the arm will continue to travel. You might want the last test to be "encoder > 11"... Does this make sense to you? |
how about this code.
we tried to keep the motor speed down so the encoder will read each tick before the program refreshes. so the motor doesn't "beat" the program before it reads the encoder.
Code:
//the encoder is at 50 resolution |
Re: how about this code.
Could work.
You still need to initialize "static unsigned int encoder= 0;" as Mike mentioned. I still think you're going to count each encoder tick more than once and your arm will end up short of the expected position. ( I have to pickup my daughter and will check back later) |
Re: how about this code.
Quote:
You can see I attempted to reformat your code to make it more readable. Now you can see how your code nests... I agree with Mark. I'm not worried about you missing an encoder ping but rather that you will get multiple hits at one ping. You should consider implementing a state machine. Do you have a mentor on your team (what team are you with anyway?) who can teach you what a state machine is? |
Re: encoder vs. motor
thanks for the help and tips. I'll have to look into state machines. Today I was in a kind of hurry (which was probably obvious). but now I've got more time to think things through. Our team doesn't really have any mentors for programming. We never have, last year we had a wiz kid, and this year its kinda up to me and another guy. neither of us have much experience. I programmed with c#, but that was with Windows, which tends to behave much differently than a robot :yikes: . our team number is, I'm not sure. we're team "lugnut" though, from Ohio.
|
Re: how about this code.
Quote:
|
Re: encoder vs. motor
Quote:
Quote:
|
Re: encoder vs. motor
lol. great! yeah, this chiefdelphi site has been an awesome help.
well, the encoder is an EC202AXXX (with 50 resolution) |
Re: encoder vs. motor
so like with this code
Code:
//the encoder is at 50 resolution |
Re: encoder vs. motor
Quote:
What you have is not a mechanical encoder. It is an optical encoder made by CUI. Here is a spec sheet: EC202A050A2(S or T)D. As you can see, it comes in two flavors a horizontal or vertical mount. More importantly, it has a quadrature output so that you can determine direction in your code. Team 177 used a very similar device last year. I very, very strongly suggest that you download Kevin Watson's example code for optical encoders at http://kevin.org/frc/ and download the file edu_encoder.zip open it up and examine his code very carefully. What Kevin did is for the edubot. You will have to do the same stuff to the RC code. However, over 50% of the work has been done for you. It works like a charm. Trust me... |
| All times are GMT -5. The time now is 03:09. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi