|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 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;
}
HELP!!! thanks, Stephen ![]() Last edited by stephenthe1 : 12-01-2005 at 15:09. |
|
#2
|
|||
|
|||
|
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)
{
pwm02 = 127;
}
{
pwm02 = p3_y;
}
Last edited by seanwitte : 12-01-2005 at 15:38. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
Re: encoders
Quote:
|
|
#5
|
|||
|
|||
|
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'
if(temp1==0)
{
temp1=Get_Left_Encoder_Count();
}
static long lec = Get_Left_Encoder_Count() - temp1;
if (lec >= 12)
{
pwm02 = 127; //set it to neutral
}
else
{
pwm02 = p3_y;
}
Last edited by Tom Bottiglieri : 12-01-2005 at 15:41. |
|
#6
|
|||
|
|||
|
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).
|
|
#7
|
|||
|
|||
|
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)
{
relay1_fwd=1;
}
void TurnOffComp(void)
{
relay1_fwd=0;
}
|
|
#8
|
|||
|
|||
|
Re: encoders
um, where do I put those functions at? (which file)
|
|
#9
|
|||
|
|||
|
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 Last edited by stephenthe1 : 12-01-2005 at 16:48. |
|
#10
|
||||
|
||||
|
Re: encoders
Stephen,
Regarding your first code posting Code:
static long lec = 0; //lec = encoder count If you already figured this out or I missed this in the above response...just ignore what I said. :-) Regards, ChuckB |
|
#11
|
|||||
|
|||||
|
Re: encoders
Quote:
|
|
#12
|
||||
|
||||
|
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. |
|
#13
|
|||||
|
|||||
|
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:
|
|
#14
|
|||
|
|||
|
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! |
|
#15
|
|||
|
|||
|
Re: encoders
Quote:
Code:
relay8_fwd = !rc_dig_in18; /* Power pump only if pressure switch is off. */ relay8_rev = 0; |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Mechanical Wheel Encoders? | Jaine Perotti | Electrical | 15 | 04-12-2004 22:46 |
| Shaft Encoders | wun | Programming | 3 | 12-10-2004 16:40 |
| encoders? what kind and where from? | ajlapp | Electrical | 1 | 03-02-2004 01:49 |
| Who used wheel encoders | CyberWolf_22 | Technical Discussion | 12 | 04-05-2003 15:37 |