Custom USB Controller on HERO

My students are working on developing a set of tools for testing and implementing mechanisms without a driver station and settled on the CTRE HERO for their control board, due to the need for CAN. However, they’ve been a little ambitious, and they’re limited by the number of digital and analog inputs on the HERO.

To expand the number of inputs and outputs, they want to use a custom USB HID, like the MSP430 Launchpad. We recognize that the HERO only has support for devices which send basic HID commands, but they were hoping this would work since the Launchpad claims to be able to run as a generic USB HID.

The Launchpad has been configured following the instructions from TI and appears correctly when connected to a computer, but they’re not sure how to declare it in their code, and simply calling it as a gamepad and attaching it using

new GameController(UsbHostDevice.GetInstance());

doesn’t seem to be working.

Any suggestions? Is there a special configuration we’re missing for the Launchpad? Thank you!

So let’s start with what you have. Do you have basic game pad stuff working on the HERO? If not then start there.

What does the Launchpad enumerate as? What kind of HID? Keyboard? Mouse? Something else? What does a computer think it is?

The HERO is running C# so all the stuff you need to deal with HIDs and USB will come from the documentation for C#.

I haven’t been down this road but if the launchpad is enumerating as a keyboard or mouse then you need to talk to it like it’s a keyboard or mouse and not a game pad. If it’s enumating as a game pad then talk to it like it’s a game pad.

Post more code as a gist and maybe myself or some others can help more.

Thanks! Yes, basic gamepad stuff is working on the HERO, both using their example code and writing our own.

On a Windows computer, it recognizes as a standard gamepad. It looks and behaves just like any generic joystick or gamepad.

Hmm, I’ll have to look into how C# handles this. I wasn’t sure if the HERO did its own thing or if C# had a general approach. Here’s how it’s being created and attached:

GameController _gamepad = new GameController(UsbHostDevice.GetInstance());

I can absolutely provide more code if needed, but that alone has been enough so far. From there, I use a simple

if (_gamepad.GetConnectionStatus() == UsbDeviceConnection.Connected)

with a debug statement to see if it’s being recognized, and no luck so far.

The example in the Hero manual is using the “D” mode of the logitech. Refenced, but not well documented is other controller classes for the microsoft controllers and the X mode of the Logitech. The X mode is the more current style. Maybe the gemapad is emulating the X mode?

Maybe something herewould be useful?

Thanks for the suggestion. I went ahead and played with X vs D mode, and have gotten both working with a standard Logitech gamepad on the HERO. Still no luck with either for the Launchpad. As for the UsbHostDevice class, I wonder if there’s a way to specify the VID or PID for the device. I don’t see anything, but if anyone has any more experience with it, maybe they have some input?

You may need to confirm this, but you may have a similar misunderstanding I had with the Hero documentation with PWM outputs and the Hero. We implemented the Hero on two practice bots over the summer, and we had leftover pwm controllers that I wanted to use for the project. Our plan was to use 4 cims in the drive base, but looking at the Hero manual and chart on the bottom of page 10, it appears P port definition only supports 3 PWM outputs, and the Hero only has one port that is P compatible, port3.

After talking with CTRE tech support, (which was great) I was told that the graphic on page 10 is really the “Gadgeteer” standard, but CTRE had implemented the functionality of the PWM on the “[UN]” pins of port3. So in actuality the Hero can drive 5 PWM motor controllers, but looking at the chart, you may only think it can drive 3. What I was told the [UN] were undefined in the standard, but could be used/activated by design.

Looking at the “A” port designation, there are 3 Analog in, in the standard, but also 3 undefined, so I suspect you may actually be able to use pins 7,8, & 9 for analog ins, totaling 6 per port, and both ports 1 and 8 can be used for Analog ins, so the Hero board probably supports 12 total analog ins.

It probably also holds true that the X ports which are defined as 3 DIO and 4 [UN] are essentially Y ports which are 7 DIO. So with 2 X ports and 2 Y ports on the Hero, you probably can handle 28 DIO.

Not sure what your application is needing, but you may have the I/O you need, but not realize it looking at page 10 and 11 (chart 2.2) of the manual. Happy Mentor with Hero running 4 PWM’s and an extra $400 in coffers I didn’t have to spend on CAN controllers. :slight_smile:

That would be fantastic if true! Can I ask what you needed to do to use the ports that way? I know in the designation in the CTRE libraries, there are specific ports allocated and defined.

I hadn’t considered that the pinouts specified would be incomplete or expandable. Our current project requires 4 analog inputs, but also the gadgeteer screen. The screen indicates that it must be plugged in to an “S” marked port, which is 1 or 8. Documentation states that are only 3 analog inputs per “A” marked port, also 1 or 8. So if we use a screen, we’re limited to 3 analog inputs. Outside of that, we’d need 7 digital inputs, which we can do easily with a single “Y” marked port, so I’m not worried there. It’s really the analog inputs that would get me. I’ll find out from CTRE if there might be other Ain ports, but I was wondering what you did to get your extra ports working, if anything. Thank you!

I dug through the manual more, with respect to the analog inputs, and it appears that I was wrong, on page 54, they did not expand the [UN] pins to added Analog ports.

PORT 1 - Pin3 Analog Input 0
PORT 1 – Pin4 Analog Input 1
PORT 1 – Pin5 Analog Input 2
PORT 8 - Pin3 Analog Input 3
PORT 8 – Pin4 Analog Input 4
PORT 8 – Pin5 Analog Input 5

Where on the PWM’s they did…

I just spoke with CTRE support, and as you said, they’re fantastic! They did confirm, as you said, that there is no additional support for analog inputs on the HERO board. However, they did suggest using the data ports on the Talon SRXs and then send the data over the CAN bus. Since we’re using Talons over CAN, this is now a valid option. I’d still like to figure out this HID thing, but it’s nice to know there’s an option.

Sorry, not much help on the USB side of things…
I also was thinking about this, and I remember seeing an analog multiplexer.

So depending on how frequently you need to read analog data, this maybe a workaround, you can control the analog channel via dio for selection and then poll the analog data.

Post your launchpad code and the HERO code and I’ll take a look when I get back to the states and have some time.

I don’t actually have any code for the Launchpad. It was configured automatically using the FRC Gamepad Tool that is provided with the FRC NI suite. Is there some additional configuration that exists for it that I’d need? As I mentioned, it registers perfectly with Windows as a generic HID gamepad. For the HERO code, there isn’t anything besides what I’ve posted so far in the thread. Just those two lines:

GameController _gamepad = new GameController(UsbHostDevice.GetInstance());
if (_gamepad.GetConnectionStatus() == UsbDeviceConnection.Connected)

Followed by a debug output to confirm that the above if statement is indicating a connection.

What I’m curious about is what’s different between the Logitech gamepad and the Launchpad, since they both register the same way in Windows and the HERO documentation specifically mentions that it works with any generic HID gamepad or joystick.

If you have something specific you’d like me to try, let me know and I’ll be happy to give it a shot. Thanks!