Sign inSign up

omarbarakota/ros2_gp

By omarbarakota

•Updated almost 2 years ago

This is a custom image from ros2 core humble used in our graduation project

Image
Internet of things
Operating systems
0

185

omarbarakota/ros2_gp repository overview

⁠ROS2 Using Docker Documentation

⁠Table Of Content

1- Intallation⁠

2- How Does It Work⁠

3- Additional Notes⁠

4- Small Demos⁠

⁠1- Installation

Installation will be devided into two parts Docker Installation and ROS2 Humble Installation

⁠1-1- Docker Installation

To install Docker on your machine

 sudo apt-get update
 sudo apt install docker.io docker-compose docker-buildx

To run Docker without using sudo, you need to add your user to the docker group, which allows managing Docker as a non-root user. Here’s how you can do it:

  1. Create the docker group (if it doesn't exist):

    sudo groupadd docker
    
  2. Add your user to the docker group: Replace $(whoami) with your username, or just use the command as is to add the current user.

    sudo usermod -aG docker $(whoami)
    
  3. Apply the new group membership: Either log out and log back in, or run the following command to apply the group membership without logging out:

    newgrp docker
    
  4. Test if you can run Docker without sudo: Try running a Docker command, like:

    docker run hello-world
    

If everything is set up correctly, Docker will run without needing sudo.

⁠1-2- ROS2 Installation

Install the following image that has ROS2 Humble on an Ubuntu 22.04LTS machine

note that this is ros core if you want the full desktop Here⁠

docker  pull ros:humble-ros-core

Congratulations now you have ROS2 Image ready on your machine

⁠2- How Does it work ?

⁠2-1- To initialize a container

Here you run any container for the first time

docker run -it --rm \
    --net=host \
    --env="DISPLAY" \
    --env="QT_X11_NO_MITSHM=1" \
    --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
    ""ImageName:TagName""

Note that if you want to run the offical image

  • ImageName:TagName -> ros:humble-ros-core

if you want to run your own customized image for example ros2_test:latest

  • ImageName:TagName -> ros2_test:latest
⁠2-2- Openning new terminal in the same container
⁠1. Get the Container ID or Name

First, you'll need to know the container ID or name

  • to know all container's ID
docker ps -a
  • to know only the running container's ID
docker ps
⁠2. Use docker exec to Open a New Terminal

Once you have the container ID or name, use the docker exec command to open a new terminal session inside the running container:

docker exec -it <container_name_or_id> /bin/bash

For example, if the container is named ros2_test_container, you would run:

docker exec -it ros2_test_container /bin/bash

This will open a new terminal session inside the running container, and you can interact with it just like you did when you first started the container.

⁠2-3- To commit Changes in Docker
⁠Docker Commit

After each new (installation, update, upgrade) or any modification in the container's content its highly recommended to commit those changes to avoid repeating it again in the future

  • to know all container's ID
docker ps -a
  • to know only the running container's ID
docker ps
  • to make a commit
docker commit "Container's ID or name" "NewImageName:Tagname"

⁠3-Additional Notes

⁠Notes:
  • -it: Same as when you initially ran the container; -i for interactive mode and -t for allocating a terminal.
  • /bin/bash: Specifies the shell to run (you can also use /bin/sh if bash is not available).

Now, you should have a new terminal session in the same container.

⁠Running two containers

Use Docker Compose file

⁠4- Small Demo

On our raspberrypi you can find docker installed and ros2_test:latest has:

  • ROS2 Humble Core
  • TurtleSim
  • Talker and listener demo tests
⁠Lets run it
  1. You need to configure your raspi on your network Wherther by doing it manually using mouse keyboard and screen or modifying network-config file by changing the SSID to your Wifi name and password to you WiFi password

  2. Then you can SSH on the raspi using putty, by writing pi.local into the host IP Address

  3. write the following command raspi-config select the Interface option and enable VNC

  4. Open VNC view and enter pi.local to connet to your raspi

It's recommended to run terminator for better terminal layout

  1. On terminal 1 run this command to start and run the custom image that we'll use:
docker run -it --rm \
    --net=host \
    --env="DISPLAY" \
    --env="QT_X11_NO_MITSHM=1" \
    --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
    --name=ros2_main\
    ros2_test:latest
  1. open a new terminal terminal 2 On Host machine (Raspi) and run this command to ensure that the container can access your host's X11 display server for OpenGL rendering
xhost +local:docker
  1. now open a new terminal terminal 3 and know the current running containers and copy the ID
docker ps 
  1. then paste the ID and run the following command to open a new terminal terminal 3 on the same container
docker exec -it "Container's ID" /bin/bash

Now terminal 1 and terminal 3 are on the same container try those demos

  1. Turtle sim demo

Run each command on a seperate terminal (terminal 1 or 3)

ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key

Congratulation now you can control turtle sim through your keyboard!

  1. Talker and listener demos

Run each command on a seperate terminal (terminal 1 or 3)

ros2 run demo_nodes_cpp talker
ros2 run demo_nodes_cpp talker

Congratulation now you've made 2 nodes communicate in that docker container!

Tag summary

Content type

Image

Digest

sha256:a451428c1…

Size

297 MB

Last updated

almost 2 years ago

docker pull omarbarakota/ros2_gp