The objective of this tutorial is to build a small demo to provide you with a starting point to use the Otus tracker. We will show you how to recreate the video on the right to control a robot. The drone is controlled using a remote-control and the robot is programmed to automatically follow the drone’s position.
To recreate this setup you do not need any programming. All the source code is provided in this tutorial and you can purchase all the parts to build it. Once you complete this tutorial you will have the tools and knowledge to use the Otus tracker in your own project.
This tutorial will present the Cherokey ROS Project found in the rcbenchmark_ros_pkg/rcb_python. You will need the following things to complete the tutorial:
- ROS installed on your Linux machine
- RCbenchmark Tracking Lab 2017 software on your Windows machine (see how to set it up here and use to it here
- The RCbenchmark client codes (at the bottom of the download page).
- Otus tracker x2 and other hardware components found
- Cherokey 4WD (or your own robot but the code for the controller will have to be modified)
- XBee x2 (see part 4)
- Arduino (see part 5)
The objectives of this tutorial are to:
- Install and configure XBee devices
- Explain the Arduino code found on the robot
- Give a high-level architecture of our ROS package
- Explain the logic behind each ROS node and its purpose
- Show that it works!
We are using ROS but the same principles apply to many other software packages.
Install XBee (1/2)
Digi XBee radio communications modules from Digi International are very handy devices for robotics users. They are an alternative to other types of network communications protocols such as Wi-Fi and Bluetooth. To find more informations on Digi XBee devices take a look here.
Before using the XBee modules, you will need to install the XCTU softwarefound on the Digi website. The XCTU is an free software which allows you to configure the XBee modules.
Install XBee (2/2)
To use and program the XBee module on Linux and ROS, you will have to install some dependencies as shown on the right:
- Install Python Package Manager pip (1/4)
- Install Python tools for working with XBee radios (2/4)
- Upgrade pip Packages (3/4)
- Give current user permissions to access serial ports (4/4)
sudo apt install python-pip pip install xbee --user pip install --upgrade pip sudo adduser @USER dialout
Make sure to re-login to get those permissions.
For this tutorial, you will have to use 2 XBee modules using the 802.15.4 communication protocol. For example, we are using the XBee S1 802.15.4 , but there are many more that can be purchased. The XCTU software is used to setup each XBee module. You won’t need to configure the devices on your own, as we provide you the XBee configuration files as shown on the right:
… > rcbenchmark_ros_pkg > rcb_python > other > Xbee Config
There are 2 files:
- xbee_coordinator.xml = Coordinator XBee = Transmitter
- xbee_endDevice.xml = End Device XBee = Receiver
You will need to load the configuration file to the respective XBee device and press the Write button. The coordinator will be represented in the XCTU with the letter “C”. The end device will be represented in the XCTU with the letter “E”.
To control our robot we use an Arduino Romeo V2board. Two positive points of this board for robotics are its integrated 2 way DC motor driver and its XBee socket. If you plan to buy an Arduino board make sure that it has an XBee socket integrated into the board, otherwise you will need to buy anXBee shield.
In this tutorial, the Arduino is mainly needed to receive and decode the XBee packets and to send the commands to the motors. On the right, you can see a simplified flowchart of thevoid loop() found in the Arduino code. The Arduino source code is provided to you and can be found in:
… > rcbenchmark_ros_pkg > rcb_python > src> Arduino Code
You can download and install the Arduino IDEhere.
High-Level Architecture (ROS)
As you can see on the right, one of the advantages of using ROS is that it gives modularity. The ROS system used for this tutorial is divided into various modules called nodes. A node is a process that performs a computation. For example, the nodes are:
- rcbenchmark_client_udp = “Client Node”
- rcbenchmark_pose_parser = “Pose Parser Node”
- cherokey_autonomous_publisher = “Controller Node”
- cherokey_xbee_XXXXX_XXXXXXXXXXXXX = “Xbee Node”
Here, each node is connected to another node through something called topics. Topics are named buses over which nodes exchange messages. A message is a simple data structure, comprising typed fields. The topics used in our system are:
- /rcbenchmark_pose_ctr1 and /rcbenchmark_pose_ctr2
Nodes communicate with each other by publishing or subscribing to these topics. For example, the “Controller Node”publishesmessages named “cherokey_msg.msg” to the topic “/cherokey_motors”, while the “Xbee Node” subscribes to messages named “cherokey_msg.msg” through the “/cherokey_motors” topic.
All messages used in this tutorial can be found in:
… > rcbenchmark_ros_pkg > rcb_python > msg
Note: In this tutorial, we are referencing the cherokey project written in Python found in the rcbenchmark_ros_pkgworkspace (see right).
Client Node (ROS)
The logic of the client node is shown on the right. The role of the client node is to construct the rcbenchmark_msg based on the UDP packages acquired from the RCbenchmark Tracking Lab 2017 server. The constructed message is published on the /rcbenchmark topic.
The client node can be found at:
… > rcbenchmark_ros_pkg > rcb_python > src> rcbenchmark_client_udp.py
You need to set the UDP_IP variable to the target address.
Pose Parser Node (ROS)
The logic of the pose parser node is shown on the right. The role of the pose parser node is to parse thercbenchmark_msg and obtain thercbenchmark_pose. The newly created message does not contain the linear and angular velocities and accelerations. The constructed message is published on the/rcbenchmark_pose_ctr# topic. Since, we might have multiple controllers streaming data to ROS , we have to publish thercbenchmark_pose on different topics (topic per controller). For example, if we had 2 controllers, we would publish to the /rcbenchmark_pose_ctr1 and /rcbenchmark_pose_ctr2topics.
The pose parser node can be found at:
… > rcbenchmark_ros_pkg > rcb_python > src> rcbenchmark_pose_parser.py
You need to changes the lines in the “if else if” statement so they contain the IDs of your controllers instead of the default ones.
Controller Node (ROS)
The logic of the controller node is shown on the right. The role of the controller node is to compute the values of the motor commands that have to be sent to the robot. The node constructs the cherokey_msg and publishes it on the /cherokey_motorstopic.
The controller presented in this tutorial is a simple algorithm that controls the robot position autonomously. In that way, the robot can follow another robot without direct control. This node can be removed, modified and implemented the way you need it in your application, but it gives an example of what can be accomplished with the Cherokey robot. There are few mathematical computations that have to be performed, but the code is well-commented.
The controller node can be found at:
… > rcbenchmark_ros_pkg > rcb_python > src> cherokey_autonomous_publisher.py
XBee Node (ROS)
The logic of the XBee node is shown on the right. The role of the XBee node is to serialize the cherokey_msg and to send it to the end device XBee located on the robot. An important thing to note is once you connect the XBee device, you have to know on which USB port it has been connected. By default, the code defines the port number to:/dev/ttyUSB0. To verify which port your XBee is using you can run the commands shown on the right.
The XBee node can be found at:
… > rcbenchmark_ros_pkg > rcb_python > src> cherokey_xbee.py
Note: The XBee is usually connected to the /dev/ttyUSBX port, where X is an integer.
Start the server in the RCbenchmark Tracking Lab
Obtain the target IP address. You can use the command /sbin/ifconfig in a terminal on the target to obtain the IP address. Use the default port 5400 and activate the server.
Cherokey Autonomous Launch (ROS)
roslaunch is a tool for easily launching multiple ROS nodes locally and remotely via SSH, as well as setting parameters on the parameter server. Instead of launching a node at the time via the rosrun command, we can group all the node in a .launch file and run them all with a single command. As shown on the right, we are launching 4 nodes at once. The command to execute the cherokey_autonomous.launchvia the shell is shown on the bottom right.
The launch files can be found at:
… > rcbenchmark_ros_pkg > rcb_python > launch
Note: there is no need to run roscore as the .launch file automatically runs it.