After finishing the installation of the ROS packages on the Jetson RACECAR, we need to program the VESC, an electronic speed controller, for use in the Jetson RACECAR. Looky here:
As discussed in Part 3 – ESC Motor Controller, the TRAXXAS steering servo and the drive motor Electronic Speed Controller (ESC) are controlled by PWM signals sent from an on board radio receiver.
For the Jetson RACECAR, we replace the stock TRAXXAS ESC with a Vedder Electronic Speed Controller (VESC). The major reason for the change is to gain full control at low speeds. The stock ESC puts the minimum vehicle speed at around 6 mph. Another reason is that the VESC is open source, which allows the curious to explore the motor controller implementation.
Architecturally, the VESC has a STM32 ARM Cortex processor. The STM32 runs ChibiOS, a real-time operating system. The default firmware flashed on the VESC-X is ‘Servo-in’, which allows a remote controller to set the motor speed. For the Jetson RACECAR application, the VESC servo port needs to be programmed as ‘Servo-out’, which allows commands to be sent to the robot steering servo.
Fortunately there is a compiled binary of the version of the VESC firmware that includes the Servo-out setting. We can flash the STM32 directly from the Jetson using a program called ‘bldc-tool’. BLDC is an acronym for BrushLess DC motor.
Note: There are also compiled versions of the bldc-tool for x86 machines, if you prefer that route.
Once the bldc-tool loads the servo-out firmware on to the VESC, we then load a configuration file which matches the VESC configuration to control a TRAXXAS Velineon 3500 motor.
Note: The actual VESC firmware is available in binary form in the bldc-tool firmwares directory. If you are interested in building the VESC firmware from source, you can compile it from the bldc firmware source tree on Github.
The VESC is wired to the Jetson using a micro USB to USB-A cable. The USB cable normally communicates motor speed and steering angles between the Jetson and the VESC. The TRAXXAS steering servo is wired to the VESC servo header. In this application, a 90 degree, 3 pin female header helps with the wiring.
The JetsonHacks account on Github contains a repository named installBLDC. To build the bldc-tool:
$ git clone https://github.com/jetsonhacks/installBLDC
$ cd installBLDC
This will build the bldc-tool and download the RACECAR motor configuration files. The RACECAR motor configuration files are downloaded from the Github mit-racecar repository, and are stored in ~/hardware/vesc.
Before starting the bldc-tool, connect the VESC to the vehicle battery. Then:
$ cd ~/bldc-tool
This will bring up the GUI to interact with the VESC. Before flashing the firmware, hit the ‘Connect’ button to communicate with the VESC. The VESC should be at ttyACM0 (more formally, /dev/ttyACM0). The current firmware revision will display in the lower right hand corner on connection.
Use the ‘Firmware’ tab to flash the firmware binary, the configuration can be loaded from the ‘Load XML’ button. Important Note: You must select the correct version of firmware to match the VESC that you are using, otherwise damage and other bad things can happen. In the video, we flashed the firmware ‘VESC_servout.bin’ for version 4.12 of the hardware.
The configuration file is located in ~/hardware/vesc. The configuration file shown in the video is ‘6.141_bldc_VESC_X_hw_30k_erpm.xml’ which is for the VESC-X. If you are using a regular VESC, you will probably want to use the configuration file ‘/6.141_bldc_old_hw_30k_erpm.xml’.
Note: You should use the updated bldc configurations, the configurations lower the min and max erpm values to avoid damaging the VESC when connected to the TRAXXAS motor.
Once the firmware and configuration files are in place, the Jetson RACECAR is ready for teleoperation. You can test a game controller to make sure it is working with the Jetson:
$ sudo jstest /dev/input/js0
The Logitech Gamepad F710 has two modes, controlled by the button labeled ‘mode’. The correct mode for the Jetson RACECAR is the one which the left joystick controls axis 0 and 1, and the right joystick controls axis 2 and 3.
Once the game pad works, you can teleoperate the robot. Make sure that the wheels are clear of any obstructions.
$ cd racercar-ws
$ source devel/setup.bash
$ roslaunch racer teleop.launch
The robot has a deadman switch, the upper button on the left horn of the game pad. Holding the deadman button, you can control the throttle with the left joystick, and the steering with the right joystick.
At this point, we have a working robot platform. We’ll have a couple of more articles on the Jetson RACECAR. As we go forward, we will build the final prototype hardware platform, which we are calling RACECAR/J.