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).
static long lec = 0; //lec = encoder count
lec = lec + Get_Left_Encoder_Count(); //add previous count
//plus the new count
//the static long is supposed to hold the value every loop
if (lec >= 12)
{
pwm02 = 127; //set it to neutral
}
else
{
pwm02 = p3_y;
}
can you please tell me why this won’t work, or if you think it should. please tell me yourself and don’t refer me to somewhere. I’ve spent so much time, and a simple few lines of code would help me to understand this almost completely. (don’t forget, Mr. Watson’s 2004 encoder code is what I’m using.)
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.
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.
Get_Left_Encoder_Count() is a function that interacts with a static variable in encoder.c named Left_Encoder_Count. Since Left_Encoder_Count is not exposed by encoder.h you can only get the value using the supplied function, Get_Left_Encoder_Count(). To change its value use the function Set_Left_Encoder_Count().
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…
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
Did someone explain that if you initialize “lec” every time this function is called, it will always be zerod? You could get rid of the ‘lec = 0’…that way it would always remember the last value (which is what you were trying to do).
If you already figured this out or I missed this in the above response…just ignore what I said.
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.
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?:
You mention you’re using Kevin’s 2004 encoder code. The version I have has a fairly complete read-me file included in the .zip file. Have you read it? If you don’t have the read-me, maybe you should get Kevin’s latest version, and use it instead of the old one.
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!
Don’t use the wheel input to control the compressor! The pressure switch output is open (0) when the pressure drops below a threshold, then closes (1)when it hits 120 psi. It stays closed (1) until the pressure drops below the threshold again. That means there is no logic involved in turning the compressor on and off, just grab the value from the switch. Its right there in Default_Routine(). The compressor is connected to relay 8 and the pressure switch to digital input 18:
relay8_fwd = !rc_dig_in18; /* Power pump only if pressure switch is off. */
relay8_rev = 0;
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.
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?
I believe it is the pressure blow off valve that cannot be removed, not the pressure sensor. In 2003, we ran without a sensor. That’s where CJO got the code from. We used the wheel since we didnt have any more buttons on the controller to map the function to. We controlled it manually since we were having power regulation problems and decided to kill the compressor completely for the last 30-45 seconds of the match.
From the readme.txt: “This software was tested with Grayhill 63R256
and 61K128 quadrature output optical encoders. Data sheets for
these devices are included.”