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.

We’re still looking for a description of the symptoms.

actually, our encoder does work, it’s just a matter of finding if the code works or not. if not, then there is an encoder problem. however, I checked the wiring. I heard there’s a way to see every time it clicks on the laptop. how’s this done? also, yes, I’ve gone over the read me.

Here’s what I would do to verify that your encoder is working: In the routine where you are controlling the arm, add the following code:


int tempEncoder;
static int prevEncoder = 0;
...
tempEncoder = Get_Left_Encoder_Count();
if (tempEncoder != prevEncoder) {
   printf("%d ", tempEncoder);
   prevEncoder = tempEncoder;
}

which screen will it print to when running the program? I know in the link cable program thing to download the (ifi loader) program, there’s a little screen.
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.

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?

Yes. that’s where you’ll see the output.

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!

That’s why my code only prints the encoder value when it changes. It will still move pretty fast when the encoder is turned, but it will stop when the encoder stops. Also in order to keep as much of the data on screen as possible, I intentionally didn’t print a newline.

also, I don’t know if it matters, but what are the three “…” periods for after the previous static encoder.

Those were just intended to show that there were lines omitted.

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?

Sorry. I guess I could have been a little more specific. The first two lines need to go at the beginning of the function. In C (unlike in C++), data definitions must appear before any executable statements in a function.

Leave out the ellipsis (the “…”), and then put the rest of the code just before the arm control code.

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!

Congratulations! Does that mean the arm is working too?

Earlier, you said

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 you mean the compressor is on relay 17? And did you really mean analog 1 for the pressure switch? If so, is it the pressure transducer (an analog pressure sensor) or the (digital) pressure switch?

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:


  relay8_fwd = !rc_dig_in18;  /* Power pump only if pressure switch is off. */
  relay8_rev = 0;

If you really are using the pressure transducer, and you want to leave the compressor on PWM 17, you will need to add some code that I’m not prepared to help you with right now, since we haven’t used any analog inputs on the robot since we have gotten the new controllers.

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


  relay17_fwd = !rc_dig_in18;  /* Power pump only if pressure switch is off. */
  relay8_rev = 0;

(Change rc_dig_in18, if necessary, to whatever digital input you connect your pressure switch to.)

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…

Encoder signals go to digital inputs on the RC, not to pwms. Quadrature encoders require power and ground, and they provide two digital signals.

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.

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???

See Kevin's FRC Code Repository for lots of example programs, many of which are complete drop-in modules. Scroll down to frc_encoder.zip for interrupt-based encoder code.

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!!!

It’s just template code that shows you how to setup the interrupts. Check out some of the other examples that show you what you can do with interrupts.

-Kevin

where can I find the other examples for interrupts?

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.

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

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

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.

(didn’t mean to sound mad :wink: ) came out that way I guess