Running out of DIO for Encoders

Hey everyone I got a brief combination electrical and software question. Our team is using the dual channel encoders for driving, shooting etc. My question is for the shooter(which we only really care about the speed in one direction) can we just some how use a single DIO port? Like we just plug in channel A and get the rate of that. If this is doable is there any way to easily do this in code? Like the initialization of the encoder and calling getRate().
Elijah
4601

P.S. We are using C++ but any example would be nice.

Have you considered something like the REV more board? It plugs into the mxp port of the roborio and breaks out all of the additional DIO’s available on the mxp.

There are another 16 dio ports on the Mxp expansion ports they are not labeled, but if you look at this diagram, you can see that there are plenty to use.

1 Like

I think the underlying FPGA module for encoders intends for two channels to be used ((http://users.wpi.edu/~bamiller/WPIRoboticsLibrary/d3/d1d/class_encoder.html)). One good option is to use TalonSRXs and get the encoder values through CAN bus. Better yet, run the PID code for your shooter on the talon itself for better performance.

It’s not actually a serious concern now, we had a old I2C magnetometer in the pins but we dug out a breakout magnetometer. The thing is now I am just curious, what if we need some more pins for some thing else? Also if we were to buy the REV board it would be a waste since we only need the speed in one direction, especially if we just need something quick and cheap.

You can use a single channel of an encoder. Just make sure to set your decoding properly.
Normally, the RoboRIO uses what is called “4x” decoding- it counts the rise and fall of both the A and B channels. However, in something like a shooter where you already know direction and only want speed, you can use just the A channel to find speed as kind of a “2x” decoding. I’m not sure if the software will support that though.

Wow I never knew that. Could you just wire up some encoders to those pins and call them the same way?

This would be great if that is possible

Yep. Correct me if I’m wrong, but I believe you can just plug them directly into the mxp pins. We have only used them for switches (we are using them for our auto selector box that uses 3-position switches) I don’t see why they wouldn’t work for encoders

I think 2x and 1x decoding of encoders on the RoboRio still requires two input pins, even if you don’t want the direction decoding. That’s at least what the constructor says in the documentation. There might be some weird Hal method to only use one pin.

You would need to use a Counter object instead of an Encoder object.

Agreed. We have done this in the past with a gear tooth sensor using the Counter class, when we knew that the wheel would never turn in the opposite direction.

If your using the TALON SRX motor controllers you can simply wire the encoders directly to them. Keeps all the wiring a lot simpler. You would THEN use a CAN bus to commutate position data with the various TALONS.

I hope you mean CAN and not I2C, cause there aren’t any legal I2C motor controllers.

If you meant doing master/slave with the Talon SRX over CAN, you shouldn’t have any problems with the speed of the CAN bus for this. Wire an encoder into one Talon, do the PID there, then you set the other Talon in follower mode and point it at the PIDing Talon. I don’t know the exact update rate of the follower, but it’s plenty fast enough for anything you’d be doing in FRC.

You can use the Counter class in place of the Encoder class for single-channel (i.e. not quadrature) mode.

Alternatively, as others have already said, a breakout board for your MXP port on the RoboRio. If you’re cheap, you can make your own breakout by using a floppy disk drive IDE cable and wiring it all up manually.