setup clion remote debug with ros2 and docker
sudo apt-get update \
&& sudo apt-get install -y ssh \
build-essential \
gcc \
g++ \
gdb \
clang \
cmake \
rsync \
tar \
python
Add new group and user (recommended)
groupadd -g 1011 test
useradd -m testuser -g test -G root
echo 'testuser:123' | chpasswd
If existed group, need to change group authority and add a new user(better to ignore existed user):
(such as 'user' is the existed group, add new user 'sftpuser' to it)
useradd -m sftpuser -g user
echo 'sftpuser:123' | chpasswd
Firstly, open write authority of sudoers file:
chmod u+w /etc/sudoers
Secondly, add text "user ALL=(ALL:ALL) ALL" into sudoers file
vim /etc/sudoers
Thirdly, close write authority of sudoers file:
chmod u+w /etc/sudoers
Write the text below into /etc/ssh/sshd_config file
Port 202
PasswordAuthentication yes
PermitEmptyPasswords no
PermitRootLogin yes
UsePAM no
Subsystem sftp internal-sftp
Match Group testuser
ChrootDirectory /
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
Important !!!!!
The name follow Match Group must be the name with the user you add, do not use group name.
The port must be the same with the docker you used.
docker commit -a "shanph" -m "upgrade" 7c8c8fbb58eb shanph:test
The 7c8c8fbb58eb is check with:
docker ps -a
Whatever command you used to run docker, must have the option -p, such as:
docker run -d --cap-add sys_ptrace -p127.0.0.1:202:202 --name clion_remote_env clion/remote-cpp-env:0.5
or just as single option in run shell:
-p 202:202
In short, you should add a new Toolchain entry in settings under Build, Execution, Deployment as a Remote Host type. Then click in the Credentials section and fill out the SSH credentials we set-up in the Dockerfile (Host: localhost, Port: 2222, User name: user, Password: password). Finally, add a CMake profile that uses this toolchain(remote). If you want more fine grained control over the paths used inside the container take a look at the Deployment settings page.
Firstly, run docker, cd to your ros2 workspace, compile and source current ws:
cd ros2_ws
. /opt/ros/foxy/setup.bash
colcon build --symlink-install
. install/setup.bash
Then copy env.sh to your ros2 workspace(env.sh is provided in my project), get the environment param.
./env.sh
Copy the output to CLion -> CMake -> Environment.
Now, all is finished.
Enjoy yourself.
Such as the costmap_converter for teb. costmap_converter pkg is not installed because I want to use the custom version. But at the begin, cannot find it.
Could not find a package configuration file provided by “costmap_converter” with any of the following names
Solve by set pkg_DIR before find_package.
set(costmap_converter_DIR /midea_robot/ros2_ws/build/costmap_converter)
Because colcon build is corrected. In build folder, there are **Config.cmake files. We can use the files to find the pkg.
Use the command to show compile process.
colcon build --symlink-install --event-handlers console_direct+
ffmpeg \
-i clion_remote_docker_debug-2021-05-12_23.29.07.mp4 \
-r 30 \
-vf "scale=512:-1,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" \
-ss 00:00:00 -to 00:00:42 \
cannot_create_directory.gif