# Jetson RACECAR Part 3 – ESC Motor Controller

In the third part of our Jetson RACECAR build series, we are working through controlling the ESC motor controller. Looky here:

## Background

In an R/C car such as the TRAXXAS Rally that we’re using in this project, servo motors and the drive motor Electronic Speed Ccontroller (ESC) are controlled by PWM pulses sent from an on board receiver. A remote radio transmitter controlled by a user is the source for the receiver signals. PWM stands for Pulse-Width Modulation, a modulation technique used to encode a message into a pulsing signal. In this particular application, you can think of PWM as a technique for getting analog results by digital means.

In order to control a servo or ESC, a PWM signal is sent to the device as repeating pulses of variable width. The devices are attached via a standard three wire connection, two wires for a DC power supply and one for a control, which carries the pulses. The pulses are defined by the frame size, which is the frequency of the pulse and the PWM duty cycle which is the ON vs. OFF time of the signal. Here’s what a single signal frame looks like:

For a servo or ESC, the device expects to see a frame every 20 milliseconds, but this can vary from device to device. For this discussion, we’ll stick with 50Hz (50 cycles per second) which is a 20ms frame (1 second = 1000 milliseconds then divide by 50 ). The device expects a pulse between 1.0 and 2.0 ms. For a servo the pulse width represents the position of the servo motor, 1.0ms represents -90 degrees, 1.5ms represents 0 degrees (center), and 2.0 ms represents +90 degrees. For an ESC the pulse width represents throttle position, 1.0 ms represents full reverse (or the lowest throttle setting, depending on the interpretation of the ESC), 1.5ms is neutral, and 2.0 represents full throttle.

Note: When using a SoC like the Jetson, interfacing with a dedicated PWM driver or other micro-controller hardware simplifies generating correctly timed PWM frames and pulses. In part this is because most SoCs do not run real time operating systems nor generate suitable clocks for the task. The result is that the timing signals can drift without dedicated hardware.

### PWM Driver

In the video, a PCA9685 PWM/Servo Driver is connected to the TRAXXAS Rally ESC to control the car motor. The Traxxas ESC, a Velineon VXL-3s, is a brushless motor controller which creates tri-phase AC power from the onboard DC battery. The ESC contains a micro controller which interprets the supplied PWM signal and appropriately controls the car motor using built-in firmware. The ESC has three performance modes, regular, race, and training. For the purposes of the Jetson RACECAR, the ESC is placed into training mode, which limits the motor power to 50%.

The PCA9685 is a 12 bit device, which means basically that you can think of each frame as being split into 2^12 slots (4096). To calculate throttle pulses:

1.0ms/20ms*4096 = 204 full reverse
1.5ms/20ms*4096 = 307 neutral
2.0ms/20ms*4096 = 409 full forward

## Wiring

The PCA9685 is connected to the Jetson Development Kit over I2C. Here’s a previous article on how to do this, look in the Wiring section. The steering servo should be wired into the first PWM slot on the PCA9685.

Before wiring, make sure the Jetson is powered off. In order to connect the ESC to the PCA9685, remove the ESC connector from the receiver and using 2.54mm m/f jumpers connect the connector black wire (GND) to the GND of the second PWM slot of the PCA9685. Connect the white wire (signal) to the SIGNAL of the second slot of the PCA9685. The red wire is not connected. Note: The red wire supplies power (6V) to the receiver. Because the PCA9685 is already powered by an auxiliary power source, the additional power wire should not be used. Looky here:

## Software

Once the board is wired up, power up the Jetson.
In order to be able inspect the PCA9685, you may find it useful to install the i2c tools:

$sudo apt-get install libi2c-dev i2c-tools After installation, in a Terminal execute:$ sudo i2cdetect -y -r 1

You should see an entry of 0x40, which is the default address of the PCA9685. If you have soldered the address pins on the PCA9685 (as is the case if you are using multiple boards chained together) you should see the appropriate address.

In order to experiment with controlling the steering and ESC of the TRAXXAS Rally car, a couple of small applications were written for exploration. The source for the apps are in the JetsonHacks jetsonRACECAR repository on Github. In a Terminal:

$git clone https://github.com/jetsonhacks/jetsonRACECAR.git$ cd jetsonRACECAR/research

You will see two folders, setThrottle and throttleControl. You can open the enclosed .pro files in each folder with Qt Creator and build the applications. Here’s an article on how to install Qt Creator on a Jetson.

## ESC Motor Control Calibration

The ESC comes calibrated to work with the supplied radio transmitter. In the case where we substitute our own signals to the ESC, we need to calibrate with the new signals. In order to do this, open a Terminal and navigate to the folder where the ‘setThrottle’ application was built and:

$sudo ./setThrottle This should send out a ‘Neutral Throttle’ signal over PWM on startup. Hookup the battery in the car, and go through the ‘Calibrating the Speed Control’ instructions from the TRAXXAS Rally Quick Start Guide, using the on screen ‘Full Reverse’, ‘Neutral’, and ‘Full Throttle’ buttons in place of the transmitter triggers. Once the speed controller has been calibrated, turn the power off on the car. In a Terminal, switch to the build directory for the ‘throttleControl’ application and:$ sudo ./throttleControl

Running the program outputs a ‘Neutral’ PWM signal.
You are then ready to start the car and place it into ‘Training’ mode. Hold down the ESC EZ-Set button until the LED blinks red three times, then release. The LED will then turn red, indicating that the car is armed and ready.

There is an item selector which chooses either the ESC or the Steering Servo to control. By default, it is for the ESC. Make sure that the wheels are not touching anything and increment the value until the motor starts. The car in the video starts forward motor at a control value of 317. There is a ‘Neutral’ button in the app that will set the control value to 307. You can experiment with the values to see how the motor is controlled, and also experiment with the servo controller to find out the optimal maximum, minimum, and center values.

## Conclusion

Two of the bigger challenges on this project, and probably the most unknown getting started, are how to control the steering and the car motor. As it turns out, the mechanics to accomplish this were relatively simple with the addition of a PWM driver. One concern at this point is being able to control the RACECAR at slower speeds, as even the slowest setting of the ESC appears to be quite fast. There are a couple of ways to think about this issue, though it pains me to think about actually slowing down a race car in the first place. The next challenge is to get the Jetson on board the car and powered.

1. Looks good. Been showing these to my r/c buddies.

2. Looks Great!! Really looking forward to your integration with ROS

• Me too! There’s a little lull here while I’m waiting for more parts, but they’re starting to trickle in and there should be some good progress on the car soon.

3. In one of the videos, you mentioned that original ESC can be replaced by an open source controller. Can you please provide the name of such an open source controller or its parameters? Thank you in advance!

• From my understanding there are several different ones. The VESC by Benjamin Vedder is one of the more popular ones.

4. I was looking for a cheaper car to use for this project, I’m only concerned about the kind of speed control used on the traxxas, I’m planning to use one of those [1] for which I found this [2] instructions for the spedd control calibration (page 6) … do you think I’ll be fine?
Thanks a lot, I found each of your video .. just Amazing!

• I’m guessing the answer is yes, any speed controller will work just fine .. but looking more carefully at the video, seems to me that the original speed control will not allow for delicate monovring in “difficult” environment (due to its aggressive start). An online search for the VESC by B. Vedder. shows an upcoming production in series of the controller (not cheap ~90 US$) .. but I guess is worth the$. (I wish I wans’t so bad in soldering microelectronic components)

5. Hi,

I’m a graduate student trying to build the MIT RACECAR platform for a research project. I’m unable to calibrate the stock ESC on the Traxxas using the PCA9865.

The calibration sequence goes well until the last step where it can’t be set back to neutral and the LED on the ESC keeps blinking. I’ve tried replacing the ESC, tweaking the values in the calibration tool source code and writing my own calibration code. It’s always the same problem. I’ve contacted Traxxas and they don’t know either.

This works with a smaller Traxxas model with a brushed DC motor and a different ESC but not on the Traxxas Rally. Help?

Thank you.

PS : Also e-mailed you. Ignore this if you’ve already gone through that.

• Thinking about it for a while, I didn’t come up with any good answers. I’m sure you’ve looked at it more than I have at this point.

The things I would check:

pca9685->setPWMFrequency(50) ;

which makes sure that the numbers are in the correct range.

Make sure the wiring is correct, and that the ESC and Steering are connected correctly.

You should be able to still get the motor to work, it’s just not calibrated.

• Hello Sai. I am also a graduate student working on building the MIT RACECAR for a research project. It would be nice if we could keep in touch and help each other out. My email is gotenkscha a-t gmail.com
Thanks!

6. Hello i make a autonomous car project using your video.
And i did motor control, steering like your comment.
Steering is running but motor is not moving.
So i think more power is needed.
You said pca9685 need more power so i add 6V but after that traxxas rally’s ESC is not run (no light).
Remove adding volt, ESC is running(but can’t motor control).
I don’t know what is wrong. Can u help me?

7. Hello.
I have a autonomous car project.
Following your video, i control steering but i can’t motor control.
so i think it need more power you comment.
And then i add 6V battery.

After adding battery, connecting traxxas rally with pca9685, car’s ESC is
not running(no light). so i remove adding battery. it running.

Why i can’t control motor? Why after adding battery rc car is not running?