[Docker] missing packages when using `ros2 launch`
I'm expanding https://github.com/Livox-SDK/livox_ros2_driver and adding a Dockerfile do colcon build and use ros2 launch. I'm trying to cross-compile livox using the instruction from https://github.com/Livox-SDK/Livox-SDK#413-arm-linux-cross-compile.
The Dockerfile content is as follows:
FROM ros:foxy-ros-base
RUN apt-get update -y && DEBIAN_FRONTEND=noninteractive apt-get install -y \
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu ros-foxy-pcl-conversions
WORKDIR /ws_livox
COPY livox_ros2_driver src/
COPY livox_lidar_config.json src/livox_ros2_driver/config/livox_lidar_config.json
SHELL ["/bin/bash", "-c"]
RUN . /ros_entrypoint.sh && \
colcon build --parallel-workers 1 --cmake-args -DCMAKE_CXX_FLAGS="--param ggc-min-expand=20"
CMD . /ros_entrypoint.sh && . install/setup.bash && \
ros2 launch src/livox_ros2_driver/launch/livox_lidar_launch.py
Building and running this throws the following error:
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<LaunchService._process_one_event() done, defined at /opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py:274> exception=PackageNotFoundError("package 'livox_ros2_driver' not found, searching: ['/ws_livox/install/livox_sdk_vendor', '/opt/ros/foxy']")>
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/ament_index_python/packages.py", line 49, in get_package_prefix
content, package_prefix = get_resource('packages', package_name)
File "/opt/ros/foxy/lib/python3.8/site-packages/ament_index_python/resources.py", line 48, in get_resource
raise LookupError(
LookupError: Could not find the resource 'livox_ros2_driver' of type 'packages'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 276, in _process_one_event
await self.__process_event(next_event)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 296, in __process_event
visit_all_entities_and_collect_futures(entity, self.__context))
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
[Previous line repeated 1 more time]
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 38, in visit_all_entities_and_collect_futures
sub_entities = entity.visit(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/action.py", line 108, in visit
return self.execute(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch_ros/actions/node.py", line 426, in execute
ret = super().execute(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/actions/execute_process.py", line 823, in execute
self.__expand_substitutions(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/actions/execute_process.py", line 668, in __expand_substitutions
cmd = [perform_substitutions(context, x) for x in self.__cmd]
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/actions/execute_process.py", line 668, in <listcomp>
cmd = [perform_substitutions(context, x) for x in self.__cmd]
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/perform_substitutions_impl.py", line 26, in perform_substitutions
return ''.join([context.perform_substitution(sub) for sub in subs])
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/perform_substitutions_impl.py", line 26, in <listcomp>
return ''.join([context.perform_substitution(sub) for sub in subs])
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_context.py", line 197, in perform_substitution
return substitution.perform(self)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch_ros/substitutions/executable_in_package.py", line 76, in perform
package_prefix = super().perform(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch_ros/substitutions/find_package.py", line 79, in perform
result = self.find(package)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch_ros/substitutions/find_package.py", line 96, in find
return get_package_prefix(package_name)
File "/opt/ros/foxy/lib/python3.8/site-packages/ament_index_python/packages.py", line 51, in get_package_prefix
raise PackageNotFoundError(
ament_index_python.packages.PackageNotFoundError: "package 'livox_ros2_driver' not found, searching: ['/ws_livox/install/livox_sdk_vendor', '/opt/ros/foxy']"
What I can't understand is why the other packages aren't available when running the CMD in docker.
If I comment out the CMD on the Dockerfile and run the container with docker run
I can source the files and use ros2 lanuch
with no problems:
❯ docker run -it --rm livox-playground_livox /bin/bash
root@64b328b16fb7:/ws_livox# . install/setup.bash
root@64b328b16fb7:/ws_livox# ros2 launch src/livox_ros2_driver/launch/livox_lidar_launch.py
[INFO] [launch]: All log files can be found below /root/.ros/log/2021-07-19-21-51-44-563397-64b328b16fb7-42
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [livox_ros2_driver_node-1]: process started with pid [44]
[livox_ros2_driver_node-1] [INFO] [1626731504.681808635] [livox_lidar_publisher]: Livox Ros Driver Version: 0.0.1
[livox_ros2_driver_node-1] [INFO] [1626731504.682200885] [livox_lidar_publisher]: Data Source is raw lidar.
[livox_ros2_driver_node-1] [INFO] [1626731504.682213676] [livox_lidar_publisher]: Config file : /ws_livox/src/livox_ros2_driver/launch/../config/livox_lidar_config.json
[livox_ros2_driver_node-1] [INFO] [1626731504.683436593] [livox_lidar_publisher]: Init lds lidar success!
Thanks for taking your time to check my question.
Asked by fampinheiro on 2021-07-19 16:54:11 UTC
Answers
A few things:
- No need to source the entrypoint in the CMD directive
- You are building from an official ROS docker image
- thus the existing entrypoint will already source ros setup before executing the CMD
- you should instead modify the entrypoint to source your workspace's setup script
- e.g. https://github.com/ros-planning/navigation2/blob/5c61644651c4eab882b042e073d0f5964f03a501/tools/distro.Dockerfile#L88-L90
- I wouldn't recomend sourceing the entrypoint from the RUN directive
- instead source the setup.sh script directly for the workspace you'd like to overlay
- e.g. https://github.com/ros-planning/navigation2/blob/5c61644651c4eab882b042e073d0f5964f03a501/tools/distro.Dockerfile#L77
- no need to change the default shell from sh/dash to bash
- when sourcing setup scripts using the sh dot
.
syntax as demoed in examples above
- when sourcing setup scripts using the sh dot
Asked by ruffsl on 2021-07-24 00:40:43 UTC
Comments