-
Notifications
You must be signed in to change notification settings - Fork 13
ROS Simulation
This page outlines the PiCar project as it relates to ROS, the Robot Operating System. Included are descriptions of the car model and its design; some of the important ROS tools that were used within the project; summaries of the Python scripts that are used within the simulations; and suggestions for ways to expand the existing code for better testing of the PiCar's autonomous driving.
In the ROS filesystem, packages are the main unit of organizing software.
The PiCar project is composed of two packages. The Picar_Base package deals primarily with the physical RC-car and the real-world control of that car. The Car_Model package is centered on the ROS simulation aspects of the project.
Nodes are processes that perform various computations within a given ROS package.
Nodes are comparable to executable files within a given package, and they are able to communicate with each other.
Most of the ROS-based Python executables in the PiCar repository use nodes to send data to RViz or Gazebo.
Messages are the principal means by which ROS Nodes communicate with each other.
They are simple data structures comprised of various typed fields.
One message type that is used throughout this project is the Twist message. A Twist message has linear and angular x, y, and z components that are used to represent velocity. Another example is an Odometry message, which is used to represent a position and velocity vector within free space.
Topics are the main transportation channels in which ROS Messages are published.
Nodes can subscribe to or publish to a particular topic, allowing them to receive or send messages, respectively.
Nodes are also able to interact with multiple topics at the same time.
$ roscore
activates a ROS master node (This is necessary for the teleop_twist_keyboard to run but not for RViz or Gazebo.)
$ roscd _packageName_
navigate into the packageName directory
$ rospack find _packageName_
find a ROS package within the workspace
$ rosnode
displays a list of commands for printing information about ROS Nodes
$ rostopic
displays a list of commands for printing information about ROS Topics
$ rosrun rqt_graph rqt_graph
a convenient GUI tool for visualizing the active ROS nodes, publishers and subscribers

Two car models can be found within the URDF Folder of the car_model package. carModel.xacro is the version that is used in the RViz-based Python scripts described below, and gazeboCar.xacro was created for Gazebo simulations.
The car models' designs are fairly straightforward, with the black box at the front of the car representing a camera that publishes images from within Gazebo. Both car models can be moved using Twist messages.
Running the teleop_twist_keyboard file allows the user to send Twist messages from the keyboard. These messages will then be received by the Twist_Driver file, which will use the messages to manually control the car model in RViz.
$ roslaunch car_model twist_driver.launch
$ rosrun teleop_twist_keyboard teleop_twist_keyboard.py
Runing these two commands from separate terminal windows will allow the user to steer the car model from within RViz.



This is the graphical representation of TwistDriver running with RViz. The "teleop_twist_keyboard" node is publishing messages on the "cmd_vel" topic to the "twist_driver" node. This node is, in turn, publishing messages on the "joint states" and "odom" topics that the "robot_state" node uses for the display.

$ roslaunch car_model video_driver.launch
The VideoDriver code is based on the Model Training portion of the PiCar project. Using a pre-recorded video of the RC car driving autonomously, the VideoDriver will record the DeepTesla model's angle predictions. VideoDriver will then include those angles within Twist messages so that the RViz car will mimic the real car's motion. VideoDriver will also publish the video frames as sensor messages for easy viewing within RViz.
The CarPublisher program acts like the TwistDriver and will receive Twist messages and use them to publish information to alter the RViz car model. The main difference is that TwistDriver will continuously send information to RViz while CarPublisher will only send information when a new Twist message is received.

In this example, the VideoDriver will publish twist messages on the "SelfDriver/cmd_vel" topic and images on the "sensor_msgs/Image" topic. CarPublisher will then interact with the robot_state node for display.

Gazebo is a robot simulation program that can be used to design robots along with complex environments in which the robots will be tested. The PiCar model can be controlled within the Gazebo world by using the teleop_twist_keyboard program or a custom program that publishes messages to the "cmd_vel" topic.
gazeboCar.xacro contains a Gazebo plugin that will take images of the area directly in front of the car. One can view these objects by opening RViz using the following commands:
$ roscd car_model
$ rosrun rviz rviz -d rviz/gazebo.rviz
The images below depict a Gazebo environment with random geometric objects placed around the car and the RViz window displaying the camera images.


-
Ideally, as part of the autonomous driving functionality, the ROS car model should be able to detect a starting point and a goal point within its simulation environment and be able to execute a plan and navigate between the two points. It could also be useful to design a map within the simulation in order to see how the path planning algorithms respond when there are obstacles in the way.
-
Publishing more accurate sensor information from the PiCar's camera can help the system better recognize its position in relation to nearby objects and avoid crashing.
-
Using the ROS Navigation Stack, one can configure a robot to control itself within a simulation environment. The provided link defines all of the various components that are required to build a proper navigation system for a given robot.
An incomplete StreamDriver Python file exists that has similar functionality to VideoDriver. Using SSH, access the RC car's Raspberry Pi, and turn on the car's web streaming and manual control.
$ roslaunch picar_base picar_base.launch
Then, from the computer, open the StreamDriver in RViz.
$ roslaunch car_model stream_driver.launch
Rviz will display a live feed from the PiCar's camera. This program can be used to test the autonomous driving code. As the PiCar is steered manually, one can look at RViz and determine how well the program is able to detect and mimic the physical motion based only on the camera feed.
(Setting Up the PiCar Repository on Your Computer)