---
# System prepended metadata

title: Run ROS-based GazeboSim of A Simple 3-link Robot (Ubuntu 16.04 and ROS Kinetic)

---

# Run ROS-based GazeboSim of A Simple 3-link Robot (Ubuntu 16.04 and ROS Kinetic)
This was based on gazebo_ros_demos created by Davet Coleman.

Refer to the following links for more detail.
RRBot Git: https://github.com/ros-simulation/gazebo_ros_demos
Tutorial: Using a URDF in Gazebo: http://gazebosim.org/tutorials/?tut=ros_urdf
Tutorial: Using Gazebo plugins with ROS: http://gazebosim.org/tutorials?tut=ros_gzplugins
Tutorial: ROS Control: http://gazebosim.org/tutorials/?tut=ros_control
ROS URDF XML: http://wiki.ros.org/urdf/XML


## Download and build RRBot
Create a catkin workspace
```
 mkdir catkin_ws
 cd catkin_ws
 mkdir build
 mkdir devel
 mkdir src
 catkin_make
 ```


Clone RRBot into src directory
```
 cd src
 git clone https://github.com/ros-simulation/gazebo_ros_demos.git
 ```
A direcotry named gazebo_ros_demo would be created.

Goto the catkin workspace and build the workspace
```
 cd ..
 catkin_make
```
At least 3 packages should be built:
* rrbot_description
* rbot_gazebo
* rrbot_Control

\
To verify RRBot is built properly, setup environment and launch RRBot with Rviz
```
 source devel/setup.bash
 roslaunch rrbot_description rrbot_rviz.launch
```
An Rviz window with an RRBot will appear.

To verify RRBot in gazebo, launch RRBot gazebo package with a launch file.
```
  roslaunch rrbot_gazebo rrbot_world.launch
```

A Gazebo window with an RRBot will appear.



## Use a ROS controller to control the RRBot in Gazebo ##

### Start RRBot Simulation ###

Open a terminal and launch RRBot in Gazebo.
```
  roslaunch rrbot_gazebo rrbot_world.launch
```

\
### Start ROS Controller ###
Open another terminal and launch RRBot ROS Controller.
```
  roslaunch rrbot_control rrbot_control.launch
```
\
**Could not find controller_manager ROS intefrace warning**
If a warning saying:
> [WARN] [WallTime: 1455881551.416911] [109.233000] Controller Spawner couldn't find the expected controller_manager ROS interface.

Then this could indicate that you did not have *gazebo_ros_control* package installed.

Please update and install the following packages and launch the ROS controller again.
```
sudo apt-get update
sudo apt-get install ros-kinetic-gazebo-ros-pkgs
sudo apt-get install ros-kinetic-gazebo-ros-control
sudo apt-get install ros-kinetic-gazebo-ros-controllers
```
\
Refer to the following links for reference:
* http://answers.gazebosim.org/question/12673/problem-with-start-controller-with-roslaunch-controller-spawner-couldnt-find-the-expected-controller_manager-ros-interface/
* http://gazebosim.org/tutorials?tut=ros_installing&cat=connect_ros


**Could not load controller error**
If a error saying when launching Gazebo:
>[ERROR] [1562408645.423077731, 19.324000000]: Could not load controller 'joint_state_controller' because controller type 'joint_state_controller/JointStateController' does not exist.
>[ERROR] [1562408645.423112694, 19.324000000]: Use 'rosservice call controller_manager/list_controller_types' to get the available types
[ERROR] [1562408646.426952533, 20.328000000]: Could not load controller 'joint1_position_controller' because controller type 'effort_controllers/JointPositionController' does not exist.
[ERROR] [1562408646.426989939, 20.328000000]: Use 'rosservice call controller_manager/list_controller_types' to get the available types
[ERROR] [1562408647.430684106, 21.331000000]: Could not load controller 'joint2_position_controller' because controller type 'effort_controllers/JointPositionController' does not exist.
[ERROR] [1562408647.430728600, 21.331000000]: Use 'rosservice call controller_manager/list_controller_types' to get the available types


or if a error saying when launch rrbot_control
>[INFO] [1562408645.418500, 0.000000]: Loading controller: joint_state_controller
[ERROR] [1562408646.424368, 20.326000]: Failed to load joint_state_controller
[INFO] [1562408646.424839, 20.326000]: Loading controller: joint1_position_controller
[ERROR] [1562408647.427938, 21.328000]: Failed to load joint1_position_controller
[INFO] [1562408647.428341, 21.329000]: Loading controller: joint2_position_controller
[ERROR] [1562408648.432052, 22.331000]: Failed to load joint2_position_controller


\
Then this could indicate that you did not have *ros-kinetic-joint-state-controller* package installed.

Please update and install the following packages and launch the ROS controller again.
```
sudo apt-get update
sudo apt-get install ros-kinetic-joint-state-controller
sudo apt-get install ros-kinetic-effort-controllers
sudo apt-get install ros-kinetic-position-controllers
```
\
Refer to the following links for reference:
* https://github.com/qboticslabs/mastering_ros/issues/7


\
**Could not find controller_manager ROS intefrace warning**
When starting rrbot_gazebo, if an error saying:
> [ERROR] [1527494740.144219702, 307.635000000]: GazeboRosControlPlugin missing <legacyModeNS> while using DefaultRobotHWSim, defaults to true.
This setting assumes you have an old package with an old implementation of DefaultRobotHWSim, where the robotNamespace is disregarded and absolute paths are used instead.
If you do not want to fix this issue in an old package just set <legacyModeNS> to true.

Then this could indicate that you are using an old version of DefaultRobotHWSim.

To fix this, add 
``` 
<legacyModeNS>true</legacyModeNS>
```
in *rrbotdescription/urdf/rrbot.gazebo*
The content of *rrbot.gazebo* is shown below:
```
<?xml version="1.0"?>
<robot>

  <!-- ros_control plugin -->
  <gazebo>
    <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
      <robotNamespace>/rrbot</robotNamespace>
      <robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType>
      <legacyModeNS>true</legacyModeNS>
    </plugin>
  </gazebo>
...
```

Refer to the following links for reference:
* https://answers.ros.org/question/292444/gazebo_ros_control-plugin-gazeboroscontrolplugin-missing-legacymodens-defaultrobothwsim/




### Send Control Commands Using Rostopic ###
Open another terminal and publish position control commands to the controller's topic.
```
rostopic pub -1 /rrbot/joint1_position_controller/command std_msgs/Float64 "data: 1.5"
rostopic pub -1 /rrbot/joint2_position_controller/command std_msgs/Float64 "data: 1.0"
```
The RRBot in Gazebo should act accordingly.



---

To control the RRBot, you'll need to create and ROS publisher that sends commands to the ROS controller.

