![]() |
encoders
I'm posting this in hope that someone who has actually registered on this site will post something. there are so many people viewing this, but not posting anything. with that said, I thought this would be a nice place for people to discuss encoders. of course, my main motivation is that these things have been my killing me over the past month. I have tried numerous things, and I can never seem to get it to work. Coding, for the most part, I don't think is a problem. I'm using 2004's code written by Mr. Watson that supports encoders and interrupts. I have everything configured, the only thing that could possible be keeping the encoder from working is my code in User_Routines_Fast.c
what the code does is this, when the third joystick is pushed forward, the arm on last year's robot goes up untill the encoder has "clicked" 12 times. then the motor on the arm is set to neutral. it's as simple as that. (for testing purposes). Code:
static long lec = 0; //lec = encoder countHELP!!! thanks, Stephen :yikes: |
Re: encoders
What does the robot do when you move the joystick? Have you tried turning the encoder by hand and printing the value of lec to make sure its being incremented correctly?
Since the call to Get_Left_Encoder_Count() does not reset the internal value, your local variable (lec) will saturate very quickly. Once the encoder moves one tick it will increment lec over 12 almost instantly. You either need to reset the value to 0 or use Get_Left_Encoder_Count() on its own as your counter. Code:
if (Get_Left_Encoder_Count() >= 12) |
Re: encoders
Quote:
do you mean set the "Get_Left_Encoder_Count()" function variable to 0? so your saying that Get_Left_Encoder_Count()" function variable holds its value every time it interrupts, even if I call it once and then call it again. that is definitely what Mr. Watson seems to have stated in his code. that makes sense, though I don't see how it holds the total value every time it interrupts without being declared as static. |
Re: encoders
Quote:
|
Re: encoders
Since the encoder may have ticked before you hit this block of code, you may want to do something like this.
Code:
//define a variable outside the loop called 'temp1' |
Re: encoders
how do I turn on the compressor in the 2004 default code? thanks. (though I'll be using it in Mr. Watson's 2004 encoder code).
|
Re: encoders
Hook up your compressor to a spike, so that the red lead is attached to the M+ output and so that the black lead is connected to your ground junction. In your code, turn that relay on and off.
So, if you used relay1, the code would look something like this.. Code:
void TurnOnComp(void) |
Re: encoders
um, where do I put those functions at? (which file)
|
Re: encoders
ok, our compressor is hooked up to digital 17. from last year's white sheet with the different wires labeled, it says that the sensor for the relay is hooked up to analog 1. I'm new to the compressor stuff. Is this all of what you need to write the code for it? It is hooked up to a spike. unless this is hard, could you show me the code for this, and tell me where to put it. That would allow me to learn from it as I get confused easily when I have to write things on my own without experience. as soon as you can is best, as I'm at a robotics meeting right now.
thank you for your help, Stephen |
Re: encoders
Stephen,
Regarding your first code posting Code:
static long lec = 0; //lec = encoder countIf you already figured this out or I missed this in the above response...just ignore what I said. :-) Regards, ChuckB |
Re: encoders
Quote:
|
Re: encoders
On the compressor, I would do something like this:
"if (p1_wheel => 127) { relay1_fwd = 1 ) else { relay1_fwd = 0 ) " The setup should be as follows: You should have a joystick connected to port 1. You should have a spike sonnected to relay port 1. When you rotate the throttle (the big wheel) on the joystick away from you all the way the compressor will turn on, otherwise, the compressor will not turn on. |
Re: encoders
Quote:
We're still looking for a description of the symptoms. (I asked too in the "What do you think about how easy theyre making programming?" thread.) All you've told us so far is that "the encoder doesn't work." Have you tried what Sean suggested?: Quote:
|
Re: encoders
thanks guys. actually, I found out in this thread that the Get_Left_Encoder_Count() function sends its returned value to the "Left_Encoder_Count" variable, which IS static. therefore I don't need the (poorly named) "lec" (left encoder count, but left count is being used for the arm this time, with the tick delta set to +1).
however, all I need for the compressor is to turn it on, but thanks for the wheel idea, as I'll try that out. It'll make testing more practical. thanks again! |
Re: encoders
Quote:
Code:
relay8_fwd = !rc_dig_in18; /* Power pump only if pressure switch is off. */ |
Re: encoders
is that already in the default routine, because our compressor doesn't automatically turn itself on. plus, if you read my above post, are you sure the default settings work with the way my bot is configured? thank you.
|
Re: encoders
I have some vague recollection that you may not pass inspection if you do not have the pressure limit switch controlling the compressor.
Last year we were overweight and removed our compressor, opting instead to charge the air tanks before each match. |
Re: encoders
Sorry if this is a bit off topic.
I was looking through the encoder the Mr.Kevin provides on his website. I did not find the model of the encoder he was using, i am currently wanting to use optical encoder from digikey there a lot of them available. I am trying to decide which one to buy and will the optical encoder just tick when the dark area changed to light? Thank you in advance |
Re: encoders
Quote:
-Tony K |
Re: encoders
Quote:
and 61K128 quadrature output optical encoders. Data sheets for these devices are included." -Kevin |
Re: encoders
As Anthony points out. If you have power to burn, leave the compressor in full auto, if, on the other hand, you want manual control (for any one of a number of reasons) I think that the wheel is a good choice, as it is convienient, and hard to press by accident.
|
Re: encoders
Quote:
|
Re: encoders
Quote:
Code:
int tempEncoder; |
Re: encoders
Quote:
is it in that? that would be hard to trace, because it prints out hundreds of lines, and there isn't a way to print or save it to a file for viewing. guess I can search it. thanks! also, I don't know if it matters, but what are the three "..." periods for after the previous static encoder. |
Re: encoders
also, it says there's an error on this line when I put it in user routines fast.
int tempEncoder; what's up with that? |
Re: encoders
Quote:
Quote:
Quote:
Quote:
Leave out the ellipsis (the "..."), and then put the rest of the code just before the arm control code. |
Re: encoders
the encoder is working!!! thanks for the help in this thread. I'm still looking at our compressor, though it's not a pain to enable, just that they have it wired oddly. thanks again!
|
Re: encoders
Quote:
Earlier, you said Quote:
The default code expects the compressor to be on relay 8, and the pressure switch on digital 18. If you hook up your compressor and pressure switch this way, you're golden. These lines in Default_Routine() in user_routines.c will take care of the compressor: Code:
relay8_fwd = !rc_dig_in18; /* Power pump only if pressure switch is off. */BTW, I think that last year, the ruling was made that even if you want to use the pressure transducer, you still have to have the digital pressure switch. If this is the case (and you still want to leave your compressor on relay 17), you will need to change the line in Default_Routine() to Code:
relay17_fwd = !rc_dig_in18; /* Power pump only if pressure switch is off. */ |
Re: encoders
On getting the Phase A/ Phase B hookup on the encoder. Do i need to splice the wires. Do i have just one pwm for each encoder or two? Please Help....
|
Re: encoders
Quote:
If you're using interrupts, you're pretty much required to use the first two digital inputs for the "A" phase outputs of two encoders, with the "B" phase outputs on two other digital inputs. |
Re: encoders
Im working on my programming, when it comes to my code I do not know how to set up my interrupt handlers, is there demo code some where for this???
|
Re: encoders
Quote:
|
Re: encoders
Sample code from Kevin on www.kevin.org/frc, the interrupts program, in file interrupts.c, there is a spot that says:
/************************************************** ***************************** * * FUNCTION: Int_3_Handler() * * PURPOSE: If enabled, the interrupt 3 handler is called when the * interrupt 3/digital input 3 pin changes logic level. * * CALLED FROM: user_routines_fast.c/InterruptHandlerLow() * * PARAMETERS: RB4_State is the current logic level of the * interrupt 3 pin. * * RETURNS: Nothing * * COMMENTS: The PIC18F8520's RB4/KBI0 pin on port b is mapped to * interrupt 3 on the EDU-RC and digital input 3 on the * FRC-RC [108]. * ************************************************** *****************************/ void Int_3_Handler(unsigned char RB4_State) { // this function will be called when an interrupt 3 occurs } Is this the final code??? What do I need to add??? HELP!!!!!!!!!!!!!!!! |
Re: encoders
Quote:
-Kevin |
Re: encoders
where can I find the other examples for interrupts?
|
Re: encoders
How do I hook up th encoders to the RC. I know that they go on Digital I/O, but do I use two PWM CABLES to hook each encoder up or what do I do? Someone please help me.
|
Re: encoders
ok, I'm assuming you have a quadrature encoder (this means there are 4 places to hook up wires on the encoder). 1 is the + power pin. 1 is the - (ground) pin. one is the phase -a pin, and one is the phase b pin. this requires two digital ports on the rc. I'm assuming you are using Kevin watson's encoder template (the only way to do this if your a beginner). hook up the +, -, and phase a wires on the digital io 1. then put the phase b wire on digital io (I think, but check the template read me provided b Mr. Watson) on digital io 6. this is how the "left" motor encoder, or w/e our using it for is hooked up.
don't feel too bad, I had this same problem about a month ago, I started a couple threads before I was able to understand it. hope this helps, Stephen |
Re: encoders
Let me see if I have this right I have to hook one encoder to two different Digital I/O ports?...I'm so confused
|
Re: encoders
ok here it is, and yes, one encoder to two digital IO's. did you read what I said carefully? um, check to see if there are four pins on the encoder, if there are, then you need two digital ios. here-
dig. io 1 ------- phase a pin ------- positive power --------negative power dig. io 6 ------- phase b pin (only, no power or anything here) if this doesn't make sense, then you really need to go to the white papers section and read up on interrupts a little and on encoders, and read through the comments on mr. Watson's code. questions are fine, but really, after reading this, you shouldn't be having any problems. |
Re: encoders
(didn't mean to sound mad ;) ) came out that way I guess
|
Re: encoders
Is it possible to change these pins if you adjust the code???
|
Re: encoders
Quote:
-Kevin |
Re: encoders
Quote:
What do you mean " phase-A signals must be tied to an interrupt", can i hook them up to digital i/o pins 3-6??? |
Re: encoders
Quote:
|
Re: encoders
I would suggest, especially Mr. Watson has it set up this way, putting the phase a's on 1-6, and b's on any other pins. Unless you can't already figure the direction your going, it won't be important to inerrupt the phase b's.
|
Re: encoders
I've got a few encoder questions. I'm trying to decide whether or not to spend $100 of my team's money on Greyhill optical quadrature encoders, when the kit already includes HAL-effect sensors. Things are beginning to look bleak in terms of the amount of time we have until ship-date, and it'll be hard enough finding someone in the construction section of the team to mount any sensor as it is.
First, I understand that quadrature encoders can detect direction, and that in addition optical encoders are more reliable, but would this high-end technology really be useful for a team that just needs to reliably determine how far the bot has traveled (or turned)? Second, will Kevin's code work with non-quadrature encoders? I assume it wouldn't - in that case, is it difficult to write my own code to interface with them, or is it as simple as reading an input? Third, is it possible to use encoders without interrupts, and just poll how many clicks have elapsed, or would polling only return whether or not it is currently clicked? Thanks. |
Re: encoders
well, it shouldn't be too much a pain to change his code to use the regular encoders. polling would only tell whether it's currenlty clicked or not. I've tried doing that and I always got messed up measurements, because it's random when it records a tick. therefore, no matter the speed of the shaft, I would suggest using interrupts always.
|
Re: encoders
if anyone has time, I would greatly appreciate it if you could upload the new compiler that Microchip temporarily released for free for me. I had it, but it's walked off to magical places. just let me know where you uploaded it to. or try Emailing it to me. idk what the max. file size limit is for my Email. or if Microchip hasn't taken the ftp link away yet, tell me the link, cause I couldn't find it. thank you a bunch.
|
Re: encoders
Quote:
You can handle encoders without interrupts, as long as they tick slowly. If you can guarantee that you poll the pin at twice the rate it transitions, you would be able to poll it reliably. |
Re: encoders
Quote:
|
Re: encoders
Based on what I see, interupts would be more reliable. However, assuming that the reliability of each method are equal, what are the pros and cons of polling and interupts, besides code complexity?
|
Re: encoders
Quote:
interrupts=every advantage you could imagine, except tough coding. this is why Mr. Watson wrote code to handle encoders with interrupts, it's truly a wonderful thing he has made. go to www.kevin.org and scroll down to the robotics link, and look for frc encoders template. It's what I used to learn about encoders and interrupts, and it is so easy to use because all the work is already done pretty much. though I wish he would consider setting up a third encoder interrupt as well, but what he has is awesome. |
Re: encoders
Quote:
|
Re: encoders
if the pin state hasn't changed, how does it know to not make another tick count? is there a flag, kind of like interrupts that must be cleared before you can register another tick? if so, that's pretty neat.
|
Re: encoders
can somebody please send me a copy of the new compiler? ( stephen51@safe-t.net ) thanks in advance.
|
Re: encoders
Quote:
Code:
// assumptions:-Kevin |
Re: encoders
Quote:
That would be illegal (copyright laws and all of that...). As they had announced at the kickoff, the V2.4 download was available for 2 weeks only and you had to link to it via the FIRST site. Now they have shut it down, as promised. Please have your main team contact phone FIRST and they will send you a CD. Mike |
Re: encoders
It suddenly occurred to me that the encoders can be reused for next year's competition, so I told my adviser to go ahead with the order. I guess I'll take another look through the readme for the encoder module and prepare to implement some autonomous driving functionality.
|
Re: encoders
I think I found our copy. and I would have to say that I disagree about it being illegal. if I purchased (or in this case got it free) a cd, and simply broke it somehow, I wouldn't be cheating the business by getting a copy from someone else, because I already paid for thir product. anyway, is the newest compiler on the disk that came with the kit this year? just to be sure. thanks
|
Re: encoders
Quote:
|
Re: encoders
Quote:
To echo what Mark just posted, the CD you got in the kit is V2.2 V2.4 has not been released yet. You can not buy it or download it. Microchip has graciously offered to let FIRST team members use a beta version. I would imagine that, if their trust in us is broken and they find these beta versions being used for anything other than FIRST robots, they would think twice about future donations. What this means is that future teams would have to spend $495.00 per seat of software to participate in FIRST. Bottom line, please do not treat this topic lightly. Our actions always have consequences. Please have your main team contact phone FIRST to get a CD. Regards, Mike |
Re: encoders
[I would imagine that, if their trust in us is broken and they find these beta versions being used for anything other than FIRST robots, they would think twice about future donations.]
Folks, everything is okay. Wow, this thread got way off topic. :) Having worked very closely with Stephen over the last month, I have gotten to know him very well. His inquiry over the C compiler is quite innocent and justly asked. If someone believes it to be a malicous act to inquire about a tool that is supplied by a vendor in an agreement with FIRST, then please direct your admonition to the team's teacher/leader. The students are here to learn the science of robotics. They do not need to feel someone's fire for something they do not have experience handling. This forum is to provide technical knowledge and stimulate interest for the students. I believe we still are under the gracious professionalism invoked by the FIRST rules of the game articulated at the kickoff. I will give Stephen a copy of the C 18 2.4 compiler. His compiler got destroyed by an erratic computer believing it was an all consuming shark, not as a friendly programming tool. I have kept a copy of the download on another unit believing that something like this would happen. [Bottom line, please do not treat this topic lightly. Our actions always have consequences.] Mike I do appreciate your input, but please do not judge Stephen too harshly. He is a hardworking student with a tenacious talent. When he left our lab last night, I did not get a chance to supply him with a fresh copy of the compiler. He will, though, receive it within the next couple of days. If anyone feels the need to continue discussing the ramifications of violating a vendor or FIRST rule, please start a new thread. I really like the discussion about encoders on this one. :-) Respectfully, Gary Dettmers 1008 Engineering/Programming Mentor |
| All times are GMT -5. The time now is 22:22. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi