Skip to content

Commit

Permalink
Make python
Browse files Browse the repository at this point in the history
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
  • Loading branch information
micragz committed Jul 11, 2024
1 parent ab6ee27 commit fd11c7d
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,16 @@ This sample performs single-acquisition 3D captures in a loop. This sample shows
the capture settings, how to subscribe to the [points/xyzrgba](#pointsxyzrgba) topic, and how to invoke the
[capture](#capture) service.

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

```bash
ros2 launch zivid_samples sample.launch sample:=sample_capture_cpp
ros2 launch zivid_samples sample.launch sample:=sample_capture_py
```
Using ros2 run (when `zivid_camera` node is already running):
```bash
ros2 run zivid_samples sample_capture_cpp
ros2 run zivid_samples sample_capture_py
```

### Sample Capture 2D
Expand Down
5 changes: 4 additions & 1 deletion zivid_samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()

find_package(ament_cmake REQUIRED)
find_package(ament_cmake_python REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(rclcpp REQUIRED)
find_package(zivid_interfaces REQUIRED)
Expand All @@ -34,7 +35,9 @@ add_executable(sample_capture_and_save_cpp src/sample_capture_and_save.cpp)
ament_target_dependencies(sample_capture_and_save_cpp rclcpp zivid_interfaces)
install(TARGETS sample_capture_and_save_cpp DESTINATION lib/${PROJECT_NAME})

install(PROGRAMS scripts/sample_capture.py DESTINATION lib/${PROJECT_NAME})
ament_python_install_package(${PROJECT_NAME} SCRIPTS_DESTINATION lib/${PROJECT_NAME})
#install(PROGRAMS scripts/zivid_samples DESTINATION bin)
#install(PROGRAMS scripts/zivid_samples DESTINATION lib/${PROJECT_NAME})

if(BUILD_TESTING)
# TODO enable linting of the samples
Expand Down
2 changes: 1 addition & 1 deletion zivid_samples/launch/sample.launch
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<arg name="sample" default=""/>
<node pkg="zivid_camera" exec="zivid_camera" name="zivid_camera" />
<node pkg="zivid_samples" exec="$(var sample)" name="$(var sample)" />
</launch>
</launch>
22 changes: 22 additions & 0 deletions zivid_samples/launch/sample_py_launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from launch import LaunchDescription
from launch_ros.actions import Node


def generate_launch_description():
launch_description = LaunchDescription()

launch_description.add_action(
Node(package="zivid_camera", executable="zivid_camera", name="zivid_camera")
)

launch_description.add_action(
Node(
package="zivid_samples",
executable="sample_capture_py",
name="zivid_sample",
output="screen",
emulate_tty=True,
),
)

return launch_description
1 change: 1 addition & 0 deletions zivid_samples/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<url type="repository">https://github.com/zivid/zivid-ros</url>
<url type="bugtracker">https://github.com/zivid/zivid-ros/issues</url>
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake_python</buildtool_depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>sensor_msgs</depend>
Expand Down
3 changes: 3 additions & 0 deletions zivid_samples/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[options.entry_points]
console_scripts =
sample_capture_py = zivid_samples.sample_capture:main
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Sample(Node):
def __init__(self):
super().__init__("sample_capture_py")

self.get_logger().info("Starting sample_capture_py")

self.capture_service = self.create_client(Trigger, "capture")
while not self.capture_service.wait_for_service(timeout_sec=3.0):
self.get_logger().info("Capture service not available, waiting again...")
Expand Down

0 comments on commit fd11c7d

Please sign in to comment.