lucasw / ros_one2z

Similar node graphs in vanilla ros1 and ros2 and also zenoh, focus on localhost using python but also C++ and maybe rust
BSD 3-Clause "New" or "Revised" License
4 stars 0 forks source link

Set up similar ros1&2 image publisher python nodes #1

Open lucasw opened 9 months ago

lucasw commented 9 months ago
catkin_create_pkg ros1_example_pkg

(no --no-comments yet, manually delete the comment lines in package.xml and CMakeLists.txt)

ros2 pkg create --build-type ament_python ros2_example_pkg
lucasw commented 9 months ago

No issues having a mixed workspace in ros1, catkin gracefully skips over the ros2 one:

[build] Warning: Skipping package `ros2_example_pkg` because it has an unsupported package build type: `ament_python`                                                                                                     

But in ros2:

--- stderr: ros1_example_pkg                                                               
Traceback (most recent call last):
  File "/home/lucasw/ros/ros2_iron_misc/build/ros1_example_pkg/catkin_generated/generate_cached_setup.py", line 22, in <module>
    code = generate_environment_script('/home/lucasw/ros/ros2_iron_misc/build/ros1_example_pkg/devel/env.sh')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/catkin/environment_cache.py", line 63, in generate_environment_script
    env_after = ast.literal_eval(output.decode('utf8'))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ast.py", line 64, in literal_eval
    node_or_string = parse(node_or_string.lstrip(" \t"), mode='eval')
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<unknown>", line 1
    ROS_DISTRO was set to 'iron' before. Please make sure that the environment does not mix paths from different distributions.
               ^^^
SyntaxError: invalid syntax
CMake Error at /usr/share/catkin/cmake/safe_execute_process.cmake:11 (message):
  execute_process(/usr/bin/python3
  "/home/lucasw/ros/ros2_iron_misc/build/ros1_example_pkg/catkin_generated/generate_cached_setup.py")
  returned error code 1
Call Stack (most recent call first):
  /usr/share/catkin/cmake/all.cmake:221 (safe_execute_process)
  /usr/share/catkin/cmake/catkinConfig.cmake:20 (include)
  CMakeLists.txt:4 (find_package)

So skip it:

colcon build --symlink-install --packages-skip ros1_example_pkg

(can that be made persistent?)

Only get this deprecation warning:

--- stderr: ros2_example_pkg                   
/usr/lib/python3/dist-packages/setuptools/command/easy_install.py:146: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
/usr/lib/python3/dist-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
lucasw commented 9 months ago
rosmsg show Image

ros2 equivalent:

ros2 interface show sensor_msgs/msg/Image
lucasw commented 9 months ago

Forgot to install rqt_image_view? Didn't really forget, it just wasn't in ros2 repos yaml.

https://github.com/lucasw/ros_from_src/issues/29

lucasw commented 9 months ago
export COLCON_DEFAULTS_FILE=$HOME/ros/colcon_defaults.yaml
{
    "build": {
        "symlink-install": true,
        "cmake-args": [
          "-DCMAKE_BUILD_TYPE=Release",
        ],
        "packages-skip": [
          "ros1_example_pkg",
        ],
    }
}

-> can use plain colcon build:

colcon build
lucasw commented 9 months ago

There doesn't appear to be a ros2 AnyMsg, but can get the message class like this:

    msg_class = get_msg_class(node, topic, blocking=True, include_hidden_topics=True)
    if msg_class is None:
        node.destroy_node()
        return

    rt = ROSTopicBandwidth(node, window_size)
    node.create_subscription(
        msg_class,
        topic,
        rt.callback, 
        qos_profile_sensor_data,
        raw=True
    )   

ros2topic/ros2topic/verb/bw.py