Sign Following Robot with ROS in Simulink
This example shows how to use Simulink® to control a simulated robot running on a separate ROS-based simulator.
In this example, you run a model that implements a sign-following algorithm and controls the simulated robot to follow a path based on signs in the environment. The algorithm receives the location information and camera information from the simulated robot, which is running in a separate ROS-based simulator. The algorithm detects the color of the sign and sends the velocity commands to turn the robot based on the color. In this example, the algorithm is designed to turn left when robot encounters a blue sign and turn right when robot encounters a green sign. FInally the robot stops when it encounters a red sign.
To see this example using ROS 2 or MATLAB®, see Sign Following Robot with ROS in MATLAB.
Start Robot Simulator
Start a ROS-based simulator for a differential-drive robot and configure the Simulink® connection with the robot simulator.
To follow along with this example, download a virtual machine using instructions in Get Started with Gazebo and Simulated TurtleBot.
Start the Ubuntu® virtual machine desktop.
In the Ubuntu desktop, click the Gazebo Sign Follower ROS icon to start the Gazebo world built for this example.
Open Model and Configure Simulink
Setup the Simulink ROS preferences to communicate with the robot simulator.
Open the example model.
To configure the network settings for ROS.
From Simulation tab, Prepare group, select ROS Network.
Specify the IP address and port number of the ROS master in Gazebo. For this example, the ROS master in Gazebo is
192.168.203.128in the Hostname/IP address box and
11311in the Port Number box.
Click OK to apply changes and close the dialog.
On each time step, the algorithm detects a sign from the camera feed, decides on turn and drives it forward. The sign detection is done in the Image Proecessing subsystem of the model.
The Sign Tracking Logic subsystem implements a Stateflow® chart that takes in the detected image size and coordinates from Image Processing and provides linear and angular velocity to drive the robot.
open_system('signFollowingRobotROS/Sign Tracking Logic');
Run the Model
Run the model and observe the behavior of the robot in the robot simulator.
The video viewers show the actual camera feed and the detected sign image.
In the simulator, the robot follows the sign and turns based on the color.
The simulation stops automatically once the robot reaches the red sign at the end.