Docker containers by default run as the 'root' user. This can create massive problems.
When creating ROS2 packages inside the container, all of the newly created files are owned by 'root'. This prevented editing and deleting the files without using the 'sudo' command outside the container.
Creates a Docker container that uses a regular user and not the 'root' user.
Build the container.
cd Docker
../build.sh
cd ..
Run the container for the first time.
Running this twice in a row will generate an error.
./run.sh
Restart the container that has already be run once.
./start.sh
If necessary:
docker rmi -f ros2_diff_drive_jazzy
# Inside the container...
cd /ros2_diff_drive_ws/src
# Create a new package for the controller
ros2 pkg create --build-type ament_python --dependencies rclpy std_msgs geometry_msgs nav_msgs tf2 tf2_ros control_msgs sensor_msgs test_msgs launch_py --description "Generic diff drive controller" --maintainer-email [email protected] --license MIT diff_drive_controller_generic
# Create a new package for the PWM control
ros2 pkg create --build-type ament_python --dependencies rclpy std_msgs sensor_msgs control_msgs launch_py --description "Generic PWM controller for robotics applications" --maintainer-email [email protected] --license MIT pwm_controller_generic
# Build the workspace
## This must be done at the workspace directory level!
cd /ros2_diff_drive_ws
colcon build --symlink-install
Starting >>> diff_drive_controller_generic
Starting >>> pwm_controller_generic
Finished <<< pwm_controller_generic [1.10s]
Finished <<< diff_drive_controller_generic [1.11s]
Summary: 2 packages finished [1.31s]
- Exit container
- git add .
- git commit -am "After colcon build."
All files are owned by the user and not 'root'.
Done.
Build the package using colcon build. Run the node using ros2 run pwm_controller_generic pwm_controller_generic. Publish duty cycle values to the /duty_cycle topic using ros2 topic pub /duty_cycle std_msgs/msg/Float64 "data: 0.5". Observe the PWM state on the /pwm_state topic using ros2 topic echo /pwm_state.