In the eleventh part of our Jetson RACECAR build we construct a breadboard to interface the car with the Jetson using an Arduino ROS Node. Then we install the software, and test using a ROS teleoperation node to control the car with a game controller to boot. Looky here:
Background
In our earlier Motor Control and Battery Discussion we had planned on using a Teensy micro controller to interface the Jetson to the steering servo and ESC on the car. After working with the Teensy for a while, I realized that in order to upload a sketch to the Teensy (a sketch is a program that is uploaded and then runs on an Arduino type of processor) an updated version of the Arduino software is needed.
The updated Arduino version is not readily available for the Jetson. An alternative is to run the Arduino software from a PC, such as the host used to flash the Jetson. At the end of the day, it is easier just to replace the Teensy with a regular Arduino and use the Arduino software natively on the Jetson. That means that during development one doesn’t have to bounce back and forth between different development machines.
In the video, an Arduino Nano is used. The Nano was selected because the parts were already on hand, if buying new, an Arduino Micro or clone probably would be the choice.
Note: These are relatively inexpensive, and may use substitute parts. For example, the Arduino Nano uses a CH-340 serial to USB chip instead of a FTDI chip. See the note at the end of the article.
Arduino ROS Node
There are ROS bindings available for the Arduino. Money quote from the ROS wiki:
The Arduino and Arduino IDE are great tools for quickly and easily programming hardware. Using the rosserial_arduino package, you can use ROS directly with the Arduino IDE. rosserial provides a ROS communication protocol that works over your Arduino’s UART. It allows your Arduino to be a full fledged ROS node which can directly publish and subscribe to ROS messages, publish TF transforms, and get the ROS system time.
In our case, we will use the Arduino ROS node to send PWM pulses to the cars steering servo and ESC using the Arduino Servo library.
Construction
Here’s a wiring diagram:
This is a straightforward build. The parts from the video:
- Arduino Nano
- Adafruit Perma-Proto Half-sized Breadboard or in black: Proto Breadboard PCB
- Right Angle Header
- Hook Up Wire
along with a soldering station: Hakko FX888D-23BY Digital Soldering Station
One note, notice that the steering servo receives 6V power from the ESC header, which gets power from the car battery. The Arduino receives 5V power over USB, and sends signals to both the steering servo and ESC. To avoid nasties, an isolation circuit can be added.
Make sure that the car battery is disconnected from the ESC before wiring the Arduino breadboard to the car. This Nano uses a mini USB connector.
Here’s what it looks like after assembly and connected to the car, with the USB from the Nano connected to the Jetson:
Software Installation
The prerequisites for software installation are ROS and the appropriate serial to USB driver for the Arduino. FTDI is usual choice for standard Arduinos, here’s an article for building a kernel and installing ROS on the Jetson TK1.
Once the prerequisites are met, you can go to the installJetsonCar repository on the JetsonHacks Github account. Install the repository on the Jetson, and then run the installation script:
$ git clone https://github.com/jetsonhacks/installJetsonCar.git
$ cd installJetsonCar
$ ./installJetsonCar.sh
Next, go to the Arduino sketchbook and open the jetsoncar sketch. This should be in ~/sketchbook/jetsoncar. The name of the sketch file is jetsoncar.ino Open jetsoncar.ino, setup the Arduino software for flashing by selecting the correct Arduino model and port number, and then upload the sketch to the Arduino.
Operation
In the video, a Nyko game pad controller was used, similar to this one. This controller is from the JetsonBot project. The game pad needs to be paired over Bluetooth with the Jetson. The Jetson in the video has a an Intel 7260 Wireless/BT Network Interface Card (NIC) card. Here’s an article on installing the NIC. You’ll also need antennas.
Then open a separate Terminal window for each command:
$ roscore
$ rosrun rosserial_python serial_node.py /dev/ttyUSB0
$ roslaunch jetsoncar_teleop nyko_teleop.launch
You should be able to examine rostopics being fired by the controller. In order to send cmd_vel topics, the ‘Y’ button on the game controller must be pressed while controlling the left joystick, right trigger, or the right button about the right trigger. The ‘Y’ button is commonly called a deadman switch in this use case.
Note: Usual safety warnings apply, make sure that the car is in stable position and the tires are free from contact with surroundings.
Once you are satisfied everything is working correctly, connect the car battery, and hit the power button on the ESC. The controller should then control the car actions.
Conclusion
As with most of these articles, this is not a step by step operation on how to build a project. It requires a bit of ingenuity on the readers part to gather the parts needed on their own, and as such these articles are more for providing a framework on how to build a project like this. Some of the software will need to take that into account, but there should be enough there to give a good starting point for your own build.
Note on Arduino Nano
As noted earlier an Arduino Nano is used in this project. This will probably be revisited with a new model. In order to get this particular Nano to work, a kernel module is built to support the CH-340 serial to USB chip on the Nano. Most Arduinos use FTDI chips, but these are somewhat more expensive than the CH-340, so some Chinese clones substitute the part. The option in the Linux kernel is:
USB Winchiphead CH341 Single Port Serial Driver
One issue that presented itself is that if the rosserial node was used more than once, the Nano would hang. This appears to be related on this particular chip to the pyserial library. On the Jetson, pyserial is 2.6 which exhibits the issue. Rolling back to version 2.5 seems to fix the problem for this particular board.
To install pyserial 2.5:
sudo apt-get install python-pip -y
pip install –user ‘pyserial==2.5’
For more information see:
https://github.com/ros-drivers/rosserial/issues/219
The post Jetson RACECAR 11 – Arduino ROS Node for Car Control appeared first on JetsonHacks.