7、Install ROS1/ROS2 in docker container

7.1 Install the corresponding images mirror (ROS environment)

(Use our latest image to skip the 7.1 installation image part!!!)

7.1.1 Method 1. Download from docke hub warehouse (requires internet connection)

ROS1-(melodic)

Use the command on the host:

image-20231214194555725

ROS2-(foxy)

Use the command on the host:

image-20231214194703351

After the installation is complete, enter the docker images command to see the image list.

7.1.2 Method 2: Load from local file (offline)

Obtain the .tar compressed package from the network disk data and select the ROS environment you need. image-20231221165130082

Use the command in the directory where the [xxx.tar] file of the host machine is located:

This operation takes some time, but rarely fails. image-20231221162423740

After docker load execution is completed, execute:

You can view the updated image and experience the new features image-20231215092406111

If you see the REPOSITORY TAG displayed as <_none>

In order to facilitate the use of subsequent scripts, we need to update the label of the image we pulled.

Command prototype: docker tag <IMAGE_ID> <REPOSITORY_NAME>:<TAG_NAME>

image-20231221163230757

7.2 Usage tips

At this point, the ros environment in docker has been set up. Follow the instructions for the corresponding accessories to enter the docker container and use it.

 

7.3 Using accessories in docker container ROS1/ROS2

7.3.1 Install device udev rules rule file

Terminal input,

install.sh is mainly a script that executes binding rule files

Mainly done (move xxx.rules to the /etc/udev/rules.d/ directory) operation

The script or startup folder under each function package generally has a .sh script. Each function package is not necessarily named install.sh. Before using it, cd to the directory and ls to see the full name of the script, and then execute it. bash command. If there is no script, you can manually cp the .rules file to the directory and the effect will be the same.

image-20231214144629620

After the installation is complete, it is best to restart.

Enter the following command to verify,

The following content appears, indicating that the binding is successful

astraproplusshow image-20231214144640807

gemini2display image-20231214144648832

7.3.2 Write startup script

ROS1 example: docker_ros1.sh

ROS2 example: docker_ros2.sh

Annotated script (not run directly)

7.3.3 Run the script to enter the container

Note: It must be executed on the VNC of the host machine or on the screen. It cannot be executed on the terminal that remotely accesses the Raspberry Pi through SSH. Otherwise, the GUI image may not be displayed in the container.

(If entering via ssh, this is an error message)

image-20231215093131203

image-20231215093309219

After entering the container, you can execute the rviz/rviz2 command to test whether the GUI is displayed normally.

7.3.4 Incoming accessory function package

Pass the corresponding function package of the accessory into the temporary transfer file directory in the container (the shared directory set in the startup script).

For example: Use WINSCP software to transfer the function package to the host, and then copy it to the shared directory, that is, /home/pi/temp. The files in the /root/temp directory in the container are synchronized.

image-20231206122215971

Next, just follow the tutorial corresponding to the accessory in the container to use it.