Support » Jrk G2 Motor Controller User’s Guide »
14. USB command encoding
This section documents how the Jrk G2’s commands are encoded as native USB control transfers, along with general information about the USB interface.
For a reference implementation of the Jrk G2 native USB protocol, see the Jrk G2 software source code.
The Jrk G2 uses the USB vendor ID of Pololu Corporation, which is 0x1FFB. Each variant has a different USB product ID:
Name | USB product ID |
---|---|
Jrk G2 18v27 | 0x00B7 |
Jrk G2 24v21 | 0x00B9 |
Jrk G2 18v19 | 0x00BF |
Jrk G2 24v13 | 0x00C1 |
Jrk G2 21v3 | 0x00C5 |
The Jrk G2 is composite device, which means it presents multiple USB interfaces to the computer in its USB descriptors. Interface 0 is the native USB interface, and it supports the USB control transfers documented below. Interfaces 1 and 2 comprise the Command Port, a CDC ACM virtual serial port that accepts the serial commands as described in Section 12. Interfaces 3 and 4 comprise the TTL Port.
The Jrk G2 supports Microsoft OS 2.0 Descriptors, an extension to the USB standard that was published by Microsoft and implemented in Windows 8.1 and later. These descriptors tell Windows to use the WinUSB driver for the Jrk G2 native USB interface, and to assign it a device interface GUID of 8d19a22d-7940-4fb5-b126-67c0bf07871f. This GUID was generated by Pololu, and is specific to the Jrk G2. Windows software uses this GUID to connect to the Jrk G2 native USB interface. To support older versions of Windows, the Jrk G2 software comes with a driver that contains equivalent information.
All of the Jrk’s native USB commands are implemented as vendor-defined control transfers on endpoint 0. The tables below show what data is sent in the SETUP packet and the data phase of the control transfer. If the wLength field is zero, the transfer has no data phase. For information about what these commands do and how to pick their parameters, see Section 11.
Set target
bmRequestType | bRequest | wValue | wIndex | wLength |
0x40 | 0x84 | target | 0 | 0 |
The bRequest field holds the target value, which should be between 0 and 4095.
Stop motor
bmRequestType | bRequest | wValue | wIndex | wLength |
0x40 | 0x87 | 0 | 0 | 0 |
Force duty cycle target
bmRequestType | bRequest | wValue | wIndex | wLength |
0x40 | 0xF2 | duty cycle | 0 | 0 |
The wValue field holds the duty cycle value, which should be between −600 and 600. The wValue field is technically an unsigned 16-bit integer, so negative duty cycle values are actually increased by 0x10000 when they are placed into the wValue field (programming languages like C do this automatically for you when you convert a signed integer to an unsigned 16-bit integer).
Force duty cycle
bmRequestType | bRequest | wValue | wIndex | wLength |
0x40 | 0xF4 | duty cycle | 0 | 0 |
This command is encoded in the same way as the “Force duty cycle target” command described above, except that it has a different value for bRequest.
Get variables
bmRequestType | bRequest | wValue | wIndex | wLength | Data |
0xC0 | 0xE5 | flags | offset | length | variable data |
The bits of the wValue variable are flags indicating which variables to clear, if any:
- Bit 0: Clear error flags halting
- Bit 1: Clear error flags occurred
- Bit 2: Clear current chopping occurrence count
For example, to clear “Error flags occurred” and “Current chopping count”, you would set bit 1 and bit 2, so bRequest would have a value of 6.
The wIndex field specifies the offset into the variable data (in bytes). The wLength field specifies how many bytes to read, and should be between 1 and 128.
Set RAM settings
bmRequestType | bRequest | wValue | wIndex | wLength | Data |
0x40 | 0xE6 | 0 | offset | length | setting data |
The wIndex field specifies the offset into the setting data (in bytes). The wLength field specifies how many bytes to write, and should be between 1 and 128.
Get RAM settings
bmRequestType | bRequest | wValue | wIndex | wLength | Data |
0xC0 | 0xEA | 0 | offset | length | setting data |
The wIndex field specifies the offset into the setting data (in bytes). The wLength field specifies how many bytes to read, and should be between 1 and 128.
Get EEPROM settings
bmRequestType | bRequest | wValue | wIndex | wLength | Data |
0xC0 | 0xE3 | 0 | offset | length | setting data |
The wIndex field specifies the offset into the setting data (in bytes). The wLength field specifies how many bytes to read, and should be between 1 and 128.
Set EEPROM setting
bmRequestType | bRequest | wValue | wIndex | wLength |
0xC0 | 0x13 | value | offset | 0 |
The wIndex field specifies the offset into the setting data (in bytes). The wValue field holds a value between 0 and 255; this value will be written to the EEPROM byte at the specified offset.
Reinitialize
bmRequestType | bRequest | wValue | wIndex | wLength |
0x40 | 0x10 | flags | 0 | 0 |
When bit 0 of bRequest is 1, errors are preserved as described in Section 11.
Start bootloader
bmRequestType | bRequest | wValue | wIndex | wLength |
0x40 | 0xFF | 0 | 0 | 0 |