Skip to content

Commit fd11c7d

Browse files
committed
Make python
This was an attempt at making the ROS2 launch files work with the Python samples on Windows. The issue is that, if we simply try to launch the python script directly, we get the following error: ``` OSError: [WinError 193] %1 is not a valid Win32 application ``` In this commit, we try to make a Python module out of the samples, install them using `ament_cmake_python`, and use a `setup.cfg` to add a console script entry point. This way, we can launch the samples using both `ros2 run` and `ros2 launch` commands. This approach was modeled after: ros/xacro#304 This seemed to work. However, a new issue emerged. While `ros2 run` still works fine, now we are not getting any log output when launching it with `ros2 launch`. We seem to be encountering this issue: MISC-2024-06-19-ros2-testing
1 parent ab6ee27 commit fd11c7d

File tree

8 files changed

+36
-3
lines changed

8 files changed

+36
-3
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,16 @@ This sample performs single-acquisition 3D captures in a loop. This sample shows
351351
the capture settings, how to subscribe to the [points/xyzrgba](#pointsxyzrgba) topic, and how to invoke the
352352
[capture](#capture) service.
353353

354-
Source code: [C++](./zivid_samples/src/sample_capture.cpp)
354+
Source code: [C++](./zivid_samples/src/sample_capture.cpp) [Python](./zivid_samples/scripts/sample_capture.py)
355355

356356
```bash
357357
ros2 launch zivid_samples sample.launch sample:=sample_capture_cpp
358+
ros2 launch zivid_samples sample.launch sample:=sample_capture_py
358359
```
359360
Using ros2 run (when `zivid_camera` node is already running):
360361
```bash
361362
ros2 run zivid_samples sample_capture_cpp
363+
ros2 run zivid_samples sample_capture_py
362364
```
363365

364366
### Sample Capture 2D

zivid_samples/CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1212
endif()
1313

1414
find_package(ament_cmake REQUIRED)
15+
find_package(ament_cmake_python REQUIRED)
1516
find_package(ament_index_cpp REQUIRED)
1617
find_package(rclcpp REQUIRED)
1718
find_package(zivid_interfaces REQUIRED)
@@ -34,7 +35,9 @@ add_executable(sample_capture_and_save_cpp src/sample_capture_and_save.cpp)
3435
ament_target_dependencies(sample_capture_and_save_cpp rclcpp zivid_interfaces)
3536
install(TARGETS sample_capture_and_save_cpp DESTINATION lib/${PROJECT_NAME})
3637

37-
install(PROGRAMS scripts/sample_capture.py DESTINATION lib/${PROJECT_NAME})
38+
ament_python_install_package(${PROJECT_NAME} SCRIPTS_DESTINATION lib/${PROJECT_NAME})
39+
#install(PROGRAMS scripts/zivid_samples DESTINATION bin)
40+
#install(PROGRAMS scripts/zivid_samples DESTINATION lib/${PROJECT_NAME})
3841

3942
if(BUILD_TESTING)
4043
# TODO enable linting of the samples

zivid_samples/launch/sample.launch

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
<arg name="sample" default=""/>
33
<node pkg="zivid_camera" exec="zivid_camera" name="zivid_camera" />
44
<node pkg="zivid_samples" exec="$(var sample)" name="$(var sample)" />
5-
</launch>
5+
</launch>
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from launch import LaunchDescription
2+
from launch_ros.actions import Node
3+
4+
5+
def generate_launch_description():
6+
launch_description = LaunchDescription()
7+
8+
launch_description.add_action(
9+
Node(package="zivid_camera", executable="zivid_camera", name="zivid_camera")
10+
)
11+
12+
launch_description.add_action(
13+
Node(
14+
package="zivid_samples",
15+
executable="sample_capture_py",
16+
name="zivid_sample",
17+
output="screen",
18+
emulate_tty=True,
19+
),
20+
)
21+
22+
return launch_description

zivid_samples/package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<url type="repository">https://github.com/zivid/zivid-ros</url>
1111
<url type="bugtracker">https://github.com/zivid/zivid-ros/issues</url>
1212
<buildtool_depend>ament_cmake</buildtool_depend>
13+
<buildtool_depend>ament_cmake_python</buildtool_depend>
1314
<depend>rclcpp</depend>
1415
<depend>rclcpp_components</depend>
1516
<depend>sensor_msgs</depend>

zivid_samples/setup.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[options.entry_points]
2+
console_scripts =
3+
sample_capture_py = zivid_samples.sample_capture:main

zivid_samples/zivid_samples/__init__.py

Whitespace-only changes.

zivid_samples/scripts/sample_capture.py zivid_samples/zivid_samples/sample_capture.py

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class Sample(Node):
1515
def __init__(self):
1616
super().__init__("sample_capture_py")
1717

18+
self.get_logger().info("Starting sample_capture_py")
19+
1820
self.capture_service = self.create_client(Trigger, "capture")
1921
while not self.capture_service.wait_for_service(timeout_sec=3.0):
2022
self.get_logger().info("Capture service not available, waiting again...")

0 commit comments

Comments
 (0)