Resources »Pololu Jrk USB Motor Controller User's Guide
View document on multiple pages.
1. Overview
The jrk family of versatile, general-purpose motor controllers supports a variety of interfaces, including USB. Analog voltage and tachometer (frequency) feedback options allow quick implementation of closed-loop servo systems, and a free configuration utility (for Windows) allows easy calibration and configuration through the USB port. There are two different jrk motor controllers: The jrk 21v3 has a broad operating range from 5 V to 28 V. The continuous output current of 3 A (5 A peak) allow this board to control most small DC brushed motors. The jrk 12v12 has an operating range from 6 V to 16 V. The high continuous output current of 12 A (30 A peak) allow this board to control many medium-sized DC brushed motors Main Features of the Jrk 21v3
Main Features of the Jrk 12v12
Main Features of all Jrk Motor Controllers
Specifications
Included Hardware
The jrk 21v3 ships with a 14×1 straight 0.100" male header strip and two 3.5mm, 2-pin terminal blocks. The jrk 12v12 ships with a 14×1 straight 0.100" male header strip and two 5mm, 2-pin terminal blocks. To provide maximum flexibility, none of these parts are soldered to the board. For the most compact installation, you can solder wires directly to the jrk pads themselves and skip using the included hardware. The included hardware allows you to make less permanent connections. You can break the 14×1 header strip into an 8×1 piece and two 3×1 pieces and solder these strips into the jrk’s I/O pads. The three mounting holes are intended for use with #2 screws (not included). Note: A USB A to mini-B cable (not included) is required to connect this device to a computer. 1.a. Module Pinout and Components
The Pololu jrk USB motor controller can connect to a computer’s USB port via a USB A to mini-B cable (not included). The USB connection is used to configure the motor controller. It can also be used to send commands to the motor controller, get information about the motor controller’s current state, and send and receive TTL serial bytes on the TX and RX lines. Power for the motor must be supplied to the jrk on the VIN and GND lines pictured on the right side of the diagram above. Your power source must be capable of delivering the current your motor will draw. The jrk has reverse power protection on the motor power input lines, so the board will not be damaged if the motor power inputs are accidentally switched. If the VIN supply is not present, the jrk’s microcontroller can be powered directly from USB and perform all of its functions except for driving the motor. For the jrk 21v3, the input voltage should be 5–28 V (the recommended operating voltage is 8–28 V, but the jrk 21v3’s motor driver has derated performance down to 5 V and transient protection to 40 V). The jrk 21v3’s motor driver can supply a continuous 3 A with peaks up to 5 A. For the jrk 12v12, the input voltage should be 6–16 V. The jrk 12v12’s motor driver can supply a continuous 12 A with peaks up to 30 A. The jrk has a linear voltage regulator that derives 5 V from the VIN supply. The 5 V supply is used as the internal logic supply for the jrk and is also available at several pins for powering devices such as external microcontrollers and feedback sensors (such as potentiometers). Because the regulator must dissipate excess power as heat, the available output current is dependent on the input voltage: 50 mA is available for VIN up to 12 V; the available current drops off linearly from 50 mA at 12 V to zero at 30 V. The jrk has three indicator LEDs:
The ERR line is an optional output that is tied to the red error LED described above. It is driven high when the red LED is on, and it is a pulled low through the red LED when the red LED is off. Since the ERR line is never driven low, it is safe to connect the ERR line of multiple jrks together. Please note, however, that doing this will cause the error LEDs of all connected jrks to turn on whenever one jrk experiences an error; the ERR output of the jrk experiencing the error will drive the LEDs of any other jrks it is connected to, even though they are not experiencing error conditions themselves. For more information on the possible error conditions and response options, please see Section 3.f. The TX line transmits non-inverted, TTL (0 – 5 V) serial bytes. These bytes can either be responses to serial commands sent to the jrk, or arbitrary bytes sent from the computer via the USB connection. For more information about the jrk’s serial interface, see Section 4. The RX line is the jrk’s control input. In serial input mode, the RX line is used to receive non-inverted, TTL (0 – 5 V) serial bytes. These bytes can either be serial commands for the jrk, arbitrary bytes to send back to the computer via the USB connection, or both. For more information about the jrk’s serial interface, see Section 4. In analog input mode, RX is the analog input line used to determine the system’s target output. In pulse width input mode, the jrk measures the duration of pulses on the RX line to determine the system’s target output. Please see Section 3.b for more information on control input signals. The FB line is the jrk’s feedback input. In analog feedback mode, the voltage on the FB line is used as a measurement of the output of the system. In frequency feedback mode, the frequency of low-to-high transitions on the FB line is used as a measurement of the output of the system. Please see Section 3.c for more information on feedback signals. The AUX line is an output that is generally high whenever the jrk has power. The line will only go low for two reasons:
The RST pin can be driven low to perform a hard reset of the jrk’s microcontroller, but this should generally not be necessary for typical applications. The line is internally pulled high, so it is safe to leave this pin unconnected. 1.b. Supported Operating SystemsThe jrk works under Microsoft Windows 8, Windows 7, Windows Vista, Windows XP, Linux, and Max OS X 10.7 or later. The configuration utility works only in Windows, so the jrk must be initially configured from a Windows computer, but after that it can be controlled from a Linux or Mac computer. Under Linux, the two virtual COM ports created by the jrk should appear as devices with names like /dev/ttyACM0 and /dev/ttyACM1 (the number depends on how many other ACM devices you have plugged in) and you can use any terminal program (such as screen) to send and receive bytes on those ports. Alternatively, you can use the Pololu USB Software Development Kit which supports Linux and has example applications that control the jrk using its native USB interface (see Section 6). Under Mac OS X 10.7 or later, the two virtual COM ports created by the jrk should appear as devices with names like /dev/cu.usbmodem00034567 and you can use any terminal program (such as screen) to send and receive bytes on those ports. Mac OS X compatibility: we have confirmed that the jrk works on Mac OS X 10.7 and we can assist with advanced technical issues, but most of our tech support staff does not use Macs, so basic support for Mac OS X is limited. 1.c. PID Calculation OverviewThe jrk is designed to be part of a control system in which the output (usually a motor position or speed) is constantly adjusted to match a specified target value. To achieve this, it constantly measures the state of the system and responds based on the latest information. The information processing performed by the jrk is outlined in the diagram below:
In this diagram, each arrow represents a specific number measured or computed by the jrk, and the blue boxes represent the internal computations that each occur once per PID period. The PID period can be set in 1 ms increments and is one of about 50 configurable parameters that affect the behavior of the system. For more information about configuring the jrk, see Section 3. The jrk uses the following measurements to determine the output:
Every PID cycle, the jrk performs the following computations to determine the behavior of the motor (see Section 3.d for more information):
The resulting value becomes the duty cycle of the PWM (pulse width modulation) signal applied to the motor. A value of +600 corresponds to 100% duty cycle in the forward direction, a value of -600 corresponds to 100% duty cycle in the reverse direction, and a value of 0 corresponds to 0% duty cycle or off. Various parameters and commands have an effect on the steps described above. For example, feedback may be turned off so that the jrk can become a simple speed controller; in this case the PID calculation is bypassed and the duty cycle target is just equal to the target minus 2048. In this mode, limits applied to the duty cycle continue to provide a useful way of preventing damage to the system. As another example, a command to turn the system off prevents the motors from being driven, but all measurements and calculations continue to occur normally. 2. Contacting Pololu
You can check the Pololu Jrk 21v3 USB Motor Controller page or the Pololu Jrk 12v12 USB Motor Controller page for additional information. We would be delighted to hear from you about any of your projects and about your experience with the jrk. You can contact us directly or post on our forum. Tell us what we did well, what we could improve, what you would like to see in the future, or anything else you would like to say! 3. Configuring the Motor Controller3.a. Installing Windows Drivers and the Configuration UtilityIf you use Windows XP, you will need to have Service Pack 3 installed before installing the drivers for the jrk. See below for details. Before you connect your Pololu jrk USB motor controller to a computer running Microsoft Windows, you must install its drivers:
Windows 8, Windows 7, and Windows Vista users: Your computer should now automatically install the necessary drivers when you connect a jrk. No further action from you is required. Windows XP users: Follow steps 5-9 for each new jrk you connect to your computer.
If you use Windows XP and experience problems installing or using the serial port drivers, the cause of your problems might be a bug in older versions of Microsoft’s usb-to-serial driver usbser.sys. Versions of this driver prior to version 5.1.2600.2930 will not work with the jrk. You can check what version of this driver you have by looking in the “Details” tab of the “Properties” window for usbser.sys in C:\Windows\System32\drivers. To get the fixed version of the driver, you will need to install Service Pack 3. If you do not want Service Pack 3, you can try installing Hotfix KB918365 instead, but some users have had problems with the hotfix that were resolved by upgrading to Service Pack 3. The configuration utility will work even if the serial port drivers are not installed properly. After installing the drivers, if you go to your computer’s Device Manager and expand the “Ports (COM & LPT)” list, you should see two COM ports: the Command Port and the TTL Port. In parentheses after these names, you will see the name of the port (e.g. “COM5” or “COM6”). If you expand the “Pololu USB Devices” list you should see an entry for the Pololu jrk motor controller.
Some software will not allow connection to higher COM port numbers. If you need to change the COM port number assigned to your USB device, you can do so using the Device Manager. Bring up the properties dialog for the COM port and click the “Advanced…” button in the “Port Settings” tab. From this dialog you can change the COM port assigned to your device. 3.b. Input Options
The Input tab of the jrk configuration utility contains settings for how the feedback system (consisting of the jrk, a motor and a feedback sensor) is externally controlled and monitored. Most importantly, there are three Input modes:
Version 1.3 of the firmware for the Jrk 21v3 and the Jrk 12v12 contains a bug fix that improves the reliability of the Pulse width input. The update is recommended for devices with an earlier firmware version number, including all devices shipped before August 25, 2009. See Section 3.h for upgrade information. Input scalingThe scaling options in this tab determine how the raw input values map to target values, which determine the output of the system. The parameters Maximum and Minimum should be set to the maximum and minimum possible values of the input device; these will be scaled to the target values specified in the right column. For input devices with a clearly defined neutral position, such as joysticks, parameters Neutral Max and Neutral Min are provided. Any input between Neutral Max and Neutral Min will be scaled to the neutral value specified in the right column. Setting the two neutral values to be different allows for a “dead zone”, which is especially desirable in speed control mode. If the input leaves the range specified by the Absolute Max and Absolute Min parameters, an Input disconnect error will occur. For convenience, the Invert input direction option is provided. Select this option to switch the positive and negative input directions. By default, the scaling is linear, but you can change the Degree parameter to use a higher-degree polynomial function, which gives you better control near the neutral point. Clicking the button labeled “Learn…” allows scaling values to be determined automatically: with the motor off, the program will request that the input be set to its minimum, maximum, and neutral positions, and the resulting values will be recorded. After learning, if the neutral position is not important for your system, you may uncheck “Asymmetric” to automatically center the neutral values between minimum and maximum. Input analog to digital conversionIn analog mode, the analog to digital conversion panel lets you specify the number of analog samples to average together each PID cycle, which determines the precision and speed of the analog to digitial conversions. The indicator labeled “PID period exceeded” at the top of the window is provided as a warning for when the analog sampling takes more time than the specified PID period. Selecting the Detect disconnect with AUX option activates an extra feature that allows the jrk to detect if the RX pin becomes disconnected from the analog voltage input device or shorted to 5 V. This option is intended for use in analog voltage input mode with a potentiometer connected between AUX and ground. When the option is selected, the jrk will periodically drive the AUX pin low, verifying that this results in a 0 V signal at RX. If the line does not respond as expected, the Input disconnect error will occur. Serial interfaceThis panel allows the serial ports of the jrk to be configured, including specifying a fixed baud rate and enabling or disabling a CRC byte for all commands. The Device Number setting is useful when using the jrk with other devices in a daisy-chained configuration, and the Timeout specifies the duration before which a Serial timeout error will occur (a Timeout of 0.00 disables the serial timeout feature). For more details on the serial interface, especially for selecting the appropriate mode for your system, see Section 4.a. Manually set target (serial mode only)This section is provided for debugging and testing systems without using an input device. The target may be specified directly with the scrollbar or numerical input. 3.c. Feedback Options
The Feedback tab of the jrk configuration utility controls the measurements of the output of the control system. If this section is properly configured, the value of scaled feedback will be 0 when the output is at the minimum position and 4095 when the output is at its maximum. There are three available feedback modes:
Feedback scalingThe scaling options in this tab determine how the raw feedback values map to scaled feedback values, which are intended to be a representation of the output of the system. The parameters Maximum and Minimum should be set to the maximum and minimum possible values of the output; these will be converted to scaled feedback values of 4095 and 0, respectively. If the feedback leaves the range specified by the Absolute Max and Absolute Min parameters, a Feedback disconnect error will occur. For convenience, the Invert feedback direction option is provided. Select this option if the direction of motion that you would like to call positive actually results in a decreasing feedback value. Clicking the button labeled “Learn…” allows scaling values to be determined automatically: with the motor off, the program will request that the output be moved to its minimum and maximum, and the resulting values will be recorded. Input analog to digital conversionIn analog mode, the analog to digital conversion panel lets you specify the number of analog samples to average together each PID cycle, which determines the precision and speed of the analog to digital conversions. The indicator labeled “PID period exceeded” at the top of the window is provided as a warning for when the analog sampling takes more time than the specified PID period. Selecting the Detect disconnect with AUX option activates an extra feature that allows the jrk to detect if the FB pin becomes disconnected from the analog voltage input device or shorted to 5 V. This option is intended for use in analog voltage feedback mode with a potentiometer connected between AUX and ground. When the option is selected, the jrk will periodically drive the AUX pin low, verifying that this results in a 0 V signal at FB. If the line does not respond as expected the Feedback disconnect error will occur. 3.d. PID Options
The PID tab of the jrk configuration utility controls the central calculation performed by the jrk:
The integral is computed as the sum of the error over all PID cycles, and the derivative is the current error minus the previous error. The error itself is the difference of the scaled feedback and the target (error = scaled feedback – target). Each of the PID coefficients is specified as an integer value divided by a power of two. The proportional and derivative coefficients can have values from 0.00003 to 1024, and any value above 0.0152 can be approximated within 0.5%. To get the closest approximation to a desired value, type the number into the box after the equal sign, and the best possible numerator and denominator will be computed. In the case of the integral coefficient, the range of the denominator is actually 23 to 218; this is a more useful range, since the integral is usually much larger than the error or derivative. The PID period can be adjusted here; this sets the rate at which the jrk runs through all of its calculations. Note that a higher PID period will result in a more slowly changing integral and a higher derivative, so that the two corresponding PID constants might need to be adjusted whenever the PID period is changed. Preventing integral wind-upThree options are provided for limiting “integral wind-up”, which is the uncontrolled growth of the integral when the feedback system is temporarily unable to keep the error small. This might happen, for example, when the target is changing quickly. One option is the integral limit, a value from 0 to 32767 that simply limits the magnitude of the integral. Note that the maximum value of the integral term can be computed as the integral coefficient times the integral limit: if this is very small compared to 600 (maximum duty cycle), the integral term will have at most a very small effect on the duty cycle. Another option causes the integral to reset to 0 when the proportional term exceeds the maximum duty cycle parameter. For example, if this option is selected when the proportional coefficient is 15 and the maximum duty cycle is 300, the integral will reset whenever the error is larger than 20. Additionally the Feedback dead zone option sets the duty cycle target to zero and resets the integral whenever the magnitude of the error is smaller than this amount. This is useful for preventing the motor from driving when the target is very close to scaled feedback. The feedback dead zone uses hysteresis to keep the system from simply riding the edge of the dead zone; once in the dead zone, the duty cycle and integral will remain zero until the magnitude of the error exceeds twice this value. 3.e. Motor Options
The Motor tab of the jrk configuration utility controls the PWM signal applied to the motor, including all limits that are applied when converting duty cycle target to duty cycle. The jrk’s PWM duty cycle has a range of -600 to 600, where -600 is full reverse and 600 is full forward. “Forward” and “reverse” should be consistent with the scaled feedback values, so that when the duty cycle is positive, the motor spins in a direction that increases the scaled feedback. By default, full forward (+600) means motor output A = VIN and B = 0 V, while full reverse (-600) means A = 0 V and B = VIN. When checked, the Invert motor direction option switches these definitions so that full forward (+600) means A = 0 V and B = VIN, while full reverse (-600) means A = VIN and B = 0 V. Detect motor directionTo automatically detect whether the motor is inverted or not, click “Detect Motor Direction”. This will attempt to drive the motor with a gradually increasing duty cycle until it starts to move, as measured by the feedback. Make sure to configure feedback correctly before clicking this button, or the results will be meaningless. It is also recommended to set up low maximum duty cycles and currents, and set the Motor drive error, Feedback disconnect, and Max. current exceeded errors to be “Enabled and latched”, so that any potentially damaging conditions encountered during this test will cause the jrk to turn off the motor. PWM frequencyThe jrk is capable of both 20 kHz and 5 kHz PWM. The 20 kHz PWM frequency is ultrasonic and can thus eliminate audible PWM-induced motor humming, which makes this frequency desirable for typical applications. However, a higher PWM frequency means greater power loss due to switching, which could make a 5 kHz PWM frequency a better choice for certain applications. Additionally, the 5 kHz PWM frequency allows for finer control at duty cycles approaching 0% or 100% (±600). This is because the timing characteristics of the jrk motor drivers make it so that very short PWM pulses (either low or high) have no effect on the output voltage. This limitation is more pronounced on the jrk 21v3, in which pulses that are shorter than approximately 4 μs have no effect on the output voltage. Therefore, at 20 kHz, the jrk 21v3 with a duty cycle less than 8% will effectively have a duty cycle of 0% (braking), while a duty cycle greater than 92% will be the same as a duty cycle of 100% (the jrk 12v12 can typically go a bit closer to 0% and 100%). At 5 kHz, the effect is smaller by a factor of four: a duty cycle less than 2% will be the same as a duty cycle of 0% (braking) while a duty cycle greater than 98% will be the same as a duty cycle of 100%. LimitsVarious limits may be applied to the duty cycle, each of which can be configured separately for forward (positive duty cycle) and reverse (negative duty cycle) if the “Asymmetric” option is checked: Max. duty cycle limits the duty cycle itself. Max. acceleration limits the amount that the duty cycle can change by in a single PID period. For example, if there is an acceleration limit of 10 in both directions, and the current duty cycle is 300, then the duty cycle in the next PID period is limited to be within -10 to 310. Max. current causes the jrk to measure the motor driver current and adjust the duty cycle as necessary to limit it the specified value. The current is reported as a number from 0 to 255 that is multiplied by the Current calibration to get a number in mA, so increasing the current calibration value will increase the measured value. For accurate current limiting, acceleration should be limited; otherwise the duty cycle will tend to oscillate when the maximum current is exceeded. Brake duration is a feature that is most useful for large motors with high-inertia loads used with frequency feedback or speed control mode (no feedback). If this option is used, the jrk will automatically keep the motor at a duty cycle of 0 for the specified time before switching directions. The “forward” setting refers to switching from forward to reverse, and the “reverse” setting refers to switching from reverse to forward. Max. duty cycle while feedback is out of range is an option to limit possible damage to systems by reducing the maximum duty cycle whenever the feedback value is beyond the absolute minimum and maximum values. This can be used, for example, to slowly bring a system back into its valid range of operation when it is dangerously near a limit. The Feedback disconnect error should be disabled when this option is used. When motor is offWhen the motor is off because of an error condition or an explicit Motor Off command, there are two options for the state of the motor driver: brake (A and B both connected to GND) and coast (A and B floating). You can familiarize yourself with motor coasting and braking using nothing more than a motor. First, with your motor disconnected from anything, try rotating the output shaft and note how easily it turns. Then hold the two motor leads together and try rotating the output shaft again. You should notice significantly more turning resistance while the leads are shorted together. The jrk 21v3 PWMs the motor outputs between driving and braking, and a duty cycle of zero is the same as braking. The jrk 12v12 PWMs the motor outputs between driving and coasting when the duty cycle is non-zero. As of firmware version 1.4, the behavior of the jrk 12v12 when the duty cycle is zero depends on the “When motor is off” configuration option. In previous versions, at a duty cycle of 0, the jrk 12v12 would brake the motor in one direction but let it coast in the other direction. 3.f. Error Response Options
There are several errors that can stop the jrk from driving its motor. For information about what each error means, see Section 4.f. The jrk’s response to the different errors can be configured. Each error has up to three different available settings.
3.g. The Plots WindowThe Plots window of the configuration utility displays real-time data from the jrk, scrolling from right to left. To access this window, select “Plots” from the Window menu, or click on the small plot displayed in the upper-right corner of the main window. All of the variables discussed in Section 1.c are available. Each variable can be independently scaled to a useful range. For example, the Error can be from -4095 to +4095, but for well-tuned feedback systems, it will usually have a much smaller value, so setting the range to ±100 might provide a more useful plot. The plot shows all variables on a scale from -100% to 100%, where 100% represents the high end of the variable’s range. The percentage range displayed on the plot can also be adjusted, using the Range settings at the bottom of the plot window. By default, the plot shows data from the past 5 seconds, with the most recent values on the right and the older values on the left. The time scale of the plot can be shortened using the Time (s) setting at the bottom of the window. The color of each variable in the graph can be selected by double clicking on the colored box next to the variable’s name. Each variable can be independently shown or hidden using the checkbox next to the variable’s name. Here is an example showing all variables plotted simultaneously:
3.h. Upgrading FirmwareThe jrk has field-upgradeable firmware that can be easily updated with bug fixes or new features. You can determine the version of your jrk’s firmware by running the configuration utility (Section 3.a), connecting to a jrk, and looking at the firmware version number which is displayed in the upper left corner below the “Connected to” dropdown box. Version 1.4 of the firmware for the jrk 12v12 extends the “When motor is off” parameter so that it now affects the behavior of the jrk whenever the duty cycle is 0. Previously, at a duty cycle of 0, the jrk 12v12 would brake the motor in one direction but let it coast in the other direction. Now the default behavior is to brake in both directions, but you can configure it to coast instead. Firmware version 1.4 also makes the jrk 12v12 brake low (connect both A and B to GND) instead of braking high. All jrk 12v12s manufactured after August 24, 2012 ship with firmware version 1.4. The latest version of the jrk 21v3 firmware available is Version 1.3. Do not attempt to load jrk 12v12 firmware onto a jrk 21v3, or vice-versa. To upgrade your jrk’s firmware, follow these steps:
If you run into problems during a firmware upgrade, please contact us for assistance. 4. Using the Serial Interface4.a. Serial ModesThe jrk has three different serial interfaces. First, it has the RX and TX lines. The jrk can send bytes on the TX line. If the jrk is in serial input mode, the RX line can be used to receive non-inverted, TTL (0 – 5 V) serial bytes (Section 4.b). If the jrk is not in serial input mode, it can not receive bytes on RX because the line is used for analog voltage or pulse width measurement. Secondly, the jrk shows up as two virtual serial ports on a computer if it is connected via USB. One of these ports is called the Command Port and the other is called the TTL port. You can determine the COM port numbers of these ports by looking in your computer’s Device Manager. See Section 3.a for information. The jrk can be configured to be in one of three basic serial modes: USB Dual Port
In this mode, the Command Port can be used to send commands to the jrk and receive responses from it. The baud rate you set in your terminal program when opening the Command Port is irrelevant. The TTL Port can be used to send bytes on the TX line and (if the jrk is in serial input mode) receive bytes on the RX line. The baud rate you set in your terminal program when opening the TTL Port determines the baud rate used to receive and send bytes on RX and TX. This allows your computer to control the jrk and simultaneously use the RX and TX lines as a general purpose serial port that can communicate with other types of TTL serial devices. USB Chained
In this mode, the Command Port is used to both transmit bytes on the TX line and send commands to the jrk. The jrk’s responses to those commands will be sent to the Command Port but not the TX line. If the input mode is serial, bytes received on the RX line will be sent to the Command Port but will not be interpreted as command bytes by the jrk. The baud rate you set in your terminal program when opening the Command Port determines the baud rate used to receive and send bytes on RX and TX. The TTL Port is not used. This mode allows a single COM port on your computer to control multiple jrks, or a jrk and other devices that have a compatible protocol. UART
In this mode, the TX and RX lines can be used to send commands to the jrk and receive responses from it. Any byte received on RX will be sent to the Command Port, but bytes sent from the Command Port will be ignored. The TTL Port is not used. The baud rate on TX and RX can either be automatically detected by the jrk when a 0xAA byte is received on RX, or it can be set to a fixed value ahead of time. This mode is only available when the input mode is serial. This mode allows you to control the jrk (and send bytes to a serial program on the computer) using a microcontroller or other TTL serial device. 4.b. TTL SerialIf the jrk is in serial input mode, then its serial receive line, RX, can receive bytes when connected to a logic-level (0 to 4.0–5 V, or “TTL”), non-inverted serial signal. The bytes sent to the jrk on RX can be commands to the jrk or an arbitrary stream of data that the jrk passes on to a computer via the USB port, depending on which Serial Mode the jrk is in (Section 4.a). The voltage on the RX pin should not go below 0 V and should not exceed 5 V. The jrk provides logic-level (0 to 5 V) serial output on its serial transmit line, TX. The bytes sent by the jrk on TX can be responses to commands that request information or an arbitrary stream of data that the jrk is receiving from a computer the USB port and passing on, depending on which Serial Mode the jrk is in. If you aren’t interested in receiving TTL serial bytes from the jrk, you can leave the TX line disconnected. The serial interface is asynchronous, meaning that the sender and receiver each independently time the serial bits. Asynchronous TTL serial is available as hardware modules called “UARTs” on many microcontrollers. Asynchronous serial output can also be “bit-banged” by a standard digital output line under software control. The data format is 8 data bits, one stop bit, with no parity, which is often expressed as 8-N-1. The diagram below depicts a typical asynchronous, non-inverted TTL serial byte:
A non-inverted TTL serial line has a default (non-active) state of high. A transmitted byte begins with a single low “start bit”, followed by the bits of the byte, least-significant bit (LSB) first. Logical ones are transmitted as high (Vcc) and logical zeros are transmitted as low (0 V), which is why this format is referred to as “non-inverted” serial. The byte is terminated by a “stop bit”, which is the line going high for at least one bit time. Because each byte requires a start bit, 8 data bits, and a stop bit, each byte takes 10 bit times to transmit, so the fastest possible data rate in bytes per second is the baud rate divided by ten. At the jrk’s maximum baud rate of 115,200 bits per second, the maximum realizable data rate, with a start bit coming immediately after the preceding byte’s stop bit, is 11,520 bytes per second. Whenever connecting devices, remember to wire the grounds together, and ensure that each device is properly powered. Unpowered devices with a TTL serial port can turn on or partially on, drawing power from the serial line, which means that extra care must be taken when turning power off and on to reset the devices. 4.c. Command ProtocolsYou can control the jrk by issuing serial commands. If your jrk’s input mode is Serial and its Serial Mode is “UART, detect baud rate”, you must first send it the byte 0xAA (170 in decimal) on the RX line (so it can detect the baud rate) before sending it any commands. The jrk serial command protocol is fairly straightforward. Communication is achieved by sending command packets consisting of a single command byte followed by any data bytes that command requires. Command bytes always have their most significant bits set (i.e. they range from 128–255, or 0x80–0xFF in hex) while data bytes always have their most significant bits cleared (i.e. they range from 0–127, or 0x00–0x7F in hex). This means that each data byte can only transmit seven bits of information. The jrk responds to two sub-protocols: Compact ProtocolThis is the simpler and more compact of the two protocols; it is the protocol you should use if your jrk is the only device connected to your serial line. The jrk compact protocol command packet is simply: command byte (with MSB set), any necessary data bytes For example, if we want to set the target to 4080 (the highest value achievable using the low resolution Set Target commands), we could send the following byte sequence:
in hex: 0xE1, 0x7F The byte 0xE1 is the Set Target Low Resolution Forward command, and the data byte contains the motor speed. Note that the Set Target High Resolution command uses some of the bits in the command byte to represent data, so there is not a one-to-one correspondence between command bytes and commands. Pololu ProtocolThis protocol is compatible with the serial protocol used by our other serial motor and servo controllers. As such, you can daisy-chain a jrk on a single serial line along with our other serial controllers (including additional jrks) and, using this protocol, send commands specifically to the desired jrk without confusing the other devices on the line. The Pololu protocol is to transmit 0xAA (170 in decimal) as the first (command) byte, followed by a Device Number data byte. The default Device Number for the jrk is 11, but this is a configuration parameter you can change. Any jrk on the line whose device number matches the specified device number accepts the command that follows; all other Pololu devices ignore the command. The remaining bytes in the command packet are the same as the compact protocol command packet you would send, with one key difference: the compact protocol command byte is now a data byte for the command 0xAA and hence must have its most significant bit cleared. Therefore, the command packet is: 0xAA, device number byte, command byte with MSB cleared, any necessary data bytes For example, if we want to set the target to 4080 for a jrk with device number 11, we could send the following byte sequence:
in hex: 0xAA, 0x0B, 0x61, 0x7F Note that 0x61 is the command 0xE1 with its most significant bit cleared. The jrk responds to both the Pololu and Compact protocols on the fly; you do not need to use a configuration parameter to identify which protocol you are using. 4.d. Cyclic Redundancy Check (CRC) Error DetectionFor certain applications, verifying the integrity of the data you are sending and receiving can be very important. Because of this, the jrk has optional 7-bit cyclic redundancy checking, which is similar to a checksum but more robust as it can detect errors that would not affect a checksum, such as an extra zero byte or bytes out of order. Cyclic redundancy checking can be enabled by checking the “Enable CRC” checkbox in the configuration utility. In CRC mode, the jrk expects an extra byte to be added onto the end of every command packet. The most-significant bit of this byte must be cleared, and the seven least-significant bits must be the 7-bit CRC for that packet. If this CRC byte is incorrect, the jrk will generate its Serial CRC error and ignore the command. The jrk does not append a CRC byte to the data it transmits in response to serial commands. A detailed account of how cyclic redundancy checking works is beyond the scope of this document, but you can find a wealth of information using Wikipedia. The CRC computation is basically a carryless long division of a CRC “polynomial”, 0x91, into your message (expressed as a continuous stream of bits), where all you care about is the remainder. The jrk uses CRC-7, which means it uses an 8-bit polynomial and, as a result, produces a 7-bit remainder. This remainder is the lower 7 bits of the CRC byte you tack onto the end of your command packets. The CRC implemented on the jrk is the same as the one on the qik motor controller but differs from that on the TReX motor controller. Instead of being done MSB first, the computation is performed LSB first to match the order in which the bits are transmitted over the serial line. In standard binary notation, the number 0x91 is written as 10010001. However, the bits are transmitted in this order: 1, 0, 0, 0, 1, 0, 0, 1, so we will write it as 10001001 to carry out the computation below. The CRC-7 algorithm is as follows:
If you have never encountered CRCs before, this probably sounds a lot more complicated than it really is. The following example shows that the CRC-7 calculation is not that difficult. For the example, we will use a two-byte sequence: 0x83, 0x01.
So the full command packet we would send with CRC enabled is: 0x83, 0x01, 0x17. 4.e. Motor Control CommandsThe jrk has several serial commands for turning the motor on and off and setting the target. These commands are mainly intended to be used in serial input mode, but they can be used in any input mode to turn the motor on or off from a computer. Motor OffCompact protocol: 0xFF This command will turn the motor off by setting the Awaiting Command error bit. The jrk will not restart the motor until it receives a Set Target command. The jrk can be configured to either brake or coast while the motor is off (Section 3.e). Set Target High ResolutionCompact protocol, binary: 110LLLLL, 0HHHHHHH This command clears the Awaiting Command error bit and (if Input Mode is Serial) lets you set the 12-bit target to any of its allowed values (0–4095). The meaning of the target depends on what Feedback Mode the jrk is in (Section 3.c). The lower 5 bits of the command byte represent the lower 5 bits of the target, while the lower 7 bits of the data byte represent the upper 7 bits of the target. For example, if you want to set the target to 3229 (110010011101 in binary), you could send the following byte sequence:
in binary: 11011101, 01100100 Here is some example C code that will generate the correct serial bytes, given an integer “target” that holds the desired target (0–4095) and an array called serialBytes: serialBytes[0] = 0xC0 + (target & 0x1F); // Command byte holds the lower 5 bits of target. serialBytes[1] = (target >> 5) & 0x7F; // Data byte holds the upper 7 bits of target. Many motor control applications do not need 12 bits of target resolution. If you want a simpler and lower-resolution set of commands for setting the target, you can use the Set Target Low Resolution commands. Alternatively, you could use the Set Target High Resolution command with the lower 5 bits of the target always zero: sending a 0xC0 byte followed by a data byte (0–127) will result in setting the target to a value of 32 multiplied by the data byte. Set Target Low Resolution ForwardCompact protocol: 0xE1, magnitude This command clears the Awaiting Command error bit and (if Input Mode is Serial) sets the target to a value of 2048 or greater which is determined by the magnitude (0–127). If the Feedback Mode is Analog or Tachometer, then the formula is Target = 2048 + 16×magnitude. If the Feedback Mode is None (speed control mode), then the formula is Target = 2048 + (600/127)×magnitude. This means that a magnitude of 127 will set the duty cycle target to full-speed forward (+600), while a magnitude of zero will make the motor stop. Set Target Low Resolution ReverseCompact protocol: 0xE0, magnitude If magnitude is zero, then this command is equivalent to the Motor Off command above: the Awaiting Command error bit will be set, so the jrk will turn the motor off until another Set Target command is received. Otherwise, this command clears the Awaiting Command error bit and (if Input Mode is Serial) sets the target to a value less than 2048 which is determined by the magnitude (0–127). If the Feedback Mode is Analog or Tachometer, then the formula is Target = 2048 − 16×magnitude. If the Feedback Mode is None (speed control mode), then the formula is Target = 2048 − (600/127)×magnitude. This means that a magnitude of 127 will set the duty cycle target to full-speed reverse (-600). 4.f. Error Reporting CommandsThere are several errors that can stop the jrk from driving its motor. The jrk’s response to the different errors can be configured (Section 3.f). Both of the error reporting commands result in a two-byte serial response form the jrk. Each bit in those two bytes represents a particular error. If the bit is 1, it means that the error occurred or is occurring. If we call the least-significant bit 0, and the first byte transmitted contains bits 0-7, then the correspondence between bits of the error bytes and errors are as follows:
Get Error Flags HaltingCompact protocol: 0xB3 This command generates a two-byte serial response reporting which errors are currently stopping the motor, and it clears the corresponding error bits (except for the Awaiting Command error bit). This command is useful for determining why your motor is not turning, and for clearing any latched errors that are enabled. This command will not report any errors that have been disabled in the configuration utility, because those errors do not stop the motor. This command is equivalent to reading the “Currently stopping motor?” column in the Errors tab of the configuration utility, and then clicking the “Clear Errors” button. If an error is stopping the motor (besides the Awaiting Command error bit), the jrk will turn the red LED on and drive the ERR line high, and this command can be used to determine the cause of the error. Get Error Flags OccurredCompact protocol: 0xB5 This command generates a two-byte serial response reporting which errors have occurred since the last time the Get Error Flags Occurred command was received. Unlike the Get Error Flags Halting command, this command has no effect on the motor. Note: If the jrk is connected to the configuration utility, then the Get Error Flags Occurred command will give unreliable responses, because the configuration utility runs this command regularly. This command will report all the errors that have occurred since the last time the Get Error Flags Occurred command was received, regardless of whether that last command came from the configuration utility, from your microcontroller, or from the jrk’s virtual Command Port. 4.g. Variable Reading CommandsCompact protocol: read variable command byte The jrk has several serial commands for reading its variables. Most of the variables are two bytes long. For each of those variables, three variable reading commands are provided:
The command bytes are listed in the table below.
The meaning of the variables is described below:
Note: All command bytes from 0x81 to 0xBF that are not listed in this section or Section 4.f are undocumented variable reading commands that will result in a serial response from the jrk and not generate a serial protocol error. These commands are not useful, but they are not harmful. 4.h. Daisy-ChainingThis section is a guide to integrating the jrk in to a project that has multiple TTL serial devices that use the Pololu Protocol or some compatible protocol. This section contains no new information about the jrk: all of the information in this section can be deduced from the definitions of the three serial modes (Section 4.a) and the Pololu Protocol (Section 4.c). First of all, assign each device in the project a different device number so that they can be individually addressed by Pololu Protocol serial commands. For the jrk, this can be done in the Input tab of the configuration utility. The following diagram shows how to connect one master and many slave devices together into a chain. Each of the devices may be a jrk or any other device compatible with the Pololu Protocol, such as a qik, servo controller, or a microcontroller.
Using a PC and a jrk together as the master deviceThe jrk can enable a personal computer to be the master device. The jrk must be connected to a PC with a USB cable and configured to be in either USB Dual Port or USB Chained serial mode. Serial input mode must be used to receive responses from slave devices (if you do not need to receive reponses, you may use other input modes). In USB Dual Port mode, the Command Port on the PC is used for sending commands directly to the jrk, and the TTL Port on the PC is used to send commands to all of the slave devices. In the USB Chained mode, only the Command Port is used on the PC, to communicate with the jrk and all of the slave devices. Select the mode that is most convenient for your application or easiest to implement in your programming language. Using a jrk as a slave deviceThe jrk can act as a slave device when configured to be in the UART serial mode and Serial input mode. In this mode, commands are received on the RX line, and responses are sent on the TX line. A USB connection to a PC is not required, though an RX-only Comand Port is available on the PC for debugging or other purposes. ConnectionsConnect the TX line of the master device to the RX lines of all of the slave devices. Commands sent by the master will then be received by all slaves. Receiving serial responses from one the slave devices on the PC can be achieved by connecting the TX line of that slave device to the RX line of the jrk. Receiving serial responses from multiple slave devices is more complicated. Each device should only transmit when requested, so if each device is addressed separately, multiple devices will not transmit simultaneously. However, the TX outputs are driven high when not sending data, so they cannot simply be wired together. Instead, you can use an AND gate, as shown in the diagram, to combine the signals. Note that in many cases receiving responses is not necessary, and the TX lines can be left unconnected. If there are multiple slave jrks, you can connect all of the jrks’ ERR lines to a single input on a microcontroller to monitor the error state. Whenever connecting devices, remember to wire the grounds together, and ensure that each device is properly powered. Unpowered devices with a TTL serial port can turn on or partially on, drawing power from the serial line, which means that extra care must be taken when turning power off and on to reset the devices. Sending commandsThe Pololu Protocol should be used when multiple Pololu devices are receiving the same serial data. This allows the devices to be individually addressed, and it allows responses to be sent without collisions. If the devices are configured to detect the baud rate, then when you issue your first Pololu Protocol command, the devices can automatically detect the baud from the initial 0xAA byte. Some older Pololu devices use 0x80 as an initial command byte. If you want to chain these together with devices expecting 0xAA, you should first transmit the byte 0x80 so that these devices can automatically detect the baud rate, and only then should you send the byte 0xAA so that the jrk can detect the baud rate. Once all devices have detected the baud rate, Pololu devices that expect a leading command byte of 0x80 will ignore command packets that start with 0xAA, and jrks will ignore command packets that start with 0x80. 4.i. Serial Example Code4.i.1. Cross-platform CThe example C code below works on Windows, Linux, and Mac OS X 10.7 or later. It demonstrates how to set the target of a jrk by sending a Set Target command to its Command Port, and how to read variables from the jrk. The jrk’s input mode must be set to “Serial” and the serial mode must be “USB Dual Port” for this code to work. You will also need to modify the line that specifies the name of the COM port device. This code will work in Windows if compiled with MinGW, but it does not work with the Microsoft C compiler. For Windows-specific example code that works with either compiler, see Section 4.i.2.
// Uses POSIX functions to send and receive data from a jrk.
// NOTE: The jrk's input mode must be "Serial".
// NOTE: The jrk's serial mode must be set to "USB Dual Port".
// NOTE: You must change the 'const char * device' line below.
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#ifdef _WIN32
#define O_NOCTTY 0
#else
#include <termios.h>
#endif
// Reads a variable from the jrk.
// The 'command' argument must be one of the two-byte variable-reading
// commands documented in the "Variable Reading Commands" section of
// the jrk user's guide.
int jrkGetVariable(int fd, unsigned char command)
{
if(write(fd, &command, 1) == -1)
{
perror("error writing");
return -1;
}
unsigned char response[2];
if(read(fd,response,2) != 2)
{
perror("error reading");
return -1;
}
return response[0] + 256*response[1];
}
// Gets the value of the jrk's Feedback variable (0-4095).
int jrkGetFeedback(int fd)
{
return jrkGetVariable(fd, 0xA5);
}
// Gets the value of the jrk's Target variable (0-4095).
int jrkGetTarget(int fd)
{
return jrkGetVariable(fd, 0xA3);
}
// Sets the jrk's Target variable (0-4095).
int jrkSetTarget(int fd, unsigned short target)
{
unsigned char command[] = {0xC0 + (target & 0x1F), (target >> 5) & 0x7F};
if (write(fd, command, sizeof(command)) == -1)
{
perror("error writing");
return -1;
}
return 0;
}
int main()
{
// Open the Jrk's virtual COM port.
const char * device = "\\\\.\\USBSER000"; // Windows, "\\\\.\\COM6" also works
//const char * device = "/dev/ttyACM0"; // Linux
//const char * device = "/dev/cu.usbmodem00000041"; // Mac OS X
int fd = open(device, O_RDWR | O_NOCTTY);
if (fd == -1)
{
perror(device);
return 1;
}
#ifndef _WIN32
struct termios options;
tcgetattr(fd, &options);
options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
options.c_oflag &= ~(ONLCR | OCRNL);
tcsetattr(fd, TCSANOW, &options);
#endif
int feedback = jrkGetFeedback(fd);
printf("Current Feedback is %d.\n", feedback);
int target = jrkGetTarget(fd);
printf("Current Target is %d.\n", target);
int newTarget = (target < 2048) ? 3000 : 1000;
printf("Setting Target to %d.\n", newTarget);
jrkSetTarget(fd, newTarget);
close(fd);
return 0;
}
4.i.2. Windows CFor example C code that shows how to control the jrk using its serial interface in Microsoft Windows, download JrkSerialCWindows.zip (4k zip). This zip archive contains a Microsoft Visual C++ 2010 Express project that shows how to send a Set Target command and also a Get Position command. It can also be compiled with MinGW. The jrk’s input mode needs to be set to “Serial” and the serial mode needs to be set to “USB Dual Port” for this code to work. This example is like the previous example except it does the serial communication using Windows-specific functions like CreateFile and WriteFile. See the comments in the source code for more details. 5. Setting Up Your SystemThe following step-by-step procedure is recommended for configuring a feedback system for use with a jrk motor controller. Connecting power and feedback
The red LED should now be off, and the yellow LED should be blinking slowly, indicating that the board has power but that no target has been set. If the red LED is on, examine the Errors tab to determine the source of the problem. Look at the value of Scaled Feedback displayed at the top of the window, and verify that it changes if you manually adjust the feedback sensor. Calibrating feedback
Setting motor limits
Connecting the motorFrom this point on, be prepared to shut down the system by clicking “Stop motor” or turning off your power supply if anything goes wrong and the limits and errors set previously fail to stop the motor.
Testing the motor
Testing basic feedback
If you did everything correctly, your feedback system should now be active, approximately following the target value. Tuning the PID constantsTuning PID constants is a complicated process that can be approached in many different ways. Here we will give a basic procedure that works for some systems, but you will probably want to try various different methods for finding the best possible values. You will want to have the Plots window open, displaying a nice view of the Error, Target, Scaled Feedback, and Duty Cycle. When setting the Integral Coefficient, it will also be useful to look at the value of the Integral.
The following example plot shows a well-tuned system, with Proportional, Integral, and Derivative Coefficients of 6.0, 0.25, and 7.5. When taking steps, the system stops very quickly at a position with very small error, randomly overshooting or undershooting by a small amount.
6. Writing PC Software to Control the JrkThere are two ways to write PC software to control the jrk: the native USB interface and the virtual serial port. The native USB interface provides more features than the serial port, such as the ability to change configuration parameters and select the jrk by its serial number. Also, the USB interface allows you to recover more easily from temporary disconnections. The virtual serial port interface is easier to use if you are not familiar with programming, and it can work with existing software programs that use serial ports, such as LabView. Native USB InterfaceThe Pololu USB Software Development Kit supports Windows and Linux, and includes C# source code for:
You can modify the applications in the SDK to suit your needs or you can use the class libraries to integrate the jrk in to your own applications. Advanced users can also use the source code as a reference when writing custom applications in any language that control the jrk over USB. Virtual Serial PortsAlmost any programming language is capable of accessing the COM ports created by the jrk. We recommend the Microsoft .NET framework, which is free to use and contains a SerialPort class that makes it easy to read and write bytes from a serial port. You can download Visual Studio Express (for either C#, C++, or Visual Basic) and write programs that use the SerialPort class to communicate with the jrk. You will need to set the jrk’s serial mode to be either “USB Dual Port” or “USB Chained”. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Log In
|
Wish Lists
|
BIG Order Form
|
Shopping Cart
US toll free: 1-877-7-POLOLU ~
(702) 262-6648 |
|||||||||||||
| Catalog | Forum | Resources | Distributors | Ordering | About | Contact | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|