Romi additional motor & encoder on GPIO?

Hi,
I am working on sample projects for FRC training with the Romi. Vision-related tasks seem a sweet spot because you really just need a drivetrain and camera for much of that. However, I think controlling a subsystem properly would be another great training area. There is a note on the FRC page for Romi that only the two drivetrain motor encoders are supported. Is there any way to use the GPIO pins or another element of the control board to add another motor/encoder combination? This would allow PID control of a small elevator or something like that.

Thanks,
Matt

Hello, Matt.

You could probably add support for another encoder (see the “Adding electronics” section of the Romi 32U4 Control Board user’s guide for more details); however, to drive an extra motor you would need additional hardware (i.e. another motor driver or motor controller). If you’re already using a Raspberry Pi and I2C interface to communicate with the Romi, one of the Motoron Controllers that use an I2C interface might be a good option, since they can be added to the I2C bus without requiring additional pins, and you can send the commands directly from the Raspberry Pi to the Motoron.

Brandon

Thanks Brandon,
That all makes sense. I haven’t looked at I2C before, though I understand the 32U4 & Pi are connected on those pins so it could be in use a layer below where I’m coding.

I think I’d like to match, as closely as possible, the existing drive motor/encoder setup. I’ll outline what I think is a next step to try if you don’t mind taking a look and calling out any obvious issues. The GPIO pins referenced are EXT0-4 which are configurable in the FRC web interface. My biggest question is below, regarding the transformation of encoder output on the standard encoder setup for romi drive motors.

  1. Motor Driver
    From the Romi User Manual I think this would match the built-in motor drivers
    Pololu - DRV8838 Single Brushed DC Motor Driver Carrier
    Then I think the pins would need connecting as:
    VIN: Battery power 7.5v (input on which 32U4 pin best)
    VCC: 5v power from 32U4 (input on which 32U4 pin is best?)
    VM: Unused (can switch for VIN if low voltage / lose reverse protection)
    GND: Ground on 32U4 (input on which is best?)
    OUT1 / OUT2: Connect to DC motor
    PHASE: not connected
    ENABLE: PWM input from GPIO pin on 32U4 configured in FRC web interface
    SLEEP: Not connected

  2. Motor/Encoder
    Romi ships with this unit so would try to use same:
    Pololu - Gearmotor and Encoder Assembly for Romi/TI-RSLK MAX
    So I think the pin connections would be:
    M1 / M1: Connected to OUT1/OUT2 on driver above
    VCC: 5v power from 32U4
    A: Encoder output to GPIO configured for DIO
    B: Encoder output to GPIO configured for DIO
    GND: 32U4 GND

With the above setup, there’s still a gap to what I see in the Romi User Manual (Page 10) regarding the DRV8838 quadrature encoders. It would seem I need to accomplish the same XOR before connecting to one of the GPIO? And would that pin need to have an interrupt? I see that EXT0 is marked with interrupt PCINT7 so would that be the one to use?

Thank you for taking a look,
Matt

I am not very familiar with the details of the WPILib software, but I think this kind of modification is probably more involved than you are expecting. Just to be clear, you will need to modify the program on the Romi 32U4 Control Board (which the WPILib refers to as the firmware) so that it handles the lower level features of controlling the phase and enable signals for the motor driver, as well as reading and keeping track of the encoder counts, and relaying that information to the Raspberry Pi, which is all done through the I2C interface. I am not sure how practical it is to have the WPILib software send custom commands via I2C, so that might be something you will need to contact the WPILib team about.

For the motor driver:

  1. You can use the VSW pin on the Romi 32U4 Control Board to supply power to the driver, since that is the same source for the onboard motor drivers.

  2. Any of the 5V and GND pins on the Romi 32U4 Control Board will work for VCC and GND on the driver, respectively.

  3. If you want to be able to drive the motor output in both directions, you will need a digital signal for the PHASE input.

  4. It looks like the WPILib documentation uses the term “PWM” to refer to hobby RC servo signals (which will not work for the enable signal). To clarify, of the 5 configurable pins they mention, only one of them (EXT0 / pin 11) is actually capable of analogWrite() (which uses the correct kind of duty cycle-based PWM signal); however, it does not sound like their software supports that functionality (pin 11 pin would probably be better to use for reading the encoders anyway, as discussed below). So, in short, this is one of the things you will need to handle at a lower level by modifying the Romi 32U4 Control Board program.

For the encoders:

An XOR gate is not necessary (we use one to reduce the number of pins required). In general, we recommend using a pin that supports interrupts for at least 1 of the encoder signals. The pin you mentioned, PCINT7 (i.e. pin 11), would work. Similar to point #4 above, you will need to modify the program on the Romi 32U4 Control Board achieve this, which involves configuring the interrupt and having the control board handle keeping track of the encoder counts and passing that information to the Raspberry Pi when requested.

Brandon

Wow, yeah I have no intention of modifying the program on the 32U4 board! I didn’t realize the PWM signal was different for the motor driver or that the interrupt had to be programmed.

If I go the I2C route, I guess I wanted to ask how to physically put more devices on that bus? My understanding is that the pi connections are the GPIO 2&3 pins that plug into the Romi.

Also, do you sell an I2C controlled encoder that could be paired with a motor powered by the I2C controller you recommended?

Thanks
Matt

If you do not want to reprogram the Romi 32U4 Control Board, you will need some other way of processing the encoder signals as well since Raspberry Pi computers are unfortunately not very good at time sensitive tasks like that.

The Motoron Motor Controllers that I mentioned before do not have any special support for reading encoders.

If you want to do closed-loop speed control (i.e. not position control) using the encoders, you could consider one of our Jrk G2 Motor Controllers. The Jrk G2 controllers can do closed-loop position control if you have some kind of analog voltage feedback (such as a potentiometer).

Otherwise, if you are trying to do closed-loop position control using feedback from quadrature encoders, you could consider the RoboClaw controllers. However, please note that the RoboClaw controllers do not offer an I2C interface; they can use USB or TTL serial though.

As far as connecting additional I2C devices, you can use pins 2 and 3 for SDA and SCL respectively (as well as a common ground connection). You can find more information in the “Adding electronics” section of the Romi 32U4 Control Board user’s guide, under the “I2C devices” heading.

Brandon

OK, I guess I might not have any choice but to modify the firmware as you suggested. The goal is to expose encoder DIO channels to the wpilib encoder class constructer, which I don’t see as possible with the other options.

I’m pretty sure that the firmware used is included in the WPILibPi package because the 32U4 is flashed from that code’s web interface. So I’m not sure what modifications are already done and would have to work with that. I’ll try to find that out from the WPILibPi side first.

Thanks for discussing this with me, I have much to learn here.

Matt