Page cover image

Launching the system

In this page you will be guided through the commands with which you can launch the project.

In this example we have used 8 terminal windows.

First, start the container with the command

cd <location of project>/docker_setup && ./run.sh

Then enter the container in all terminal windows with the command

docker exec -it hil_setup_noetic_foxy /bin/bash

Then, add the following two lines to the /etc/hosts file inside the container and in the robot, if you haven't done so already. You can do this with any text editor of your choice, in this example we've used vim. For this, you need to know the IP address of your computer and the robot.

<IP address ROSbot>       <hostname ROSbot>
<IP address container>    <hostname container>

You should also switch to the root user in the robot.

------- Terminal 1 -------
root@Minty:/ros2_ws# vim /etc/hosts

------- Terminal 6 -------
root@Minty:/ros2_ws# ssh husarion@192.168.0.101
husarion@husarion:~$ sudo su

------- Terminal 7 -------
root@Minty:/ros2_ws# ssh husarion@192.168.0.101
husarion@husarion:~$ sudo su
root@husarion:/home/husarion# vim /etc/hosts

As part of the setup, you should define the topics that you would like to bridge with the ros2/ros1 bridge. In this example we create a file and put the following content into it. You can do so with your preferred text editor.

------- Terminal 8 -------
root@Minty:/ros2_ws# vim bridge.yaml
bridge.yaml
topics:  
  -
    topic: /odom  # Topic name on both ROS 1 and ROS 2
    type: nav_msgs/msg/Odometry  # Type of topic to bridge
    queue_size: 1  # Queue size
  -
    topic: /imu  # Topic name on both ROS 1 and ROS 2
    type: sensor_msgs/msg/Imu  # Type of topic to bridge
    queue_size: 1  # Queue size
  -
    topic: /cmd_vel  # Topic name on both ROS 1 and ROS 2
    type: geometry_msgs/msg/Twist  # Type of topic to bridge
    queue_size: 1  # Queue size
   -
    topic: /clock  # Topic name on both ROS 1 and ROS 2
    type: rosgraph_msgs/msg/Clock  # Type of topic to bridge
    queue_size: 1  # Queue size
   -
    topic: /tf  # Topic name on both ROS 1 and ROS 2
    type: tf2_msgs/msg/TFMessage # Type of topic to bridge
    queue_size: 1  # Queue size
   -
    topic: /joint_states  # Topic name on both ROS 1 and ROS 2
    type: sensor_msgs/msg/JointState  # Type of topic to bridge
    queue_size: 1  # Queue size

Now, the appropriate environment variables need to be exported in the terminals that use ROS1. This means the two terminals in which we are connected to the robot, and the terminal where the ros2/ros1 bridge will be started.

------- Terminal 6 -------
root@husarion:/home/husarion# export ROS_MASTER_URI=http://husarion:46335/
root@husarion:/home/husarion# export ROS_HOSTNAME=husarion
root@husarion:/home/husarion# export ROS_IP=192.168.0.101

------- Terminal 7 -------
root@husarion:/home/husarion# export ROS_MASTER_URI=http://husarion:46335/
root@husarion:/home/husarion# export ROS_HOSTNAME=husarion
root@husarion:/home/husarion# export ROS_IP=192.168.0.101

------- Terminal 8 -------
root@Minty:/ros2_ws# export ROS_MASTER_URI=http://husarion:46335/
root@Minty:/ros2_ws# export ROS_HOSTNAME=laptop
root@Minty:/ros2_ws# export ROS_IP=192.168.0.100

Afterwards, source the ROS2 and the ROS1 workspaces. In the first 5 terminals, this will be the /ros2_pkgs_ws. In the 6th and 7th terminals this is the /home/husarion/husarion_ws_two. In the last one, this is the /ros2_ws. Sourcing the setup sources both packages from this workspace and its underlay as well. For more information, visit: https://docs.ros.org/en/foxy/Tutorials/Beginner-Client-Libraries/Creating-A-Workspace/Creating-A-Workspace.html#source-the-overlay.

------- Terminal 1 -------
root@Minty:/ros2_ws# cd /ros2_pkgs_ws
root@Minty:/ros2_pkgs_ws# source install/setup.bash

------- Terminal 2 -------
root@Minty:/ros2_ws# cd /ros2_pkgs_ws
root@Minty:/ros2_pkgs_ws# source install/setup.bash

------- Terminal 3 -------
root@Minty:/ros2_ws# cd /ros2_pkgs_ws
root@Minty:/ros2_pkgs_ws# source install/setup.bash

------- Terminal 4 -------
root@Minty:/ros2_ws# cd /ros2_pkgs_ws
root@Minty:/ros2_pkgs_ws# source install/setup.bash

------- Terminal 5 -------
root@Minty:/ros2_ws# cd /ros2_pkgs_ws
root@Minty:/ros2_pkgs_ws# source install/setup.bash

------- Terminal 7 -------
root@husarion:/home/husarion# cd husarion_ws_two/
root@husarion:/home/husarion/husarion_ws_two# source devel/setup.bash

------- Terminal 8 -------
root@Minty:/ros2_ws# source install/setup.bash

Finally, start the project. First, start the ROS master on the robot. Then, start the ros2/ros1 bridge. Launch the gazebo world, spawn the robot and start the position update script. Finally, start the rosbot drivers launchfile on the robot, launch the navigation stack in the container and the nav2 bringup. In this step the order of the commands matter. Carry out the commands in the order you see them listed below.

------- Terminal 6 -------
root@husarion:/home/husarion# roscore -p 46335

------- Terminal 8 -------
root@Minty:/ros2_ws# rosparam load ./bridge.yaml
root@Minty:/ros2_ws# ros2 run ros1_bridge parameter_bridge

------- Terminal 2 -------
root@Minty:/ros2_pkgs_ws# ros2 launch simple_obstacle_world launch_simple_obstacle_world.launch.py

------- Terminal 3 -------
root@Minty:/ros2_pkgs_ws# ros2 launch husarion_rosbot launch_husarion_rosbot.launch.py
root@Minty:/ros2_pkgs_ws# ros2 run simple_obstacle_world update_model_position

------- Terminal 7 -------
root@husarion:/home/husarion/husarion_ws_two# roslaunch husarion_ros rosbot_drivers.launch

------- Terminal 4 -------
root@Minty:/ros2_pkgs_ws# ros2 launch navigation_stack launch_navigation_stack.launch.py

------- Terminal 1 -------
root@Minty:/ros2_pkgs_ws# ros2 run teleop_twist_keyboard teleop_twist_keyboard

------- Terminal 5 -------
root@Minty:/ros2_pkgs_ws# ros2 launch nav2_bringup navigation_launch.py params_file:=/ros2_pkgs_ws/src/navigation_stack/config/nav2_params.yaml

Finally, set up RViz according to your preferences.

In the video below you can see the steps carried out and a movement command completed by the ROSbot.

The following section you can see all the necessary commands grouped by terminal windows (starting from the state when the user is already inside the container).

root@Minty - inside container running on computer
root@husarion - inside husarion rosbot, connected from container on computer via ssh


------- Terminal 1 -------
root@Minty:/ros2_ws# cd /ros2_pkgs_ws
root@Minty:/ros2_pkgs_ws# source install/setup.bash
root@Minty:/ros2_pkgs_ws# export ROS_MASTER_URI=http://husarion:46335/
root@Minty:/ros2_pkgs_ws# export ROS_HOSTNAME=laptop
root@Minty:/ros2_pkgs_ws# export ROS_IP=192.168.0.100
root@Minty:/ros2_pkgs_ws# ros2 run teleop_twist_keyboard teleop_twist_keyboard


------- Terminal 2 -------
root@Minty:/ros2_ws# cd /ros2_pkgs_ws
root@Minty:/ros2_pkgs_ws# source install/setup.bash
root@Minty:/ros2_pkgs_ws# ros2 launch simple_obstacle_world launch_simple_obstacle_world.launch.py


------- Terminal 3 -------
root@Minty:/ros2_ws# cd /ros2_pkgs_ws
root@Minty:/ros2_pkgs_ws# source install/setup.bash
root@Minty:/ros2_pkgs_ws# ros2 launch husarion_rosbot launch_husarion_rosbot.launch.py
root@Minty:/ros2_pkgs_ws# ros2 run simple_obstacle_world update_model_position


------- Terminal 4 -------
root@Minty:/ros2_ws# cd /ros2_pkgs_ws
root@Minty:/ros2_pkgs_ws# source install/setup.bash
root@Minty:/ros2_pkgs_ws# ros2 launch navigation_stack launch_navigation_stack.launch.py


------- Terminal 5 -------
root@Minty:/ros2_ws# cd /ros2_pkgs_ws
root@Minty:/ros2_pkgs_ws# source install/setup.bash
root@Minty:/ros2_pkgs_ws# ros2 launch nav2_bringup navigation_launch.py params_file:=/ros2_pkgs_ws/src/navigation_stack/config/nav2_params.yaml


------- Terminal 6 -------
root@Minty:/ros2_ws# ssh husarion@192.168.0.101
husarion@husarion:~$ sudo su
root@husarion:/home/husarion# export ROS_MASTER_URI=http://husarion:46335/
root@husarion:/home/husarion# export ROS_HOSTNAME=husarion
root@husarion:/home/husarion# export ROS_IP=192.168.0.101
root@husarion:/home/husarion# source /opt/ros/noetic/setup.bash
root@husarion:/home/husarion# roscore -p 46335


------- Terminal 7 -------
root@Minty:/ros2_ws# ssh husarion@192.168.0.101
husarion@husarion:~$ sudo su
root@husarion:/home/husarion# export ROS_MASTER_URI=http://husarion:46335/
root@husarion:/home/husarion# export ROS_HOSTNAME=husarion
root@husarion:/home/husarion# export ROS_IP=192.168.0.101
root@husarion:/home/husarion# source /opt/ros/noetic/setup.bash
root@husarion:/home/husarion# cd husarion_ws_two/
root@husarion:/home/husarion/husarion_ws_two# source devel/setup.bash
root@husarion:/home/husarion/husarion_ws_two# roslaunch husarion_ros rosbot_drivers.launch


------- Terminal 8 -------
root@Minty:/ros2_ws# source install/setup.bash
root@Minty:/ros2_ws# export ROS_MASTER_URI=http://husarion:46335/
root@Minty:/ros2_ws# export ROS_HOSTNAME=laptop
root@Minty:/ros2_ws# export ROS_IP=192.168.0.100
root@Minty:/ros2_ws# vim bridge.yaml
root@Minty:/ros2_ws# rosparam load ./bridge.yaml
root@Minty:/ros2_ws# ros2 run ros1_bridge parameter_bridge

This ends the description of this project. We hope you had fun and learned useful information that helps you on your journey with your own work!

Last updated