Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _data/navigation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ wiki:
url: /wiki/interfacing/controller-area-network-can/
- title: Interfacing Streamlit, ROS2, and HTML/CSS/JS for visualization
url: /wiki/interfacing/interfacing-streamlit-ros2-and-html-css-js-for-visualization/
- title: Interfacing RobotEQ Motor Controller with ROS
url: /wiki/common-platforms/interfacing-with-nvidia-orin/

- title: Computing
url: /wiki/computing/
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/interfacing/roborun-run-page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/interfacing/roborun-script-page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions wiki/interfacing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ This section delves into **interfacing techniques and tools** for robotics appli
- **[Interfacing Streamlit, ROS2, and HTML/CSS/JS for Visualizations](/wiki/interfacing/interfacing-streamlit-ros2-and-html-css-js-for-visualization/)**
A practical architecture and implementation guide for combining Streamlit, ROS2, and web components to build real-time robotics visualization dashboards.

- **[Iterfacing with RobotEQ motor controllers](/wiki/interfacing/roboteq-motor-controllers/)**
A comprehensive guide to interfacing RobotEQ motor drivers, including configuration, serial communication, onboard scripting, and ROS integration.

## Resources

### General Tools and Frameworks
Expand Down
357 changes: 357 additions & 0 deletions wiki/interfacing/roboteq-motor-controllers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,357 @@
---
# Jekyll 'Front Matter' goes here. Most are set by default, and should NOT be
# overwritten except in special circumstances.
# You should set the date the article was last updated like this:
date: 2026-02-12 # YYYY-MM-DD
# This will be displayed at the bottom of the article
# You should set the article's title:
title: RobotEQ Motor Controllers
# The 'title' is automatically displayed at the top of the page
# and used in other parts of the site.
---


This page covers interfacing with RobotEQ motor controllers, including configuration, serial communication, onboard scripting, and ROS integration.
RobotEQ motor controllers are designed to control DC motors with encoder feedback. Many models provide position, velocity, and power control.
All models have several safety features, safety/emergency stop, current limits, and speed limits, making RobotEQ controllers a safe choice for prototyping.
This page does not cover hardware interfacing, only software, since hardware configuration depends on the use case.

## Prerequisites

It is assumed that the motor controller hardware is already set up.

Serial communication with RobotEQ motor controllers can be established over a USB-B cable, the same type as for an Arduino UNO.

RobotEQ controllers can be configured and tested with a Windows utility called RoboRun+, which is available for free download from
[https://www.roboteq.com/products/software/roborunplus-detail](https://www.roboteq.com/products/software/roborunplus-detail).
It is possible to configure the controller over serial alone, but doing so won't be covered here.

RobotEQ manuals can be downloaded from [https://www.roboteq.com/support/documentation-download](https://www.roboteq.com/support/documentation-download).
The manuals referenced by this page are:
- [User Manual](https://www.roboteq.com/docman-list/motor-controllers-documents-and-files/documentation/user-manual/1047-roboteq-controllers-user-manual-v2-1a/file): general information about all RobotEQ controllers (for a range of firmware versions)
- [MicroBasic Scripting](https://www.roboteq.com/docman-list/motor-controllers-documents-and-files/documentation/user-manual/1063-microbasic-scripting-manual-v2-1a/file): details about how to run small programs on the motor controller itself
- [MDC2xxx Datasheet](https://www.roboteq.com/docman-list/motor-controllers-documents-and-files/documentation/datasheets/gen3/2-datasheet-mdc2xxx/file): a representative datasheet for a RobotEQ controller

It is recommended you download RoboRun+ and the linked manuals for easy access when setting up the controller.


## RoboRun+ Usage

### Configuration

![RoboRun+ Config Tab](/assets/images/interfacing/roborun-config-page.png)

There are many configuration tabs for RobotEQ controllers, but the parameters focused on in this page
are ones relevant for software interfacing, and avoiding some gotchas.

The `Command Priorities` set which serial interface will override the other when signals are active simultaneously.
"Pulse" means the serial connection wired onto the board, and "RS232" is the USB connection. Ensure that whichever
serial source you need has the highest priority.

One issue that can cause the system to fail is the encoder pulses/rev being in the "wrong" direction.
If the encoder wiring is such that the "forward" motor direction is the "backward" encoder direction,
then the position and velocity control modes can fail, either by the motor not moving or by saturating the PID controller.
This case can be caught by running the motors forward in "power" control (which requires no encoder feedback),
and seeing if the pulses counted from the encoder are a positive number, not a negative number.
The fix for this is either to swap the encoder wires, or make the pulses/rev a negative number.

### Testing

![RoboRun+ Run Tab](/assets/images/interfacing/roborun-run-page.png)

The Run Tab includes GUI panels for monitoring and controlling states of the motor controller:
- Status: shows global flags for controller states
- Motor Status: shows fault flags per motor
- Fault: shows global fault flags for the controller
- Digital Inputs: shows the binary state of generic/named digital inputs
- Digital Outputs (D-Out): shows the binary state of digital outputs
- Clicking on an output can toggle it if the output has no external condition controlling it
- Analog Inputs: shows digital signals from onboard the DAC
- Pulse Inputs: tracks the pulses from dedicated pulse inputs for rising/falling/dual edge
- Command: allows sending control signals to the motors from -1000 to 1000
- "mute" means do not send the signal and stop the motors
- "join" means make the motor 1 and motor 2 signals the same
- The red square (stop) button sets the command value to 0
- The value between -1000 and 1000 is interpreted differently depending on if the motor is in position, velocity, or power mode
- Chart/Chart Feed: Displays internal state variables of the motor controller
- This is useful for debugging scripts when state is stored in a user variable
- Console: Allows sending serial commands directly, per the User Manual. The examples in the image are:
- `!VAR 1 0`: set user variable 1 to value 0
- `!G 2 255`: set motor 2 control value to 255


### The Serial Interface

The serial interface is the primary way an external computer will communicate with the RobotEQ controller.
The interface is rich and offers access to every aspect of the device, including updating the controller configuration,
sending motor control commands, setting/clearing the emergency stop, and more!
The reference in the linked [User Manual](https://www.roboteq.com/docman-list/motor-controllers-documents-and-files/documentation/user-manual/1047-roboteq-controllers-user-manual-v2-1a/file) is in `Section 15: Commands Reference`.

Serial commands follow this pattern:

> [symbol] [command] [arguments...] `\r`

Symbols are a single character, meaning:
- `!`: runtime commands that change something immediately and don't persist after power off (e.g. motor control, value in RAM)
- `?`: runtime queries that write information about non-persistant state over serial (e.g. encoder counts)
- `%`: maintenance commands that control persistant state, such as EEPROM
- `~`: config queries that write information about the configuration over serial (e.g. anything in the RoboRun+ config page)
- `^`: config commands that change the configuration while the robot is powered on (they do not persist between power cycles)

For general control, the following commands will be the most relevant:
- `!G ch v`: Set motor on channel `ch` (1/2) to control value `v` (-1000 to 1000)
- `!EX`: emergency stop
- `!MG`: emergency stop release
- `!VAR x y`: Set user variable `x` (0-255) to value `y` (-2^31 to 2^31-1)


### Scripting

Scripts written in MicroBasic run directly on the RobotEQ controller
and can be used to simplify serial communication or execute logic without any communication delay.

The following script is provided as an example. It includes switching between motor control modes,
establishing runtime configuration changes, and supplementing the serial communication interface.
Comments are after the single quote (') character.

```vb
SCRIPT_VER=28
MAX_CHANNELS=2
' Mode values are:
' -1 stopped
' 0 speed mode
' 1 position mode
' These correspond to the constants in roboteq_msgs/Command. The motor begins in stopped
' mode, the setup for which is run when last_mode[0] != VAR[1].
Dim last_mode[2] as Integer ' last mode per motor
Dim c as Integer
Dim last_auton_switch as Integer ' state to track rising/falling edge of digital input

'_VAR[i] contains the desired mode as commanded by the PC
for ch = 1 andwhile ch <= MAX_CHANNELS evaluate ch++
setcommand(_VAR, ch, -1) ' user variables 1 and 2 set the motor control mode per motor
last_mode[ch-1] = -127 ' state to track which state was used previously per motor
next
last_auton_switch = -1
' Motor controller configuration. Much of this is particular to Grizzly
' and can be generalized/parameterized as the need arises. Page numbers
' are a reference to this document:
' www.roboteq.com/index.php/docman/motor-controllers-documents-and-files/documentation/user-manual/7-nextgen-controllers-user-manual/file

' RUNTIME CONFIG CHANGES: these overwrite the config stored from RoboRun, and can be used to centralize controller config in a script instead of a RoboRun file

setconfig(_ECHOF, 1) ' Serial echo off (p195)

setconfig(_RWD, 1000) ' Watchdog timeout, milliseconds (p195)
'setconfig(_AMOD, 1, 1) ' Analog input 1 absolute mode
'setconfig(_AMOD, 2, 1) ' Analog input 2 absolute mode

' Undervoltage/overvoltage limits (p214) (Volts * 10)
setconfig(_OVL, 300)
setconfig(_UVL, 180)

' Encoder, config (p208, p221)
'_EMOD = encoder mode. 18 = motor 1 feedback, 34 = motor 2 feedback
'_EPPR = encoder pulse per revolution (non-quadrature counts)
' Encoder 1 provides motor 1 feedback
setconfig(_EMOD, 1, 18)
setconfig(_EPPR, 1, -1940)

' Encoder 2 provides motor 2 feedback
setconfig(_EMOD, 2, 34)
setconfig(_EPPR, 2, -1940) ' Negative encoder pulses per rev to account for swapped direction

for ch = 1 andwhile ch <= MAX_CHANNELS evaluate ch++
' Speed config (p208, p221)
setconfig(_MXRPM, ch, 100)
setconfig(_CLERD, ch, 0)

' Current limit (p216)
setconfig(_ALIM, ch, 200)
setconfig(_ATGA, ch, 2) ' trigger estop
setconfig(_ATGD, ch, 500)
setconfig(_ATRIG, ch, 200) ' 200 units = 20 A

' Max acceleration/deceleration (p219)
setconfig(_MAC, ch, 200)
setconfig(_MDEC, ch, 500)
next

c = 0 ' counts how many loops there were since the last serial message (prevents saturating the connection)
top:
' Check for amp trigger and estop
if (getvalue(_FM, 1) AND 64) <> 0 then
setcommand(_EX, 1)
end if
if (getvalue(_FM, 2) AND 64) <> 0 then
setcommand(_EX, 1)
end if

' Handle switching between autonomous and manual modes
if last_auton_switch <> getvalue(_DIN, 4) then
last_auton_switch = getvalue(_DIN, 4)
if last_auton_switch = 0 then
' In manual mode, listen to the transmitter's values only (pulse input)
setconfig(_CPRI, 1, 1)
setconfig(_CPRI, 2, 4)
setconfig(_CPRI, 3, 4)
else
' In autonomous mode, listen to the serial connection only (RS232)
setconfig(_CPRI, 1, 0)
setconfig(_CPRI, 2, 4)
setconfig(_CPRI, 3, 4)
' Set motor mixing mode to separate
setconfig(_MXMD, 0)
end if
end if

' In manual mode, use velocity control with mix mode 1
if last_auton_switch = 0 then
' Set all channels to velocity mode
for ch = 1 andwhile ch <= MAX_CHANNELS evaluate ch++
GoSub SetVelocityControlMode
last_mode[ch - 1] = -127
next
' Set mixing mode to mix mode 1
setconfig(_MXMD, 1)
end if
' In autonomous mode, handle switching between position and velocity control
if last_auton_switch = 1 then
for ch = 1 andwhile ch <= MAX_CHANNELS evaluate ch++
if last_mode[ch - 1] <> getvalue(_VAR, ch) then
last_mode[ch - 1] = getvalue(_VAR, ch)

' Motor to be stopped (high-Z).
if getvalue(_VAR, ch) = -1 then
'setconfig(_MMOD, ch, 1)
setconfig(_KP, ch, 0)
setconfig(_KI, ch, 0)
setconfig(_KD, ch, 0)
setconfig(_ICAP, ch, 0)
setcommand(_G, ch, 0)
end if

' Motor in velocity-control mode.
if getvalue(_VAR, ch) = 0 then
GoSub SetVelocityControlMode
end if

' Motor in position-control mode.
if getvalue(_VAR, ch) = 1 then
'setconfig(_MMOD, ch, 3)
setconfig(_KP, ch, 10)
setconfig(_KI, ch, 0)
setconfig(_KD, ch, 0)
setconfig(_ICAP, ch, 0)
end if
end if
next
end if

' Send Feedback for channels at 25Hz
for ch = 1 andwhile ch <= MAX_CHANNELS evaluate ch++
GoSub PrintFeedback
next
' Send status messages for the controller at 5Hz.
c++
if c = 5 then
GoSub PrintStatus
c = 0
end if

wait(19) ' change wait time to naively change loop frequency, there are more sophistocated ways to do this
goto top ' infinite loop

SetVelocityControlMode:
'setconfig(_MMOD, ch, 1)
setconfig(_KP, ch, 100) '0.0001
setconfig(_KI, ch, 100000000) '100
setconfig(_KD, ch, 0)
setconfig(_ICAP, ch, 10) '10%
Return

PrintFeedback:
' This is a custom format to be read by the PC
print("&f:", ch)
print(":", getvalue(_MOTAMPS, ch))
print(":", getvalue(_MOTCMD, ch))
print(":", getvalue(_MOTPWR, ch))
print(":", getvalue(_ABSPEED, ch))
print(":", getvalue(_ABCNTR, ch))
print(":", getvalue(_VOLTS, 2))
print(":", getvalue(_BATAMPS, ch))
print(":", getvalue(_ANAIN, ch))
print(":", getvalue(_TEMP, ch+1))
print("\r")
Return

PrintStatus:
' This is a custom format to be read by the PC
print("&s:", SCRIPT_VER)
print(":", getvalue(_FLTFLAG))
print(":", getvalue(_STFLAG))
print(":", getvalue(_VOLTS, 1)) ' Should be 12V internal
print(":", getvalue(_VOLTS, 2)) ' Should be 24V battery
print(":", getvalue(_TEMP, 1))
print("\r")
Return
```

This script supplements the pre-existing serial commands interface by making user variables
change how the robot responds to commands:
- `!VAR 1/2 -1/0/1`: set motor channel 1/2 to -1(stop), 0 (velocity), or 1 (position) mode
- `!G 1/2 -1000..1000`: this control signal means something different when `!VAR 1/2` is changed

It constantly writes a feedback and status line for values that are needed continuously:
- `&1:2:3:4...`: '&' symbol differentiates line from other command types, ':' used as separator, '\r' used as suffix

It also overwrites configuration values when it starts up, which avoids having all configuration
in the proprietary RoboRun+ XML format. In theory, all configuration could be done through a script.

The idea to constantly publish state and change control modes is universally useful,
but the logic, configuration changes, and constantly published data should be changed to suit your use case.


![RoboRun+ Scripting Tab](/assets/images/interfacing/roborun-script-page.png)

Scripts can be checked for errors by pressing "Build" and uploaded by pressing "To Device".
The "Inspect" button can be used to read values of individual variables *while the script is running on the controller* as a powerful debugging utility.


## ROS Integration

The ROS node acting as the bridge between the RobotEQ controller and the ROS network needs to convert between Serial messages and ROS messages.
ROS provides a guide to define custom message types, which should match the custom status and per-motor feedback messages over serial.
The guide can be found on [docs.ros.org](https://docs.ros.org/en/jazzy/Tutorials/Beginner-Client-Libraries/Custom-ROS2-Interfaces.html), per your ROS version.

Since RobotEQ drivers usually control two motors at a time, they are suited for differential drive.
ROS 2 by convention controls wheeled robots on the `/cmd_vel` topic using the [geometry_msgs/msg/Twist](https://docs.ros.org/en/noetic/api/geometry_msgs/html/msg/Twist.html) message type.
For a differential drive robot, only these two fields of the `Twist` message matter:
- `linear.x`: forward velocity, in the robot frame
- `angular.z`: counterclockwise angular velocity about a vector perpendicular to the ground, in the robot frame

To convert from the Twist to individual motor commmands, the following variables and equations can be used:
- $v$: forward velocity in m/s
- $\omega$: angular velocity in rad/s
- $r$: wheel radius in m
- $d$: width between wheels in m
- $\omega_l, \omega_r$: angular velocity of left and right wheel in rad/s

$$\omega_l = \frac{v - \omega d/2}{r} \quad \omega_r = \frac{v + \omega d/2}{r}$$

The velocity control mode requires scaling the rad/s value into a range -1000 to 1000,
where 1000 is the maximum rpm of the motor per the configuration:
`!G 1/2 setpoint \r` where `setpoint = omega * 30 / pi * 1000 / max_rpm `.

If using a script similar to the example where the motor control mode can be changed with a user variable,
the user variable must be set to velocity mode before each motor command is sent to ensure proper interpretation of the command:
```
!VAR 1/2 0\r
!G 1/2 setpoint\r
```

## Summary

RobotEQ controllers are robust high-power motor drivers that have flexible configuration and a powerful serial interface, making them a strong choice for prototyping.
However, flexibility makes it difficult to decide how exactly to integrate the device within a larger system.
Hopefully this page has clarified how a RobotEQ controller would be integrated with a ROS-based system using serial communication and MicroBasic scripting.