No version for distro humble showing jazzy. Known supported distros are highlighted in the buttons above.

Package Summary

Version 3.0.5
License BSD-3-Clause
Build type CATKIN
Use RECOMMENDED

Repository Summary

Description
Checkout URI https://github.com/jsk-ros-pkg/jsk_common.git
VCS Type git
VCS Version 3.0.5
Last Updated 2026-11-10
Dev Status UNKNOWN
Released RELEASED
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Package Description

Shared ROS1(roscpp/rospy)/ROS2(rclcpp/rclpy) compatibility helpers used across jsk_common's ROS2-ported packages, so that individual packages don't each maintain their own copy.

Maintainers

  • Kei Okada

Authors

No additional authors.

jsk_ros1_ros2_compat

Shared ROS1 (roscpp/rospy) / ROS2 (rclcpp/rclpy) compatibility helpers, so that a package can keep one source tree that builds and runs on both, with the ROS1 code left as close to the original as possible.

Porting style

  • One package.xml / CMakeLists.txt branched on $ROS_VERSION.
    • package.xml: condition="$ROS_VERSION == 1" / "== 2" on the dependencies and on <build_type> in <export>.
    • CMakeLists.txt: keep the ROS1 lines byte-identical (no re-indentation), e.g. prepend the ROS2 build and wrap the original in else()/endif():
    if("$ENV{ROS_VERSION}" EQUAL 2)
      cmake_minimum_required(VERSION 3.8)
      project(foo)
      find_package(ament_cmake REQUIRED)
      find_package(jsk_ros1_ros2_compat REQUIRED)
      jsk_ros1_ros2_compat_install_python(PROGRAMS scripts/foo_node.py)
      ament_package()
    else() # if("$ENV{ROS_VERSION}" EQUAL 2)
    cmake_minimum_required(VERSION 2.8.3)
    project(foo)
    ...  # the ROS1 original, unchanged
    endif() # if("$ENV{ROS_VERSION}" EQUAL 2)
    
  • Python nodes call ros_compat.xxx(node, ...) instead of rospy.xxx(...), where node is None on ROS1 and the rclpy.node.Node on ROS2.

Python: jsk_ros1_ros2_compat.rospy_rclpy_compat

from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION

if __name__ == '__main__':
    node = ros_compat.init_node('foo')  # None on ROS1
    Foo(node)
    ros_compat.spin(node)

  ROS1 ROS2
get_param(node, '~name', default), has_param rospy.get_param declares a (dynamically typed) parameter
init_node(name, anonymous=False, multi_threaded=False) rospy.init_node, returns None rclpy.init() + a new node, returned (multi_threaded: see below)
spin(node), spin_once(node, timeout_sec), shutdown(node) (after an own while not is_shutdown(node) loop) rospy.spin, rospy.sleep, - spin_and_shutdown, rclpy.spin_once, cleanup
loginfo/logwarn/logerr/logdebug/logfatal(node, msg) rospy.log* node.get_logger().* (msg must be a str; node=None uses a logger named after the script)
loginfo/logwarn/logerr_throttle(node, period, msg), loginfo/logwarn/logerr_once(node, msg) like rospy.log*_throttle/_once like throttle_duration_sec=/once=True (per call site, done in compat)
create_publisher(node, topic, type, queue_size=1, latch=False) rospy.Publisher node.create_publisher (latch: transient-local QoS)
create_subscription(node, topic, type, cb, queue_size=None, latch=False) rospy.Subscriber (None: unbounded) node.create_subscription (None: depth 1; latch: transient-local QoS; ~foo -> ~/foo)
wait_for_service(node, name, type, timeout) (returns bool), set_param(node, name, value) rospy.wait_for_service, rospy.set_param a client’s wait_for_service, node.set_parameters
create_service, create_trigger_service, call_service, create_request/response, get_response_class (FooResponse(*values) on both) rospy.Service/ServiceProxy node.create_service/create_client
create_timer(node, period, cb) rospy.Timer node.create_timer (cb(None))
create_simple_action_client(node, name, type) actionlib.SimpleActionClient same subset over rclpy.action.ActionClient
create_simple_action_server(node, name, type, execute_cb) actionlib.SimpleActionServer same subset over rclpy.action.ActionServer
callback_group= of create_subscription/service/trigger_service/timer/simple_action_client/simple_action_server ignored (rospy runs each callback in its own thread) the rclpy callback group, e.g. ReentrantCallbackGroup() with a MultiThreadedExecutor
init_node(name, multi_threaded=True), for callbacks waiting for other callbacks (e.g. a service callback waiting for a topic) ignored (as above) create_* default to a ReentrantCallbackGroup and spin() uses a MultiThreadedExecutor
create_reconfigure_server(node, Config, cb, defaults) dynamic_reconfigure.server.Server parameters declared from defaults + on-set callback
now_sec, stamp_now, stamp_to_sec, duration_from_sec, sleep, Rate rospy.Time/Duration/... node.get_clock(), …
get_name, is_shutdown, on_shutdown, signal_shutdown rospy.* node name / rclpy context
create_tf_buffer_and_listener, create_tf_broadcaster tf2_ros tf2_ros with node
spin_and_shutdown(node, executor=None) - spin until SIGINT/SIGTERM/signal_shutdown, then clean up

Action types: pass FooAction/FooGoal on ROS1 and Foo/Foo.Goal on ROS2; timeouts are in seconds on both. actionlib/dynamic_reconfigure are imported lazily, so depend on them in your own package.

Packages outside jsk_common

jsk_ros1_ros2_compat is only released with jsk_common >= 3.0, which is not available for every ROS1 distro. Depend on it for ROS2 only and fall back to rospy when it can not be imported, listing just the functions you use:

<exec_depend condition="$ROS_VERSION == 2">jsk_ros1_ros2_compat</exec_depend>

try:
    from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
    from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION
except ImportError:
    # jsk_common < 3.0 has no jsk_ros1_ros2_compat, so this is ROS1 only:
    # forward ros_compat.xxx(node, ...) to rospy.xxx(...)
    import rospy
    ROS_VERSION = 1
    class ros_compat(object):
        get_param = staticmethod(lambda node, *args, **kwargs: rospy.get_param(*args, **kwargs))
        loginfo = staticmethod(lambda node, *args, **kwargs: rospy.loginfo(*args, **kwargs))

Or, to keep the original rospy code untouched for its ROS1 users, add a jsk_ros1_ros2_compat version next to it and choose by whether jsk_ros1_ros2_compat can be imported (not by ROS_VERSION):

```python try:

File truncated at 100 lines see the full file

CHANGELOG

Changelog for package jsk_ros1_ros2_compat

3.0.5 (2026-11-10)

  • Merge pull request #1841 from k-okada/rosdistro-55117-review rosdistro#55117 review: add LICENSE to each package, use SPDX license identifiers
  • Merge pull request #1840 from k-okada/rhel-ambiguous-shebang Fix RHEL rpm build (ambiguous python shebang) of image_view2 and uv venv
  • use SPDX license identifiers (BSD-3-Clause, Apache-2.0) in package.xml BSD -> BSD-3-Clause and "Apache License 2.0" -> Apache-2.0 in all packages (ros/rosdistro#55117 review: "BSD is ambiguous. The headers show the 3-clause variant, so BSD-3-Clause (SPDX) is preferred."). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • add LICENSE to each package (BSD-3-Clause, jsk_tools: Apache-2.0) The ROS2 release review of jsk_common in ros/rosdistro#55117 says (https://github.com/ros/rosdistro/pull/55117#issuecomment-6757665510): > - [ ] At least one of the following must be present > - [ ] Top level license file: None. There is no LICENSE/COPYING at > the repo root (tree @ cbbd0ab). > - [ ] Per package license files: None. No package directory has a > license file. The license text only appears in source-file headers > (e.g. deprecated_relay.h#L1-L33, BSD-3-Clause, "JSK Lab"). Since jsk_tools is Apache-2.0 and the others are BSD-3-Clause, add a license file to each package instead of one at the top level. The BSD ones use the same text as the source headers, "Copyright (c) <year>-, JSK Lab" where <year> is when the package.xml was added, and jsk_tools has the Apache License 2.0 text from apache.org. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • jsk_ros1_ros2_compat: drop exec bits of python modules in uv venv (RHEL ambiguous shebang) Some wheels (e.g. protobuf's _parameterized.py) ship modules executable with a "#!/usr/bin/env python" shebang, which makes brp-mangle-shebangs fail the RHEL rpm build of packages using jsk_ros1_ros2_compat_generate_uv_venv(). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • Contributors: Kei Okada

3.0.4 (2026-11-04)

3.0.3 (2026-11-03)

  • Merge pull request #1835 from k-okada/ros-version-fallback-ament Fix ROS2 buildfarm binary jobs: ROS_VERSION without ros_environment, boost for jsk_topic_tools

  • Merge pull request #1834 from pazeshun/array-to-heatmap [jsk_ros1_ros2_compat, jsk_topic_tools, jsk_rosbag_tools] Add array heatmap tools with ROS 1 and ROS 2 support

  • Guess ROS_VERSION from AMENT_PREFIX_PATH when unset, depend on ros_environment The ROS2 binary jobs of the buildfarm failed at find_package(catkin): they install only the build dependencies, none of which pulls in ros_environment, so $ENV{ROS_VERSION} is empty and the fallback at the top of CMakeLists.txt chose ROS1.

    - package.xml: add a ROS2 buildtool_depend on ros_environment, which sets ROS_VERSION.

    - CMakeLists.txt: when ROS_VERSION is still unset, guess it from AMENT_PREFIX_PATH (bloom's ROS2 debian/rules passes it to cmake, setup.sh and colcon set the environment variable, catkin never does) instead of always assuming ROS1, and warn about it. jsk_tools had no fallback at all and gets the same block. Applies to jsk_ros1_ros2_compat, jsk_tools, jsk_topic_tools, jsk_common, jsk_data, jsk_rosbag_tools, dynamic_tf_publisher, audio_video_recorder and image_view2. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Merge pull request #1 from k-okada/array-to-heatmap-old-distros Support indigo/kinetic in array heatmap tools (OpenCV 2.4, numpy < 1.9, rosbag < 1.13)

  • [jsk_ros1_ros2_compat] rosbag: raw messages with connection headers on rosbag < 1.13 rosbag of indigo/kinetic has neither read_messages(..., return_connection_header=) nor write(..., connection_header=), which failed test_add_heatmap on the kinetic CI. There, read_raw_messages() takes the header of each topic's connection from the bag, and write_raw() registers a new topic's connection with the given header before writing, as write(..., connection_header=) does on newer rosbag. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Add array heatmap tools with ROS 1 and ROS 2 support

    • Render numeric MultiArray and scalar Image topics as heatmap images with optional cell values and configurable color scales
    • Add heatmap topics to bags while preserving original messages, recording timestamps, and connection or QoS metadata
    • Extend the compatibility layer with raw bag I/O and shared message type helpers
    • Add installation rules, documentation, and tests for both ROS versions
  • Merge pull request

File truncated at 100 lines see the full file

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged jsk_ros1_ros2_compat at Robotics Stack Exchange

Package Summary

Version 3.0.5
License BSD-3-Clause
Build type CATKIN
Use RECOMMENDED

Repository Summary

Description
Checkout URI https://github.com/jsk-ros-pkg/jsk_common.git
VCS Type git
VCS Version 3.0.5
Last Updated 2026-11-10
Dev Status UNKNOWN
Released RELEASED
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Package Description

Shared ROS1(roscpp/rospy)/ROS2(rclcpp/rclpy) compatibility helpers used across jsk_common's ROS2-ported packages, so that individual packages don't each maintain their own copy.

Maintainers

  • Kei Okada

Authors

No additional authors.

jsk_ros1_ros2_compat

Shared ROS1 (roscpp/rospy) / ROS2 (rclcpp/rclpy) compatibility helpers, so that a package can keep one source tree that builds and runs on both, with the ROS1 code left as close to the original as possible.

Porting style

  • One package.xml / CMakeLists.txt branched on $ROS_VERSION.
    • package.xml: condition="$ROS_VERSION == 1" / "== 2" on the dependencies and on <build_type> in <export>.
    • CMakeLists.txt: keep the ROS1 lines byte-identical (no re-indentation), e.g. prepend the ROS2 build and wrap the original in else()/endif():
    if("$ENV{ROS_VERSION}" EQUAL 2)
      cmake_minimum_required(VERSION 3.8)
      project(foo)
      find_package(ament_cmake REQUIRED)
      find_package(jsk_ros1_ros2_compat REQUIRED)
      jsk_ros1_ros2_compat_install_python(PROGRAMS scripts/foo_node.py)
      ament_package()
    else() # if("$ENV{ROS_VERSION}" EQUAL 2)
    cmake_minimum_required(VERSION 2.8.3)
    project(foo)
    ...  # the ROS1 original, unchanged
    endif() # if("$ENV{ROS_VERSION}" EQUAL 2)
    
  • Python nodes call ros_compat.xxx(node, ...) instead of rospy.xxx(...), where node is None on ROS1 and the rclpy.node.Node on ROS2.

Python: jsk_ros1_ros2_compat.rospy_rclpy_compat

from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION

if __name__ == '__main__':
    node = ros_compat.init_node('foo')  # None on ROS1
    Foo(node)
    ros_compat.spin(node)

  ROS1 ROS2
get_param(node, '~name', default), has_param rospy.get_param declares a (dynamically typed) parameter
init_node(name, anonymous=False, multi_threaded=False) rospy.init_node, returns None rclpy.init() + a new node, returned (multi_threaded: see below)
spin(node), spin_once(node, timeout_sec), shutdown(node) (after an own while not is_shutdown(node) loop) rospy.spin, rospy.sleep, - spin_and_shutdown, rclpy.spin_once, cleanup
loginfo/logwarn/logerr/logdebug/logfatal(node, msg) rospy.log* node.get_logger().* (msg must be a str; node=None uses a logger named after the script)
loginfo/logwarn/logerr_throttle(node, period, msg), loginfo/logwarn/logerr_once(node, msg) like rospy.log*_throttle/_once like throttle_duration_sec=/once=True (per call site, done in compat)
create_publisher(node, topic, type, queue_size=1, latch=False) rospy.Publisher node.create_publisher (latch: transient-local QoS)
create_subscription(node, topic, type, cb, queue_size=None, latch=False) rospy.Subscriber (None: unbounded) node.create_subscription (None: depth 1; latch: transient-local QoS; ~foo -> ~/foo)
wait_for_service(node, name, type, timeout) (returns bool), set_param(node, name, value) rospy.wait_for_service, rospy.set_param a client’s wait_for_service, node.set_parameters
create_service, create_trigger_service, call_service, create_request/response, get_response_class (FooResponse(*values) on both) rospy.Service/ServiceProxy node.create_service/create_client
create_timer(node, period, cb) rospy.Timer node.create_timer (cb(None))
create_simple_action_client(node, name, type) actionlib.SimpleActionClient same subset over rclpy.action.ActionClient
create_simple_action_server(node, name, type, execute_cb) actionlib.SimpleActionServer same subset over rclpy.action.ActionServer
callback_group= of create_subscription/service/trigger_service/timer/simple_action_client/simple_action_server ignored (rospy runs each callback in its own thread) the rclpy callback group, e.g. ReentrantCallbackGroup() with a MultiThreadedExecutor
init_node(name, multi_threaded=True), for callbacks waiting for other callbacks (e.g. a service callback waiting for a topic) ignored (as above) create_* default to a ReentrantCallbackGroup and spin() uses a MultiThreadedExecutor
create_reconfigure_server(node, Config, cb, defaults) dynamic_reconfigure.server.Server parameters declared from defaults + on-set callback
now_sec, stamp_now, stamp_to_sec, duration_from_sec, sleep, Rate rospy.Time/Duration/... node.get_clock(), …
get_name, is_shutdown, on_shutdown, signal_shutdown rospy.* node name / rclpy context
create_tf_buffer_and_listener, create_tf_broadcaster tf2_ros tf2_ros with node
spin_and_shutdown(node, executor=None) - spin until SIGINT/SIGTERM/signal_shutdown, then clean up

Action types: pass FooAction/FooGoal on ROS1 and Foo/Foo.Goal on ROS2; timeouts are in seconds on both. actionlib/dynamic_reconfigure are imported lazily, so depend on them in your own package.

Packages outside jsk_common

jsk_ros1_ros2_compat is only released with jsk_common >= 3.0, which is not available for every ROS1 distro. Depend on it for ROS2 only and fall back to rospy when it can not be imported, listing just the functions you use:

<exec_depend condition="$ROS_VERSION == 2">jsk_ros1_ros2_compat</exec_depend>

try:
    from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
    from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION
except ImportError:
    # jsk_common < 3.0 has no jsk_ros1_ros2_compat, so this is ROS1 only:
    # forward ros_compat.xxx(node, ...) to rospy.xxx(...)
    import rospy
    ROS_VERSION = 1
    class ros_compat(object):
        get_param = staticmethod(lambda node, *args, **kwargs: rospy.get_param(*args, **kwargs))
        loginfo = staticmethod(lambda node, *args, **kwargs: rospy.loginfo(*args, **kwargs))

Or, to keep the original rospy code untouched for its ROS1 users, add a jsk_ros1_ros2_compat version next to it and choose by whether jsk_ros1_ros2_compat can be imported (not by ROS_VERSION):

```python try:

File truncated at 100 lines see the full file

CHANGELOG

Changelog for package jsk_ros1_ros2_compat

3.0.5 (2026-11-10)

  • Merge pull request #1841 from k-okada/rosdistro-55117-review rosdistro#55117 review: add LICENSE to each package, use SPDX license identifiers
  • Merge pull request #1840 from k-okada/rhel-ambiguous-shebang Fix RHEL rpm build (ambiguous python shebang) of image_view2 and uv venv
  • use SPDX license identifiers (BSD-3-Clause, Apache-2.0) in package.xml BSD -> BSD-3-Clause and "Apache License 2.0" -> Apache-2.0 in all packages (ros/rosdistro#55117 review: "BSD is ambiguous. The headers show the 3-clause variant, so BSD-3-Clause (SPDX) is preferred."). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • add LICENSE to each package (BSD-3-Clause, jsk_tools: Apache-2.0) The ROS2 release review of jsk_common in ros/rosdistro#55117 says (https://github.com/ros/rosdistro/pull/55117#issuecomment-6757665510): > - [ ] At least one of the following must be present > - [ ] Top level license file: None. There is no LICENSE/COPYING at > the repo root (tree @ cbbd0ab). > - [ ] Per package license files: None. No package directory has a > license file. The license text only appears in source-file headers > (e.g. deprecated_relay.h#L1-L33, BSD-3-Clause, "JSK Lab"). Since jsk_tools is Apache-2.0 and the others are BSD-3-Clause, add a license file to each package instead of one at the top level. The BSD ones use the same text as the source headers, "Copyright (c) <year>-, JSK Lab" where <year> is when the package.xml was added, and jsk_tools has the Apache License 2.0 text from apache.org. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • jsk_ros1_ros2_compat: drop exec bits of python modules in uv venv (RHEL ambiguous shebang) Some wheels (e.g. protobuf's _parameterized.py) ship modules executable with a "#!/usr/bin/env python" shebang, which makes brp-mangle-shebangs fail the RHEL rpm build of packages using jsk_ros1_ros2_compat_generate_uv_venv(). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • Contributors: Kei Okada

3.0.4 (2026-11-04)

3.0.3 (2026-11-03)

  • Merge pull request #1835 from k-okada/ros-version-fallback-ament Fix ROS2 buildfarm binary jobs: ROS_VERSION without ros_environment, boost for jsk_topic_tools

  • Merge pull request #1834 from pazeshun/array-to-heatmap [jsk_ros1_ros2_compat, jsk_topic_tools, jsk_rosbag_tools] Add array heatmap tools with ROS 1 and ROS 2 support

  • Guess ROS_VERSION from AMENT_PREFIX_PATH when unset, depend on ros_environment The ROS2 binary jobs of the buildfarm failed at find_package(catkin): they install only the build dependencies, none of which pulls in ros_environment, so $ENV{ROS_VERSION} is empty and the fallback at the top of CMakeLists.txt chose ROS1.

    - package.xml: add a ROS2 buildtool_depend on ros_environment, which sets ROS_VERSION.

    - CMakeLists.txt: when ROS_VERSION is still unset, guess it from AMENT_PREFIX_PATH (bloom's ROS2 debian/rules passes it to cmake, setup.sh and colcon set the environment variable, catkin never does) instead of always assuming ROS1, and warn about it. jsk_tools had no fallback at all and gets the same block. Applies to jsk_ros1_ros2_compat, jsk_tools, jsk_topic_tools, jsk_common, jsk_data, jsk_rosbag_tools, dynamic_tf_publisher, audio_video_recorder and image_view2. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Merge pull request #1 from k-okada/array-to-heatmap-old-distros Support indigo/kinetic in array heatmap tools (OpenCV 2.4, numpy < 1.9, rosbag < 1.13)

  • [jsk_ros1_ros2_compat] rosbag: raw messages with connection headers on rosbag < 1.13 rosbag of indigo/kinetic has neither read_messages(..., return_connection_header=) nor write(..., connection_header=), which failed test_add_heatmap on the kinetic CI. There, read_raw_messages() takes the header of each topic's connection from the bag, and write_raw() registers a new topic's connection with the given header before writing, as write(..., connection_header=) does on newer rosbag. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Add array heatmap tools with ROS 1 and ROS 2 support

    • Render numeric MultiArray and scalar Image topics as heatmap images with optional cell values and configurable color scales
    • Add heatmap topics to bags while preserving original messages, recording timestamps, and connection or QoS metadata
    • Extend the compatibility layer with raw bag I/O and shared message type helpers
    • Add installation rules, documentation, and tests for both ROS versions
  • Merge pull request

File truncated at 100 lines see the full file

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged jsk_ros1_ros2_compat at Robotics Stack Exchange

Package Summary

Version 3.0.5
License BSD-3-Clause
Build type CATKIN
Use RECOMMENDED

Repository Summary

Description
Checkout URI https://github.com/jsk-ros-pkg/jsk_common.git
VCS Type git
VCS Version master
Last Updated 2026-11-18
Dev Status UNKNOWN
Released RELEASED
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Package Description

Shared ROS1(roscpp/rospy)/ROS2(rclcpp/rclpy) compatibility helpers used across jsk_common's ROS2-ported packages, so that individual packages don't each maintain their own copy.

Maintainers

  • Kei Okada

Authors

No additional authors.

jsk_ros1_ros2_compat

Shared ROS1 (roscpp/rospy) / ROS2 (rclcpp/rclpy) compatibility helpers, so that a package can keep one source tree that builds and runs on both, with the ROS1 code left as close to the original as possible.

ROS 1 / ROS 2

This is a library package (no nodes, scripts or launch files). It builds for both ROS 1 (catkin) and ROS 2 (ament), selected by $ROS_VERSION:

  ROS 1 ROS 2
C++ headers (include/jsk_ros1_ros2_compat/*.h) yes yes
Python package jsk_ros1_ros2_compat (rospy_rclpy_compat, rosbag, log_utils) yes yes
CMake jsk_ros1_ros2_compat_install_python() defined, but meant for ROS 2 builds yes
CMake jsk_ros1_ros2_compat_generate_uv_venv() and the bundled uv binary (lib/jsk_ros1_ros2_compat/uv) no (use catkin_virtualenv) yes

ROS_VERSION in the Python modules is read from the ROS_VERSION environment variable (default 1). The C++ headers detect ROS 1 by whether <ros/ros.h> can be included, so no compile definition is needed.

Porting style

  • One package.xml / CMakeLists.txt branched on $ROS_VERSION.
    • package.xml: condition="$ROS_VERSION == 1" / "== 2" on the dependencies and on <build_type> in <export>.
    • CMakeLists.txt: keep the ROS1 lines byte-identical (no re-indentation), e.g. prepend the ROS2 build and wrap the original in else()/endif():
    if("$ENV{ROS_VERSION}" EQUAL 2)
      cmake_minimum_required(VERSION 3.8)
      project(foo)
      find_package(ament_cmake REQUIRED)
      find_package(jsk_ros1_ros2_compat REQUIRED)
      jsk_ros1_ros2_compat_install_python(PROGRAMS scripts/foo_node.py)
      ament_package()
    else() # if("$ENV{ROS_VERSION}" EQUAL 2)
    cmake_minimum_required(VERSION 2.8.3)
    project(foo)
    ...  # the ROS1 original, unchanged
    endif() # if("$ENV{ROS_VERSION}" EQUAL 2)
    
  • Python nodes call ros_compat.xxx(node, ...) instead of rospy.xxx(...), where node is None on ROS1 and the rclpy.node.Node on ROS2.

Python: jsk_ros1_ros2_compat.rospy_rclpy_compat

from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION

if __name__ == '__main__':
    node = ros_compat.init_node('foo')  # None on ROS1
    Foo(node)
    ros_compat.spin(node)

  ROS1 ROS2
get_param(node, '~name', default), has_param rospy.get_param declares a (dynamically typed) parameter
init_node(name, anonymous=False, multi_threaded=False) rospy.init_node, returns None rclpy.init() + a new node, returned (multi_threaded: see below)
spin(node), spin_once(node, timeout_sec), shutdown(node) (after an own while not is_shutdown(node) loop) rospy.spin, rospy.sleep, - spin_and_shutdown, rclpy.spin_once, cleanup
loginfo/logwarn/logerr/logdebug/logfatal(node, msg) rospy.log* node.get_logger().* (msg must be a str; node=None uses a logger named after the script)
loginfo/logwarn/logerr_throttle(node, period, msg), loginfo/logwarn/logerr_once(node, msg) like rospy.log*_throttle/_once like throttle_duration_sec=/once=True (per call site, done in compat)
create_publisher(node, topic, type, queue_size=1, latch=False) rospy.Publisher node.create_publisher (depth queue_size, default reliable QoS; latch: transient-local QoS; ~foo -> ~/foo)
create_subscription(node, topic, type, cb, queue_size=None, latch=False, callback_group=None, qos=None) rospy.Subscriber (None: unbounded; latch, qos ignored) node.create_subscription (None: depth 1; QoS: see below; ~foo -> ~/foo)
wait_for_service(node, name, type, timeout) (returns bool), set_param(node, name, value) rospy.wait_for_service, rospy.set_param a client’s wait_for_service, node.set_parameters
create_service, create_trigger_service, call_service, create_request/response, get_response_class (FooResponse(*values) on both) rospy.Service/ServiceProxy node.create_service/create_client
create_timer(node, period, cb) rospy.Timer node.create_timer (cb(None))
create_simple_action_client(node, name, type) actionlib.SimpleActionClient same subset over rclpy.action.ActionClient
create_simple_action_server(node, name, type, execute_cb) actionlib.SimpleActionServer same subset over rclpy.action.ActionServer
callback_group= of create_subscription/service/trigger_service/timer/simple_action_client/simple_action_server ignored (rospy runs each callback in its own thread) the rclpy callback group, e.g. ReentrantCallbackGroup() with a MultiThreadedExecutor
init_node(name, multi_threaded=True), for callbacks waiting for other callbacks (e.g. a service callback waiting for a topic) ignored (as above) create_* default to a ReentrantCallbackGroup and spin() uses a MultiThreadedExecutor
create_reconfigure_server(node, Config, cb, defaults) dynamic_reconfigure.server.Server parameters declared from defaults + on-set callback
now_sec, stamp_now, stamp_to_sec, duration_from_sec, sleep, Rate rospy.Time/Duration/... node.get_clock(), …
get_name, is_shutdown, on_shutdown, signal_shutdown rospy.* node name / rclpy context
create_tf_buffer_and_listener, create_tf_broadcaster tf2_ros tf2_ros with node
spin_and_shutdown(node, executor=None) - spin until SIGINT/SIGTERM/signal_shutdown, then clean up
private_name(name), message_type_name(msg), resolve_message_class('pkg/Type') name unchanged, msg._type, roslib.message ~foo -> ~/foo, 'pkg/Type', get_message (accepts pkg/Type and pkg/msg/Type)
declare_params(node, defaults), get_params(node, names) - ROS2 only: declare / read several parameters at once

QoS of create_subscription() on ROS2 (ignored on ROS1), from the qos argument:

qos QoS
None (default) 'any', or transient-local with depth queue_size if latch=True
'any' BEST_EFFORT + VOLATILE with depth queue_size: reads the topic of any publisher, whenever it joins
'best_available' BEST_AVAILABLE reliability and durability (Iron and later) of the publishers discovered when the subscription is created; a publisher with a weaker QoS that joins later is not read. Falls back to 'any' on Humble
a QoSProfile (e.g. rclpy.qos.qos_profile_sensor_data) as given
an int that depth, rclpy’s default (reliable) QoS

So by default a subscriber receives from both reliable and best-effort publishers, but delivery is best effort. Pass qos= (e.g. a depth for reliable delivery) where lost messages matter, and latch=True for the last message of a create_publisher(..., latch=True) topic.

File truncated at 100 lines see the full file

CHANGELOG

Changelog for package jsk_ros1_ros2_compat

3.0.5 (2026-11-10)

  • Merge pull request #1841 from k-okada/rosdistro-55117-review rosdistro#55117 review: add LICENSE to each package, use SPDX license identifiers
  • Merge pull request #1840 from k-okada/rhel-ambiguous-shebang Fix RHEL rpm build (ambiguous python shebang) of image_view2 and uv venv
  • use SPDX license identifiers (BSD-3-Clause, Apache-2.0) in package.xml BSD -> BSD-3-Clause and "Apache License 2.0" -> Apache-2.0 in all packages (ros/rosdistro#55117 review: "BSD is ambiguous. The headers show the 3-clause variant, so BSD-3-Clause (SPDX) is preferred."). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • add LICENSE to each package (BSD-3-Clause, jsk_tools: Apache-2.0) The ROS2 release review of jsk_common in ros/rosdistro#55117 says (https://github.com/ros/rosdistro/pull/55117#issuecomment-6757665510): > - [ ] At least one of the following must be present > - [ ] Top level license file: None. There is no LICENSE/COPYING at > the repo root (tree @ cbbd0ab). > - [ ] Per package license files: None. No package directory has a > license file. The license text only appears in source-file headers > (e.g. deprecated_relay.h#L1-L33, BSD-3-Clause, "JSK Lab"). Since jsk_tools is Apache-2.0 and the others are BSD-3-Clause, add a license file to each package instead of one at the top level. The BSD ones use the same text as the source headers, "Copyright (c) <year>-, JSK Lab" where <year> is when the package.xml was added, and jsk_tools has the Apache License 2.0 text from apache.org. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • jsk_ros1_ros2_compat: drop exec bits of python modules in uv venv (RHEL ambiguous shebang) Some wheels (e.g. protobuf's _parameterized.py) ship modules executable with a "#!/usr/bin/env python" shebang, which makes brp-mangle-shebangs fail the RHEL rpm build of packages using jsk_ros1_ros2_compat_generate_uv_venv(). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • Contributors: Kei Okada

3.0.4 (2026-11-04)

3.0.3 (2026-11-03)

  • Merge pull request #1835 from k-okada/ros-version-fallback-ament Fix ROS2 buildfarm binary jobs: ROS_VERSION without ros_environment, boost for jsk_topic_tools

  • Merge pull request #1834 from pazeshun/array-to-heatmap [jsk_ros1_ros2_compat, jsk_topic_tools, jsk_rosbag_tools] Add array heatmap tools with ROS 1 and ROS 2 support

  • Guess ROS_VERSION from AMENT_PREFIX_PATH when unset, depend on ros_environment The ROS2 binary jobs of the buildfarm failed at find_package(catkin): they install only the build dependencies, none of which pulls in ros_environment, so $ENV{ROS_VERSION} is empty and the fallback at the top of CMakeLists.txt chose ROS1.

    - package.xml: add a ROS2 buildtool_depend on ros_environment, which sets ROS_VERSION.

    - CMakeLists.txt: when ROS_VERSION is still unset, guess it from AMENT_PREFIX_PATH (bloom's ROS2 debian/rules passes it to cmake, setup.sh and colcon set the environment variable, catkin never does) instead of always assuming ROS1, and warn about it. jsk_tools had no fallback at all and gets the same block. Applies to jsk_ros1_ros2_compat, jsk_tools, jsk_topic_tools, jsk_common, jsk_data, jsk_rosbag_tools, dynamic_tf_publisher, audio_video_recorder and image_view2. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Merge pull request #1 from k-okada/array-to-heatmap-old-distros Support indigo/kinetic in array heatmap tools (OpenCV 2.4, numpy < 1.9, rosbag < 1.13)

  • [jsk_ros1_ros2_compat] rosbag: raw messages with connection headers on rosbag < 1.13 rosbag of indigo/kinetic has neither read_messages(..., return_connection_header=) nor write(..., connection_header=), which failed test_add_heatmap on the kinetic CI. There, read_raw_messages() takes the header of each topic's connection from the bag, and write_raw() registers a new topic's connection with the given header before writing, as write(..., connection_header=) does on newer rosbag. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Add array heatmap tools with ROS 1 and ROS 2 support

    • Render numeric MultiArray and scalar Image topics as heatmap images with optional cell values and configurable color scales
    • Add heatmap topics to bags while preserving original messages, recording timestamps, and connection or QoS metadata
    • Extend the compatibility layer with raw bag I/O and shared message type helpers
    • Add installation rules, documentation, and tests for both ROS versions
  • Merge pull request

File truncated at 100 lines see the full file

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged jsk_ros1_ros2_compat at Robotics Stack Exchange

Package Summary

Version 3.0.5
License BSD-3-Clause
Build type CATKIN
Use RECOMMENDED

Repository Summary

Description
Checkout URI https://github.com/jsk-ros-pkg/jsk_common.git
VCS Type git
VCS Version master
Last Updated 2026-11-18
Dev Status UNKNOWN
Released RELEASED
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Package Description

Shared ROS1(roscpp/rospy)/ROS2(rclcpp/rclpy) compatibility helpers used across jsk_common's ROS2-ported packages, so that individual packages don't each maintain their own copy.

Maintainers

  • Kei Okada

Authors

No additional authors.

jsk_ros1_ros2_compat

Shared ROS1 (roscpp/rospy) / ROS2 (rclcpp/rclpy) compatibility helpers, so that a package can keep one source tree that builds and runs on both, with the ROS1 code left as close to the original as possible.

ROS 1 / ROS 2

This is a library package (no nodes, scripts or launch files). It builds for both ROS 1 (catkin) and ROS 2 (ament), selected by $ROS_VERSION:

  ROS 1 ROS 2
C++ headers (include/jsk_ros1_ros2_compat/*.h) yes yes
Python package jsk_ros1_ros2_compat (rospy_rclpy_compat, rosbag, log_utils) yes yes
CMake jsk_ros1_ros2_compat_install_python() defined, but meant for ROS 2 builds yes
CMake jsk_ros1_ros2_compat_generate_uv_venv() and the bundled uv binary (lib/jsk_ros1_ros2_compat/uv) no (use catkin_virtualenv) yes

ROS_VERSION in the Python modules is read from the ROS_VERSION environment variable (default 1). The C++ headers detect ROS 1 by whether <ros/ros.h> can be included, so no compile definition is needed.

Porting style

  • One package.xml / CMakeLists.txt branched on $ROS_VERSION.
    • package.xml: condition="$ROS_VERSION == 1" / "== 2" on the dependencies and on <build_type> in <export>.
    • CMakeLists.txt: keep the ROS1 lines byte-identical (no re-indentation), e.g. prepend the ROS2 build and wrap the original in else()/endif():
    if("$ENV{ROS_VERSION}" EQUAL 2)
      cmake_minimum_required(VERSION 3.8)
      project(foo)
      find_package(ament_cmake REQUIRED)
      find_package(jsk_ros1_ros2_compat REQUIRED)
      jsk_ros1_ros2_compat_install_python(PROGRAMS scripts/foo_node.py)
      ament_package()
    else() # if("$ENV{ROS_VERSION}" EQUAL 2)
    cmake_minimum_required(VERSION 2.8.3)
    project(foo)
    ...  # the ROS1 original, unchanged
    endif() # if("$ENV{ROS_VERSION}" EQUAL 2)
    
  • Python nodes call ros_compat.xxx(node, ...) instead of rospy.xxx(...), where node is None on ROS1 and the rclpy.node.Node on ROS2.

Python: jsk_ros1_ros2_compat.rospy_rclpy_compat

from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION

if __name__ == '__main__':
    node = ros_compat.init_node('foo')  # None on ROS1
    Foo(node)
    ros_compat.spin(node)

  ROS1 ROS2
get_param(node, '~name', default), has_param rospy.get_param declares a (dynamically typed) parameter
init_node(name, anonymous=False, multi_threaded=False) rospy.init_node, returns None rclpy.init() + a new node, returned (multi_threaded: see below)
spin(node), spin_once(node, timeout_sec), shutdown(node) (after an own while not is_shutdown(node) loop) rospy.spin, rospy.sleep, - spin_and_shutdown, rclpy.spin_once, cleanup
loginfo/logwarn/logerr/logdebug/logfatal(node, msg) rospy.log* node.get_logger().* (msg must be a str; node=None uses a logger named after the script)
loginfo/logwarn/logerr_throttle(node, period, msg), loginfo/logwarn/logerr_once(node, msg) like rospy.log*_throttle/_once like throttle_duration_sec=/once=True (per call site, done in compat)
create_publisher(node, topic, type, queue_size=1, latch=False) rospy.Publisher node.create_publisher (depth queue_size, default reliable QoS; latch: transient-local QoS; ~foo -> ~/foo)
create_subscription(node, topic, type, cb, queue_size=None, latch=False, callback_group=None, qos=None) rospy.Subscriber (None: unbounded; latch, qos ignored) node.create_subscription (None: depth 1; QoS: see below; ~foo -> ~/foo)
wait_for_service(node, name, type, timeout) (returns bool), set_param(node, name, value) rospy.wait_for_service, rospy.set_param a client’s wait_for_service, node.set_parameters
create_service, create_trigger_service, call_service, create_request/response, get_response_class (FooResponse(*values) on both) rospy.Service/ServiceProxy node.create_service/create_client
create_timer(node, period, cb) rospy.Timer node.create_timer (cb(None))
create_simple_action_client(node, name, type) actionlib.SimpleActionClient same subset over rclpy.action.ActionClient
create_simple_action_server(node, name, type, execute_cb) actionlib.SimpleActionServer same subset over rclpy.action.ActionServer
callback_group= of create_subscription/service/trigger_service/timer/simple_action_client/simple_action_server ignored (rospy runs each callback in its own thread) the rclpy callback group, e.g. ReentrantCallbackGroup() with a MultiThreadedExecutor
init_node(name, multi_threaded=True), for callbacks waiting for other callbacks (e.g. a service callback waiting for a topic) ignored (as above) create_* default to a ReentrantCallbackGroup and spin() uses a MultiThreadedExecutor
create_reconfigure_server(node, Config, cb, defaults) dynamic_reconfigure.server.Server parameters declared from defaults + on-set callback
now_sec, stamp_now, stamp_to_sec, duration_from_sec, sleep, Rate rospy.Time/Duration/... node.get_clock(), …
get_name, is_shutdown, on_shutdown, signal_shutdown rospy.* node name / rclpy context
create_tf_buffer_and_listener, create_tf_broadcaster tf2_ros tf2_ros with node
spin_and_shutdown(node, executor=None) - spin until SIGINT/SIGTERM/signal_shutdown, then clean up
private_name(name), message_type_name(msg), resolve_message_class('pkg/Type') name unchanged, msg._type, roslib.message ~foo -> ~/foo, 'pkg/Type', get_message (accepts pkg/Type and pkg/msg/Type)
declare_params(node, defaults), get_params(node, names) - ROS2 only: declare / read several parameters at once

QoS of create_subscription() on ROS2 (ignored on ROS1), from the qos argument:

qos QoS
None (default) 'any', or transient-local with depth queue_size if latch=True
'any' BEST_EFFORT + VOLATILE with depth queue_size: reads the topic of any publisher, whenever it joins
'best_available' BEST_AVAILABLE reliability and durability (Iron and later) of the publishers discovered when the subscription is created; a publisher with a weaker QoS that joins later is not read. Falls back to 'any' on Humble
a QoSProfile (e.g. rclpy.qos.qos_profile_sensor_data) as given
an int that depth, rclpy’s default (reliable) QoS

So by default a subscriber receives from both reliable and best-effort publishers, but delivery is best effort. Pass qos= (e.g. a depth for reliable delivery) where lost messages matter, and latch=True for the last message of a create_publisher(..., latch=True) topic.

File truncated at 100 lines see the full file

CHANGELOG

Changelog for package jsk_ros1_ros2_compat

3.0.5 (2026-11-10)

  • Merge pull request #1841 from k-okada/rosdistro-55117-review rosdistro#55117 review: add LICENSE to each package, use SPDX license identifiers
  • Merge pull request #1840 from k-okada/rhel-ambiguous-shebang Fix RHEL rpm build (ambiguous python shebang) of image_view2 and uv venv
  • use SPDX license identifiers (BSD-3-Clause, Apache-2.0) in package.xml BSD -> BSD-3-Clause and "Apache License 2.0" -> Apache-2.0 in all packages (ros/rosdistro#55117 review: "BSD is ambiguous. The headers show the 3-clause variant, so BSD-3-Clause (SPDX) is preferred."). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • add LICENSE to each package (BSD-3-Clause, jsk_tools: Apache-2.0) The ROS2 release review of jsk_common in ros/rosdistro#55117 says (https://github.com/ros/rosdistro/pull/55117#issuecomment-6757665510): > - [ ] At least one of the following must be present > - [ ] Top level license file: None. There is no LICENSE/COPYING at > the repo root (tree @ cbbd0ab). > - [ ] Per package license files: None. No package directory has a > license file. The license text only appears in source-file headers > (e.g. deprecated_relay.h#L1-L33, BSD-3-Clause, "JSK Lab"). Since jsk_tools is Apache-2.0 and the others are BSD-3-Clause, add a license file to each package instead of one at the top level. The BSD ones use the same text as the source headers, "Copyright (c) <year>-, JSK Lab" where <year> is when the package.xml was added, and jsk_tools has the Apache License 2.0 text from apache.org. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • jsk_ros1_ros2_compat: drop exec bits of python modules in uv venv (RHEL ambiguous shebang) Some wheels (e.g. protobuf's _parameterized.py) ship modules executable with a "#!/usr/bin/env python" shebang, which makes brp-mangle-shebangs fail the RHEL rpm build of packages using jsk_ros1_ros2_compat_generate_uv_venv(). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • Contributors: Kei Okada

3.0.4 (2026-11-04)

3.0.3 (2026-11-03)

  • Merge pull request #1835 from k-okada/ros-version-fallback-ament Fix ROS2 buildfarm binary jobs: ROS_VERSION without ros_environment, boost for jsk_topic_tools

  • Merge pull request #1834 from pazeshun/array-to-heatmap [jsk_ros1_ros2_compat, jsk_topic_tools, jsk_rosbag_tools] Add array heatmap tools with ROS 1 and ROS 2 support

  • Guess ROS_VERSION from AMENT_PREFIX_PATH when unset, depend on ros_environment The ROS2 binary jobs of the buildfarm failed at find_package(catkin): they install only the build dependencies, none of which pulls in ros_environment, so $ENV{ROS_VERSION} is empty and the fallback at the top of CMakeLists.txt chose ROS1.

    - package.xml: add a ROS2 buildtool_depend on ros_environment, which sets ROS_VERSION.

    - CMakeLists.txt: when ROS_VERSION is still unset, guess it from AMENT_PREFIX_PATH (bloom's ROS2 debian/rules passes it to cmake, setup.sh and colcon set the environment variable, catkin never does) instead of always assuming ROS1, and warn about it. jsk_tools had no fallback at all and gets the same block. Applies to jsk_ros1_ros2_compat, jsk_tools, jsk_topic_tools, jsk_common, jsk_data, jsk_rosbag_tools, dynamic_tf_publisher, audio_video_recorder and image_view2. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Merge pull request #1 from k-okada/array-to-heatmap-old-distros Support indigo/kinetic in array heatmap tools (OpenCV 2.4, numpy < 1.9, rosbag < 1.13)

  • [jsk_ros1_ros2_compat] rosbag: raw messages with connection headers on rosbag < 1.13 rosbag of indigo/kinetic has neither read_messages(..., return_connection_header=) nor write(..., connection_header=), which failed test_add_heatmap on the kinetic CI. There, read_raw_messages() takes the header of each topic's connection from the bag, and write_raw() registers a new topic's connection with the given header before writing, as write(..., connection_header=) does on newer rosbag. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Add array heatmap tools with ROS 1 and ROS 2 support

    • Render numeric MultiArray and scalar Image topics as heatmap images with optional cell values and configurable color scales
    • Add heatmap topics to bags while preserving original messages, recording timestamps, and connection or QoS metadata
    • Extend the compatibility layer with raw bag I/O and shared message type helpers
    • Add installation rules, documentation, and tests for both ROS versions
  • Merge pull request

File truncated at 100 lines see the full file

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged jsk_ros1_ros2_compat at Robotics Stack Exchange

Package Summary

Version 3.0.5
License BSD-3-Clause
Build type CATKIN
Use RECOMMENDED

Repository Summary

Description
Checkout URI https://github.com/jsk-ros-pkg/jsk_common.git
VCS Type git
VCS Version 3.0.5
Last Updated 2026-11-10
Dev Status UNKNOWN
Released RELEASED
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Package Description

Shared ROS1(roscpp/rospy)/ROS2(rclcpp/rclpy) compatibility helpers used across jsk_common's ROS2-ported packages, so that individual packages don't each maintain their own copy.

Maintainers

  • Kei Okada

Authors

No additional authors.

jsk_ros1_ros2_compat

Shared ROS1 (roscpp/rospy) / ROS2 (rclcpp/rclpy) compatibility helpers, so that a package can keep one source tree that builds and runs on both, with the ROS1 code left as close to the original as possible.

Porting style

  • One package.xml / CMakeLists.txt branched on $ROS_VERSION.
    • package.xml: condition="$ROS_VERSION == 1" / "== 2" on the dependencies and on <build_type> in <export>.
    • CMakeLists.txt: keep the ROS1 lines byte-identical (no re-indentation), e.g. prepend the ROS2 build and wrap the original in else()/endif():
    if("$ENV{ROS_VERSION}" EQUAL 2)
      cmake_minimum_required(VERSION 3.8)
      project(foo)
      find_package(ament_cmake REQUIRED)
      find_package(jsk_ros1_ros2_compat REQUIRED)
      jsk_ros1_ros2_compat_install_python(PROGRAMS scripts/foo_node.py)
      ament_package()
    else() # if("$ENV{ROS_VERSION}" EQUAL 2)
    cmake_minimum_required(VERSION 2.8.3)
    project(foo)
    ...  # the ROS1 original, unchanged
    endif() # if("$ENV{ROS_VERSION}" EQUAL 2)
    
  • Python nodes call ros_compat.xxx(node, ...) instead of rospy.xxx(...), where node is None on ROS1 and the rclpy.node.Node on ROS2.

Python: jsk_ros1_ros2_compat.rospy_rclpy_compat

from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION

if __name__ == '__main__':
    node = ros_compat.init_node('foo')  # None on ROS1
    Foo(node)
    ros_compat.spin(node)

  ROS1 ROS2
get_param(node, '~name', default), has_param rospy.get_param declares a (dynamically typed) parameter
init_node(name, anonymous=False, multi_threaded=False) rospy.init_node, returns None rclpy.init() + a new node, returned (multi_threaded: see below)
spin(node), spin_once(node, timeout_sec), shutdown(node) (after an own while not is_shutdown(node) loop) rospy.spin, rospy.sleep, - spin_and_shutdown, rclpy.spin_once, cleanup
loginfo/logwarn/logerr/logdebug/logfatal(node, msg) rospy.log* node.get_logger().* (msg must be a str; node=None uses a logger named after the script)
loginfo/logwarn/logerr_throttle(node, period, msg), loginfo/logwarn/logerr_once(node, msg) like rospy.log*_throttle/_once like throttle_duration_sec=/once=True (per call site, done in compat)
create_publisher(node, topic, type, queue_size=1, latch=False) rospy.Publisher node.create_publisher (latch: transient-local QoS)
create_subscription(node, topic, type, cb, queue_size=None, latch=False) rospy.Subscriber (None: unbounded) node.create_subscription (None: depth 1; latch: transient-local QoS; ~foo -> ~/foo)
wait_for_service(node, name, type, timeout) (returns bool), set_param(node, name, value) rospy.wait_for_service, rospy.set_param a client’s wait_for_service, node.set_parameters
create_service, create_trigger_service, call_service, create_request/response, get_response_class (FooResponse(*values) on both) rospy.Service/ServiceProxy node.create_service/create_client
create_timer(node, period, cb) rospy.Timer node.create_timer (cb(None))
create_simple_action_client(node, name, type) actionlib.SimpleActionClient same subset over rclpy.action.ActionClient
create_simple_action_server(node, name, type, execute_cb) actionlib.SimpleActionServer same subset over rclpy.action.ActionServer
callback_group= of create_subscription/service/trigger_service/timer/simple_action_client/simple_action_server ignored (rospy runs each callback in its own thread) the rclpy callback group, e.g. ReentrantCallbackGroup() with a MultiThreadedExecutor
init_node(name, multi_threaded=True), for callbacks waiting for other callbacks (e.g. a service callback waiting for a topic) ignored (as above) create_* default to a ReentrantCallbackGroup and spin() uses a MultiThreadedExecutor
create_reconfigure_server(node, Config, cb, defaults) dynamic_reconfigure.server.Server parameters declared from defaults + on-set callback
now_sec, stamp_now, stamp_to_sec, duration_from_sec, sleep, Rate rospy.Time/Duration/... node.get_clock(), …
get_name, is_shutdown, on_shutdown, signal_shutdown rospy.* node name / rclpy context
create_tf_buffer_and_listener, create_tf_broadcaster tf2_ros tf2_ros with node
spin_and_shutdown(node, executor=None) - spin until SIGINT/SIGTERM/signal_shutdown, then clean up

Action types: pass FooAction/FooGoal on ROS1 and Foo/Foo.Goal on ROS2; timeouts are in seconds on both. actionlib/dynamic_reconfigure are imported lazily, so depend on them in your own package.

Packages outside jsk_common

jsk_ros1_ros2_compat is only released with jsk_common >= 3.0, which is not available for every ROS1 distro. Depend on it for ROS2 only and fall back to rospy when it can not be imported, listing just the functions you use:

<exec_depend condition="$ROS_VERSION == 2">jsk_ros1_ros2_compat</exec_depend>

try:
    from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
    from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION
except ImportError:
    # jsk_common < 3.0 has no jsk_ros1_ros2_compat, so this is ROS1 only:
    # forward ros_compat.xxx(node, ...) to rospy.xxx(...)
    import rospy
    ROS_VERSION = 1
    class ros_compat(object):
        get_param = staticmethod(lambda node, *args, **kwargs: rospy.get_param(*args, **kwargs))
        loginfo = staticmethod(lambda node, *args, **kwargs: rospy.loginfo(*args, **kwargs))

Or, to keep the original rospy code untouched for its ROS1 users, add a jsk_ros1_ros2_compat version next to it and choose by whether jsk_ros1_ros2_compat can be imported (not by ROS_VERSION):

```python try:

File truncated at 100 lines see the full file

CHANGELOG

Changelog for package jsk_ros1_ros2_compat

3.0.5 (2026-11-10)

  • Merge pull request #1841 from k-okada/rosdistro-55117-review rosdistro#55117 review: add LICENSE to each package, use SPDX license identifiers
  • Merge pull request #1840 from k-okada/rhel-ambiguous-shebang Fix RHEL rpm build (ambiguous python shebang) of image_view2 and uv venv
  • use SPDX license identifiers (BSD-3-Clause, Apache-2.0) in package.xml BSD -> BSD-3-Clause and "Apache License 2.0" -> Apache-2.0 in all packages (ros/rosdistro#55117 review: "BSD is ambiguous. The headers show the 3-clause variant, so BSD-3-Clause (SPDX) is preferred."). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • add LICENSE to each package (BSD-3-Clause, jsk_tools: Apache-2.0) The ROS2 release review of jsk_common in ros/rosdistro#55117 says (https://github.com/ros/rosdistro/pull/55117#issuecomment-6757665510): > - [ ] At least one of the following must be present > - [ ] Top level license file: None. There is no LICENSE/COPYING at > the repo root (tree @ cbbd0ab). > - [ ] Per package license files: None. No package directory has a > license file. The license text only appears in source-file headers > (e.g. deprecated_relay.h#L1-L33, BSD-3-Clause, "JSK Lab"). Since jsk_tools is Apache-2.0 and the others are BSD-3-Clause, add a license file to each package instead of one at the top level. The BSD ones use the same text as the source headers, "Copyright (c) <year>-, JSK Lab" where <year> is when the package.xml was added, and jsk_tools has the Apache License 2.0 text from apache.org. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • jsk_ros1_ros2_compat: drop exec bits of python modules in uv venv (RHEL ambiguous shebang) Some wheels (e.g. protobuf's _parameterized.py) ship modules executable with a "#!/usr/bin/env python" shebang, which makes brp-mangle-shebangs fail the RHEL rpm build of packages using jsk_ros1_ros2_compat_generate_uv_venv(). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • Contributors: Kei Okada

3.0.4 (2026-11-04)

3.0.3 (2026-11-03)

  • Merge pull request #1835 from k-okada/ros-version-fallback-ament Fix ROS2 buildfarm binary jobs: ROS_VERSION without ros_environment, boost for jsk_topic_tools

  • Merge pull request #1834 from pazeshun/array-to-heatmap [jsk_ros1_ros2_compat, jsk_topic_tools, jsk_rosbag_tools] Add array heatmap tools with ROS 1 and ROS 2 support

  • Guess ROS_VERSION from AMENT_PREFIX_PATH when unset, depend on ros_environment The ROS2 binary jobs of the buildfarm failed at find_package(catkin): they install only the build dependencies, none of which pulls in ros_environment, so $ENV{ROS_VERSION} is empty and the fallback at the top of CMakeLists.txt chose ROS1.

    - package.xml: add a ROS2 buildtool_depend on ros_environment, which sets ROS_VERSION.

    - CMakeLists.txt: when ROS_VERSION is still unset, guess it from AMENT_PREFIX_PATH (bloom's ROS2 debian/rules passes it to cmake, setup.sh and colcon set the environment variable, catkin never does) instead of always assuming ROS1, and warn about it. jsk_tools had no fallback at all and gets the same block. Applies to jsk_ros1_ros2_compat, jsk_tools, jsk_topic_tools, jsk_common, jsk_data, jsk_rosbag_tools, dynamic_tf_publisher, audio_video_recorder and image_view2. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Merge pull request #1 from k-okada/array-to-heatmap-old-distros Support indigo/kinetic in array heatmap tools (OpenCV 2.4, numpy < 1.9, rosbag < 1.13)

  • [jsk_ros1_ros2_compat] rosbag: raw messages with connection headers on rosbag < 1.13 rosbag of indigo/kinetic has neither read_messages(..., return_connection_header=) nor write(..., connection_header=), which failed test_add_heatmap on the kinetic CI. There, read_raw_messages() takes the header of each topic's connection from the bag, and write_raw() registers a new topic's connection with the given header before writing, as write(..., connection_header=) does on newer rosbag. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Add array heatmap tools with ROS 1 and ROS 2 support

    • Render numeric MultiArray and scalar Image topics as heatmap images with optional cell values and configurable color scales
    • Add heatmap topics to bags while preserving original messages, recording timestamps, and connection or QoS metadata
    • Extend the compatibility layer with raw bag I/O and shared message type helpers
    • Add installation rules, documentation, and tests for both ROS versions
  • Merge pull request

File truncated at 100 lines see the full file

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged jsk_ros1_ros2_compat at Robotics Stack Exchange

No version for distro github showing jazzy. Known supported distros are highlighted in the buttons above.

Package Summary

Version 3.0.5
License BSD-3-Clause
Build type CATKIN
Use RECOMMENDED

Repository Summary

Description
Checkout URI https://github.com/jsk-ros-pkg/jsk_common.git
VCS Type git
VCS Version 3.0.5
Last Updated 2026-11-10
Dev Status UNKNOWN
Released RELEASED
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Package Description

Shared ROS1(roscpp/rospy)/ROS2(rclcpp/rclpy) compatibility helpers used across jsk_common's ROS2-ported packages, so that individual packages don't each maintain their own copy.

Maintainers

  • Kei Okada

Authors

No additional authors.

jsk_ros1_ros2_compat

Shared ROS1 (roscpp/rospy) / ROS2 (rclcpp/rclpy) compatibility helpers, so that a package can keep one source tree that builds and runs on both, with the ROS1 code left as close to the original as possible.

Porting style

  • One package.xml / CMakeLists.txt branched on $ROS_VERSION.
    • package.xml: condition="$ROS_VERSION == 1" / "== 2" on the dependencies and on <build_type> in <export>.
    • CMakeLists.txt: keep the ROS1 lines byte-identical (no re-indentation), e.g. prepend the ROS2 build and wrap the original in else()/endif():
    if("$ENV{ROS_VERSION}" EQUAL 2)
      cmake_minimum_required(VERSION 3.8)
      project(foo)
      find_package(ament_cmake REQUIRED)
      find_package(jsk_ros1_ros2_compat REQUIRED)
      jsk_ros1_ros2_compat_install_python(PROGRAMS scripts/foo_node.py)
      ament_package()
    else() # if("$ENV{ROS_VERSION}" EQUAL 2)
    cmake_minimum_required(VERSION 2.8.3)
    project(foo)
    ...  # the ROS1 original, unchanged
    endif() # if("$ENV{ROS_VERSION}" EQUAL 2)
    
  • Python nodes call ros_compat.xxx(node, ...) instead of rospy.xxx(...), where node is None on ROS1 and the rclpy.node.Node on ROS2.

Python: jsk_ros1_ros2_compat.rospy_rclpy_compat

from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION

if __name__ == '__main__':
    node = ros_compat.init_node('foo')  # None on ROS1
    Foo(node)
    ros_compat.spin(node)

  ROS1 ROS2
get_param(node, '~name', default), has_param rospy.get_param declares a (dynamically typed) parameter
init_node(name, anonymous=False, multi_threaded=False) rospy.init_node, returns None rclpy.init() + a new node, returned (multi_threaded: see below)
spin(node), spin_once(node, timeout_sec), shutdown(node) (after an own while not is_shutdown(node) loop) rospy.spin, rospy.sleep, - spin_and_shutdown, rclpy.spin_once, cleanup
loginfo/logwarn/logerr/logdebug/logfatal(node, msg) rospy.log* node.get_logger().* (msg must be a str; node=None uses a logger named after the script)
loginfo/logwarn/logerr_throttle(node, period, msg), loginfo/logwarn/logerr_once(node, msg) like rospy.log*_throttle/_once like throttle_duration_sec=/once=True (per call site, done in compat)
create_publisher(node, topic, type, queue_size=1, latch=False) rospy.Publisher node.create_publisher (latch: transient-local QoS)
create_subscription(node, topic, type, cb, queue_size=None, latch=False) rospy.Subscriber (None: unbounded) node.create_subscription (None: depth 1; latch: transient-local QoS; ~foo -> ~/foo)
wait_for_service(node, name, type, timeout) (returns bool), set_param(node, name, value) rospy.wait_for_service, rospy.set_param a client’s wait_for_service, node.set_parameters
create_service, create_trigger_service, call_service, create_request/response, get_response_class (FooResponse(*values) on both) rospy.Service/ServiceProxy node.create_service/create_client
create_timer(node, period, cb) rospy.Timer node.create_timer (cb(None))
create_simple_action_client(node, name, type) actionlib.SimpleActionClient same subset over rclpy.action.ActionClient
create_simple_action_server(node, name, type, execute_cb) actionlib.SimpleActionServer same subset over rclpy.action.ActionServer
callback_group= of create_subscription/service/trigger_service/timer/simple_action_client/simple_action_server ignored (rospy runs each callback in its own thread) the rclpy callback group, e.g. ReentrantCallbackGroup() with a MultiThreadedExecutor
init_node(name, multi_threaded=True), for callbacks waiting for other callbacks (e.g. a service callback waiting for a topic) ignored (as above) create_* default to a ReentrantCallbackGroup and spin() uses a MultiThreadedExecutor
create_reconfigure_server(node, Config, cb, defaults) dynamic_reconfigure.server.Server parameters declared from defaults + on-set callback
now_sec, stamp_now, stamp_to_sec, duration_from_sec, sleep, Rate rospy.Time/Duration/... node.get_clock(), …
get_name, is_shutdown, on_shutdown, signal_shutdown rospy.* node name / rclpy context
create_tf_buffer_and_listener, create_tf_broadcaster tf2_ros tf2_ros with node
spin_and_shutdown(node, executor=None) - spin until SIGINT/SIGTERM/signal_shutdown, then clean up

Action types: pass FooAction/FooGoal on ROS1 and Foo/Foo.Goal on ROS2; timeouts are in seconds on both. actionlib/dynamic_reconfigure are imported lazily, so depend on them in your own package.

Packages outside jsk_common

jsk_ros1_ros2_compat is only released with jsk_common >= 3.0, which is not available for every ROS1 distro. Depend on it for ROS2 only and fall back to rospy when it can not be imported, listing just the functions you use:

<exec_depend condition="$ROS_VERSION == 2">jsk_ros1_ros2_compat</exec_depend>

try:
    from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
    from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION
except ImportError:
    # jsk_common < 3.0 has no jsk_ros1_ros2_compat, so this is ROS1 only:
    # forward ros_compat.xxx(node, ...) to rospy.xxx(...)
    import rospy
    ROS_VERSION = 1
    class ros_compat(object):
        get_param = staticmethod(lambda node, *args, **kwargs: rospy.get_param(*args, **kwargs))
        loginfo = staticmethod(lambda node, *args, **kwargs: rospy.loginfo(*args, **kwargs))

Or, to keep the original rospy code untouched for its ROS1 users, add a jsk_ros1_ros2_compat version next to it and choose by whether jsk_ros1_ros2_compat can be imported (not by ROS_VERSION):

```python try:

File truncated at 100 lines see the full file

CHANGELOG

Changelog for package jsk_ros1_ros2_compat

3.0.5 (2026-11-10)

  • Merge pull request #1841 from k-okada/rosdistro-55117-review rosdistro#55117 review: add LICENSE to each package, use SPDX license identifiers
  • Merge pull request #1840 from k-okada/rhel-ambiguous-shebang Fix RHEL rpm build (ambiguous python shebang) of image_view2 and uv venv
  • use SPDX license identifiers (BSD-3-Clause, Apache-2.0) in package.xml BSD -> BSD-3-Clause and "Apache License 2.0" -> Apache-2.0 in all packages (ros/rosdistro#55117 review: "BSD is ambiguous. The headers show the 3-clause variant, so BSD-3-Clause (SPDX) is preferred."). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • add LICENSE to each package (BSD-3-Clause, jsk_tools: Apache-2.0) The ROS2 release review of jsk_common in ros/rosdistro#55117 says (https://github.com/ros/rosdistro/pull/55117#issuecomment-6757665510): > - [ ] At least one of the following must be present > - [ ] Top level license file: None. There is no LICENSE/COPYING at > the repo root (tree @ cbbd0ab). > - [ ] Per package license files: None. No package directory has a > license file. The license text only appears in source-file headers > (e.g. deprecated_relay.h#L1-L33, BSD-3-Clause, "JSK Lab"). Since jsk_tools is Apache-2.0 and the others are BSD-3-Clause, add a license file to each package instead of one at the top level. The BSD ones use the same text as the source headers, "Copyright (c) <year>-, JSK Lab" where <year> is when the package.xml was added, and jsk_tools has the Apache License 2.0 text from apache.org. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • jsk_ros1_ros2_compat: drop exec bits of python modules in uv venv (RHEL ambiguous shebang) Some wheels (e.g. protobuf's _parameterized.py) ship modules executable with a "#!/usr/bin/env python" shebang, which makes brp-mangle-shebangs fail the RHEL rpm build of packages using jsk_ros1_ros2_compat_generate_uv_venv(). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • Contributors: Kei Okada

3.0.4 (2026-11-04)

3.0.3 (2026-11-03)

  • Merge pull request #1835 from k-okada/ros-version-fallback-ament Fix ROS2 buildfarm binary jobs: ROS_VERSION without ros_environment, boost for jsk_topic_tools

  • Merge pull request #1834 from pazeshun/array-to-heatmap [jsk_ros1_ros2_compat, jsk_topic_tools, jsk_rosbag_tools] Add array heatmap tools with ROS 1 and ROS 2 support

  • Guess ROS_VERSION from AMENT_PREFIX_PATH when unset, depend on ros_environment The ROS2 binary jobs of the buildfarm failed at find_package(catkin): they install only the build dependencies, none of which pulls in ros_environment, so $ENV{ROS_VERSION} is empty and the fallback at the top of CMakeLists.txt chose ROS1.

    - package.xml: add a ROS2 buildtool_depend on ros_environment, which sets ROS_VERSION.

    - CMakeLists.txt: when ROS_VERSION is still unset, guess it from AMENT_PREFIX_PATH (bloom's ROS2 debian/rules passes it to cmake, setup.sh and colcon set the environment variable, catkin never does) instead of always assuming ROS1, and warn about it. jsk_tools had no fallback at all and gets the same block. Applies to jsk_ros1_ros2_compat, jsk_tools, jsk_topic_tools, jsk_common, jsk_data, jsk_rosbag_tools, dynamic_tf_publisher, audio_video_recorder and image_view2. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Merge pull request #1 from k-okada/array-to-heatmap-old-distros Support indigo/kinetic in array heatmap tools (OpenCV 2.4, numpy < 1.9, rosbag < 1.13)

  • [jsk_ros1_ros2_compat] rosbag: raw messages with connection headers on rosbag < 1.13 rosbag of indigo/kinetic has neither read_messages(..., return_connection_header=) nor write(..., connection_header=), which failed test_add_heatmap on the kinetic CI. There, read_raw_messages() takes the header of each topic's connection from the bag, and write_raw() registers a new topic's connection with the given header before writing, as write(..., connection_header=) does on newer rosbag. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Add array heatmap tools with ROS 1 and ROS 2 support

    • Render numeric MultiArray and scalar Image topics as heatmap images with optional cell values and configurable color scales
    • Add heatmap topics to bags while preserving original messages, recording timestamps, and connection or QoS metadata
    • Extend the compatibility layer with raw bag I/O and shared message type helpers
    • Add installation rules, documentation, and tests for both ROS versions
  • Merge pull request

File truncated at 100 lines see the full file

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged jsk_ros1_ros2_compat at Robotics Stack Exchange

No version for distro galactic showing jazzy. Known supported distros are highlighted in the buttons above.

Package Summary

Version 3.0.5
License BSD-3-Clause
Build type CATKIN
Use RECOMMENDED

Repository Summary

Description
Checkout URI https://github.com/jsk-ros-pkg/jsk_common.git
VCS Type git
VCS Version 3.0.5
Last Updated 2026-11-10
Dev Status UNKNOWN
Released RELEASED
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Package Description

Shared ROS1(roscpp/rospy)/ROS2(rclcpp/rclpy) compatibility helpers used across jsk_common's ROS2-ported packages, so that individual packages don't each maintain their own copy.

Maintainers

  • Kei Okada

Authors

No additional authors.

jsk_ros1_ros2_compat

Shared ROS1 (roscpp/rospy) / ROS2 (rclcpp/rclpy) compatibility helpers, so that a package can keep one source tree that builds and runs on both, with the ROS1 code left as close to the original as possible.

Porting style

  • One package.xml / CMakeLists.txt branched on $ROS_VERSION.
    • package.xml: condition="$ROS_VERSION == 1" / "== 2" on the dependencies and on <build_type> in <export>.
    • CMakeLists.txt: keep the ROS1 lines byte-identical (no re-indentation), e.g. prepend the ROS2 build and wrap the original in else()/endif():
    if("$ENV{ROS_VERSION}" EQUAL 2)
      cmake_minimum_required(VERSION 3.8)
      project(foo)
      find_package(ament_cmake REQUIRED)
      find_package(jsk_ros1_ros2_compat REQUIRED)
      jsk_ros1_ros2_compat_install_python(PROGRAMS scripts/foo_node.py)
      ament_package()
    else() # if("$ENV{ROS_VERSION}" EQUAL 2)
    cmake_minimum_required(VERSION 2.8.3)
    project(foo)
    ...  # the ROS1 original, unchanged
    endif() # if("$ENV{ROS_VERSION}" EQUAL 2)
    
  • Python nodes call ros_compat.xxx(node, ...) instead of rospy.xxx(...), where node is None on ROS1 and the rclpy.node.Node on ROS2.

Python: jsk_ros1_ros2_compat.rospy_rclpy_compat

from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION

if __name__ == '__main__':
    node = ros_compat.init_node('foo')  # None on ROS1
    Foo(node)
    ros_compat.spin(node)

  ROS1 ROS2
get_param(node, '~name', default), has_param rospy.get_param declares a (dynamically typed) parameter
init_node(name, anonymous=False, multi_threaded=False) rospy.init_node, returns None rclpy.init() + a new node, returned (multi_threaded: see below)
spin(node), spin_once(node, timeout_sec), shutdown(node) (after an own while not is_shutdown(node) loop) rospy.spin, rospy.sleep, - spin_and_shutdown, rclpy.spin_once, cleanup
loginfo/logwarn/logerr/logdebug/logfatal(node, msg) rospy.log* node.get_logger().* (msg must be a str; node=None uses a logger named after the script)
loginfo/logwarn/logerr_throttle(node, period, msg), loginfo/logwarn/logerr_once(node, msg) like rospy.log*_throttle/_once like throttle_duration_sec=/once=True (per call site, done in compat)
create_publisher(node, topic, type, queue_size=1, latch=False) rospy.Publisher node.create_publisher (latch: transient-local QoS)
create_subscription(node, topic, type, cb, queue_size=None, latch=False) rospy.Subscriber (None: unbounded) node.create_subscription (None: depth 1; latch: transient-local QoS; ~foo -> ~/foo)
wait_for_service(node, name, type, timeout) (returns bool), set_param(node, name, value) rospy.wait_for_service, rospy.set_param a client’s wait_for_service, node.set_parameters
create_service, create_trigger_service, call_service, create_request/response, get_response_class (FooResponse(*values) on both) rospy.Service/ServiceProxy node.create_service/create_client
create_timer(node, period, cb) rospy.Timer node.create_timer (cb(None))
create_simple_action_client(node, name, type) actionlib.SimpleActionClient same subset over rclpy.action.ActionClient
create_simple_action_server(node, name, type, execute_cb) actionlib.SimpleActionServer same subset over rclpy.action.ActionServer
callback_group= of create_subscription/service/trigger_service/timer/simple_action_client/simple_action_server ignored (rospy runs each callback in its own thread) the rclpy callback group, e.g. ReentrantCallbackGroup() with a MultiThreadedExecutor
init_node(name, multi_threaded=True), for callbacks waiting for other callbacks (e.g. a service callback waiting for a topic) ignored (as above) create_* default to a ReentrantCallbackGroup and spin() uses a MultiThreadedExecutor
create_reconfigure_server(node, Config, cb, defaults) dynamic_reconfigure.server.Server parameters declared from defaults + on-set callback
now_sec, stamp_now, stamp_to_sec, duration_from_sec, sleep, Rate rospy.Time/Duration/... node.get_clock(), …
get_name, is_shutdown, on_shutdown, signal_shutdown rospy.* node name / rclpy context
create_tf_buffer_and_listener, create_tf_broadcaster tf2_ros tf2_ros with node
spin_and_shutdown(node, executor=None) - spin until SIGINT/SIGTERM/signal_shutdown, then clean up

Action types: pass FooAction/FooGoal on ROS1 and Foo/Foo.Goal on ROS2; timeouts are in seconds on both. actionlib/dynamic_reconfigure are imported lazily, so depend on them in your own package.

Packages outside jsk_common

jsk_ros1_ros2_compat is only released with jsk_common >= 3.0, which is not available for every ROS1 distro. Depend on it for ROS2 only and fall back to rospy when it can not be imported, listing just the functions you use:

<exec_depend condition="$ROS_VERSION == 2">jsk_ros1_ros2_compat</exec_depend>

try:
    from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
    from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION
except ImportError:
    # jsk_common < 3.0 has no jsk_ros1_ros2_compat, so this is ROS1 only:
    # forward ros_compat.xxx(node, ...) to rospy.xxx(...)
    import rospy
    ROS_VERSION = 1
    class ros_compat(object):
        get_param = staticmethod(lambda node, *args, **kwargs: rospy.get_param(*args, **kwargs))
        loginfo = staticmethod(lambda node, *args, **kwargs: rospy.loginfo(*args, **kwargs))

Or, to keep the original rospy code untouched for its ROS1 users, add a jsk_ros1_ros2_compat version next to it and choose by whether jsk_ros1_ros2_compat can be imported (not by ROS_VERSION):

```python try:

File truncated at 100 lines see the full file

CHANGELOG

Changelog for package jsk_ros1_ros2_compat

3.0.5 (2026-11-10)

  • Merge pull request #1841 from k-okada/rosdistro-55117-review rosdistro#55117 review: add LICENSE to each package, use SPDX license identifiers
  • Merge pull request #1840 from k-okada/rhel-ambiguous-shebang Fix RHEL rpm build (ambiguous python shebang) of image_view2 and uv venv
  • use SPDX license identifiers (BSD-3-Clause, Apache-2.0) in package.xml BSD -> BSD-3-Clause and "Apache License 2.0" -> Apache-2.0 in all packages (ros/rosdistro#55117 review: "BSD is ambiguous. The headers show the 3-clause variant, so BSD-3-Clause (SPDX) is preferred."). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • add LICENSE to each package (BSD-3-Clause, jsk_tools: Apache-2.0) The ROS2 release review of jsk_common in ros/rosdistro#55117 says (https://github.com/ros/rosdistro/pull/55117#issuecomment-6757665510): > - [ ] At least one of the following must be present > - [ ] Top level license file: None. There is no LICENSE/COPYING at > the repo root (tree @ cbbd0ab). > - [ ] Per package license files: None. No package directory has a > license file. The license text only appears in source-file headers > (e.g. deprecated_relay.h#L1-L33, BSD-3-Clause, "JSK Lab"). Since jsk_tools is Apache-2.0 and the others are BSD-3-Clause, add a license file to each package instead of one at the top level. The BSD ones use the same text as the source headers, "Copyright (c) <year>-, JSK Lab" where <year> is when the package.xml was added, and jsk_tools has the Apache License 2.0 text from apache.org. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • jsk_ros1_ros2_compat: drop exec bits of python modules in uv venv (RHEL ambiguous shebang) Some wheels (e.g. protobuf's _parameterized.py) ship modules executable with a "#!/usr/bin/env python" shebang, which makes brp-mangle-shebangs fail the RHEL rpm build of packages using jsk_ros1_ros2_compat_generate_uv_venv(). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • Contributors: Kei Okada

3.0.4 (2026-11-04)

3.0.3 (2026-11-03)

  • Merge pull request #1835 from k-okada/ros-version-fallback-ament Fix ROS2 buildfarm binary jobs: ROS_VERSION without ros_environment, boost for jsk_topic_tools

  • Merge pull request #1834 from pazeshun/array-to-heatmap [jsk_ros1_ros2_compat, jsk_topic_tools, jsk_rosbag_tools] Add array heatmap tools with ROS 1 and ROS 2 support

  • Guess ROS_VERSION from AMENT_PREFIX_PATH when unset, depend on ros_environment The ROS2 binary jobs of the buildfarm failed at find_package(catkin): they install only the build dependencies, none of which pulls in ros_environment, so $ENV{ROS_VERSION} is empty and the fallback at the top of CMakeLists.txt chose ROS1.

    - package.xml: add a ROS2 buildtool_depend on ros_environment, which sets ROS_VERSION.

    - CMakeLists.txt: when ROS_VERSION is still unset, guess it from AMENT_PREFIX_PATH (bloom's ROS2 debian/rules passes it to cmake, setup.sh and colcon set the environment variable, catkin never does) instead of always assuming ROS1, and warn about it. jsk_tools had no fallback at all and gets the same block. Applies to jsk_ros1_ros2_compat, jsk_tools, jsk_topic_tools, jsk_common, jsk_data, jsk_rosbag_tools, dynamic_tf_publisher, audio_video_recorder and image_view2. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Merge pull request #1 from k-okada/array-to-heatmap-old-distros Support indigo/kinetic in array heatmap tools (OpenCV 2.4, numpy < 1.9, rosbag < 1.13)

  • [jsk_ros1_ros2_compat] rosbag: raw messages with connection headers on rosbag < 1.13 rosbag of indigo/kinetic has neither read_messages(..., return_connection_header=) nor write(..., connection_header=), which failed test_add_heatmap on the kinetic CI. There, read_raw_messages() takes the header of each topic's connection from the bag, and write_raw() registers a new topic's connection with the given header before writing, as write(..., connection_header=) does on newer rosbag. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Add array heatmap tools with ROS 1 and ROS 2 support

    • Render numeric MultiArray and scalar Image topics as heatmap images with optional cell values and configurable color scales
    • Add heatmap topics to bags while preserving original messages, recording timestamps, and connection or QoS metadata
    • Extend the compatibility layer with raw bag I/O and shared message type helpers
    • Add installation rules, documentation, and tests for both ROS versions
  • Merge pull request

File truncated at 100 lines see the full file

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged jsk_ros1_ros2_compat at Robotics Stack Exchange

No version for distro iron showing jazzy. Known supported distros are highlighted in the buttons above.

Package Summary

Version 3.0.5
License BSD-3-Clause
Build type CATKIN
Use RECOMMENDED

Repository Summary

Description
Checkout URI https://github.com/jsk-ros-pkg/jsk_common.git
VCS Type git
VCS Version 3.0.5
Last Updated 2026-11-10
Dev Status UNKNOWN
Released RELEASED
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Package Description

Shared ROS1(roscpp/rospy)/ROS2(rclcpp/rclpy) compatibility helpers used across jsk_common's ROS2-ported packages, so that individual packages don't each maintain their own copy.

Maintainers

  • Kei Okada

Authors

No additional authors.

jsk_ros1_ros2_compat

Shared ROS1 (roscpp/rospy) / ROS2 (rclcpp/rclpy) compatibility helpers, so that a package can keep one source tree that builds and runs on both, with the ROS1 code left as close to the original as possible.

Porting style

  • One package.xml / CMakeLists.txt branched on $ROS_VERSION.
    • package.xml: condition="$ROS_VERSION == 1" / "== 2" on the dependencies and on <build_type> in <export>.
    • CMakeLists.txt: keep the ROS1 lines byte-identical (no re-indentation), e.g. prepend the ROS2 build and wrap the original in else()/endif():
    if("$ENV{ROS_VERSION}" EQUAL 2)
      cmake_minimum_required(VERSION 3.8)
      project(foo)
      find_package(ament_cmake REQUIRED)
      find_package(jsk_ros1_ros2_compat REQUIRED)
      jsk_ros1_ros2_compat_install_python(PROGRAMS scripts/foo_node.py)
      ament_package()
    else() # if("$ENV{ROS_VERSION}" EQUAL 2)
    cmake_minimum_required(VERSION 2.8.3)
    project(foo)
    ...  # the ROS1 original, unchanged
    endif() # if("$ENV{ROS_VERSION}" EQUAL 2)
    
  • Python nodes call ros_compat.xxx(node, ...) instead of rospy.xxx(...), where node is None on ROS1 and the rclpy.node.Node on ROS2.

Python: jsk_ros1_ros2_compat.rospy_rclpy_compat

from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION

if __name__ == '__main__':
    node = ros_compat.init_node('foo')  # None on ROS1
    Foo(node)
    ros_compat.spin(node)

  ROS1 ROS2
get_param(node, '~name', default), has_param rospy.get_param declares a (dynamically typed) parameter
init_node(name, anonymous=False, multi_threaded=False) rospy.init_node, returns None rclpy.init() + a new node, returned (multi_threaded: see below)
spin(node), spin_once(node, timeout_sec), shutdown(node) (after an own while not is_shutdown(node) loop) rospy.spin, rospy.sleep, - spin_and_shutdown, rclpy.spin_once, cleanup
loginfo/logwarn/logerr/logdebug/logfatal(node, msg) rospy.log* node.get_logger().* (msg must be a str; node=None uses a logger named after the script)
loginfo/logwarn/logerr_throttle(node, period, msg), loginfo/logwarn/logerr_once(node, msg) like rospy.log*_throttle/_once like throttle_duration_sec=/once=True (per call site, done in compat)
create_publisher(node, topic, type, queue_size=1, latch=False) rospy.Publisher node.create_publisher (latch: transient-local QoS)
create_subscription(node, topic, type, cb, queue_size=None, latch=False) rospy.Subscriber (None: unbounded) node.create_subscription (None: depth 1; latch: transient-local QoS; ~foo -> ~/foo)
wait_for_service(node, name, type, timeout) (returns bool), set_param(node, name, value) rospy.wait_for_service, rospy.set_param a client’s wait_for_service, node.set_parameters
create_service, create_trigger_service, call_service, create_request/response, get_response_class (FooResponse(*values) on both) rospy.Service/ServiceProxy node.create_service/create_client
create_timer(node, period, cb) rospy.Timer node.create_timer (cb(None))
create_simple_action_client(node, name, type) actionlib.SimpleActionClient same subset over rclpy.action.ActionClient
create_simple_action_server(node, name, type, execute_cb) actionlib.SimpleActionServer same subset over rclpy.action.ActionServer
callback_group= of create_subscription/service/trigger_service/timer/simple_action_client/simple_action_server ignored (rospy runs each callback in its own thread) the rclpy callback group, e.g. ReentrantCallbackGroup() with a MultiThreadedExecutor
init_node(name, multi_threaded=True), for callbacks waiting for other callbacks (e.g. a service callback waiting for a topic) ignored (as above) create_* default to a ReentrantCallbackGroup and spin() uses a MultiThreadedExecutor
create_reconfigure_server(node, Config, cb, defaults) dynamic_reconfigure.server.Server parameters declared from defaults + on-set callback
now_sec, stamp_now, stamp_to_sec, duration_from_sec, sleep, Rate rospy.Time/Duration/... node.get_clock(), …
get_name, is_shutdown, on_shutdown, signal_shutdown rospy.* node name / rclpy context
create_tf_buffer_and_listener, create_tf_broadcaster tf2_ros tf2_ros with node
spin_and_shutdown(node, executor=None) - spin until SIGINT/SIGTERM/signal_shutdown, then clean up

Action types: pass FooAction/FooGoal on ROS1 and Foo/Foo.Goal on ROS2; timeouts are in seconds on both. actionlib/dynamic_reconfigure are imported lazily, so depend on them in your own package.

Packages outside jsk_common

jsk_ros1_ros2_compat is only released with jsk_common >= 3.0, which is not available for every ROS1 distro. Depend on it for ROS2 only and fall back to rospy when it can not be imported, listing just the functions you use:

<exec_depend condition="$ROS_VERSION == 2">jsk_ros1_ros2_compat</exec_depend>

try:
    from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
    from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION
except ImportError:
    # jsk_common < 3.0 has no jsk_ros1_ros2_compat, so this is ROS1 only:
    # forward ros_compat.xxx(node, ...) to rospy.xxx(...)
    import rospy
    ROS_VERSION = 1
    class ros_compat(object):
        get_param = staticmethod(lambda node, *args, **kwargs: rospy.get_param(*args, **kwargs))
        loginfo = staticmethod(lambda node, *args, **kwargs: rospy.loginfo(*args, **kwargs))

Or, to keep the original rospy code untouched for its ROS1 users, add a jsk_ros1_ros2_compat version next to it and choose by whether jsk_ros1_ros2_compat can be imported (not by ROS_VERSION):

```python try:

File truncated at 100 lines see the full file

CHANGELOG

Changelog for package jsk_ros1_ros2_compat

3.0.5 (2026-11-10)

  • Merge pull request #1841 from k-okada/rosdistro-55117-review rosdistro#55117 review: add LICENSE to each package, use SPDX license identifiers
  • Merge pull request #1840 from k-okada/rhel-ambiguous-shebang Fix RHEL rpm build (ambiguous python shebang) of image_view2 and uv venv
  • use SPDX license identifiers (BSD-3-Clause, Apache-2.0) in package.xml BSD -> BSD-3-Clause and "Apache License 2.0" -> Apache-2.0 in all packages (ros/rosdistro#55117 review: "BSD is ambiguous. The headers show the 3-clause variant, so BSD-3-Clause (SPDX) is preferred."). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • add LICENSE to each package (BSD-3-Clause, jsk_tools: Apache-2.0) The ROS2 release review of jsk_common in ros/rosdistro#55117 says (https://github.com/ros/rosdistro/pull/55117#issuecomment-6757665510): > - [ ] At least one of the following must be present > - [ ] Top level license file: None. There is no LICENSE/COPYING at > the repo root (tree @ cbbd0ab). > - [ ] Per package license files: None. No package directory has a > license file. The license text only appears in source-file headers > (e.g. deprecated_relay.h#L1-L33, BSD-3-Clause, "JSK Lab"). Since jsk_tools is Apache-2.0 and the others are BSD-3-Clause, add a license file to each package instead of one at the top level. The BSD ones use the same text as the source headers, "Copyright (c) <year>-, JSK Lab" where <year> is when the package.xml was added, and jsk_tools has the Apache License 2.0 text from apache.org. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • jsk_ros1_ros2_compat: drop exec bits of python modules in uv venv (RHEL ambiguous shebang) Some wheels (e.g. protobuf's _parameterized.py) ship modules executable with a "#!/usr/bin/env python" shebang, which makes brp-mangle-shebangs fail the RHEL rpm build of packages using jsk_ros1_ros2_compat_generate_uv_venv(). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • Contributors: Kei Okada

3.0.4 (2026-11-04)

3.0.3 (2026-11-03)

  • Merge pull request #1835 from k-okada/ros-version-fallback-ament Fix ROS2 buildfarm binary jobs: ROS_VERSION without ros_environment, boost for jsk_topic_tools

  • Merge pull request #1834 from pazeshun/array-to-heatmap [jsk_ros1_ros2_compat, jsk_topic_tools, jsk_rosbag_tools] Add array heatmap tools with ROS 1 and ROS 2 support

  • Guess ROS_VERSION from AMENT_PREFIX_PATH when unset, depend on ros_environment The ROS2 binary jobs of the buildfarm failed at find_package(catkin): they install only the build dependencies, none of which pulls in ros_environment, so $ENV{ROS_VERSION} is empty and the fallback at the top of CMakeLists.txt chose ROS1.

    - package.xml: add a ROS2 buildtool_depend on ros_environment, which sets ROS_VERSION.

    - CMakeLists.txt: when ROS_VERSION is still unset, guess it from AMENT_PREFIX_PATH (bloom's ROS2 debian/rules passes it to cmake, setup.sh and colcon set the environment variable, catkin never does) instead of always assuming ROS1, and warn about it. jsk_tools had no fallback at all and gets the same block. Applies to jsk_ros1_ros2_compat, jsk_tools, jsk_topic_tools, jsk_common, jsk_data, jsk_rosbag_tools, dynamic_tf_publisher, audio_video_recorder and image_view2. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Merge pull request #1 from k-okada/array-to-heatmap-old-distros Support indigo/kinetic in array heatmap tools (OpenCV 2.4, numpy < 1.9, rosbag < 1.13)

  • [jsk_ros1_ros2_compat] rosbag: raw messages with connection headers on rosbag < 1.13 rosbag of indigo/kinetic has neither read_messages(..., return_connection_header=) nor write(..., connection_header=), which failed test_add_heatmap on the kinetic CI. There, read_raw_messages() takes the header of each topic's connection from the bag, and write_raw() registers a new topic's connection with the given header before writing, as write(..., connection_header=) does on newer rosbag. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Add array heatmap tools with ROS 1 and ROS 2 support

    • Render numeric MultiArray and scalar Image topics as heatmap images with optional cell values and configurable color scales
    • Add heatmap topics to bags while preserving original messages, recording timestamps, and connection or QoS metadata
    • Extend the compatibility layer with raw bag I/O and shared message type helpers
    • Add installation rules, documentation, and tests for both ROS versions
  • Merge pull request

File truncated at 100 lines see the full file

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged jsk_ros1_ros2_compat at Robotics Stack Exchange

Package Summary

Version 3.0.5
License BSD-3-Clause
Build type CATKIN
Use RECOMMENDED

Repository Summary

Description
Checkout URI https://github.com/jsk-ros-pkg/jsk_common.git
VCS Type git
VCS Version master
Last Updated 2026-11-18
Dev Status UNKNOWN
Released RELEASED
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Package Description

Shared ROS1(roscpp/rospy)/ROS2(rclcpp/rclpy) compatibility helpers used across jsk_common's ROS2-ported packages, so that individual packages don't each maintain their own copy.

Maintainers

  • Kei Okada

Authors

No additional authors.

jsk_ros1_ros2_compat

Shared ROS1 (roscpp/rospy) / ROS2 (rclcpp/rclpy) compatibility helpers, so that a package can keep one source tree that builds and runs on both, with the ROS1 code left as close to the original as possible.

ROS 1 / ROS 2

This is a library package (no nodes, scripts or launch files). It builds for both ROS 1 (catkin) and ROS 2 (ament), selected by $ROS_VERSION:

  ROS 1 ROS 2
C++ headers (include/jsk_ros1_ros2_compat/*.h) yes yes
Python package jsk_ros1_ros2_compat (rospy_rclpy_compat, rosbag, log_utils) yes yes
CMake jsk_ros1_ros2_compat_install_python() defined, but meant for ROS 2 builds yes
CMake jsk_ros1_ros2_compat_generate_uv_venv() and the bundled uv binary (lib/jsk_ros1_ros2_compat/uv) no (use catkin_virtualenv) yes

ROS_VERSION in the Python modules is read from the ROS_VERSION environment variable (default 1). The C++ headers detect ROS 1 by whether <ros/ros.h> can be included, so no compile definition is needed.

Porting style

  • One package.xml / CMakeLists.txt branched on $ROS_VERSION.
    • package.xml: condition="$ROS_VERSION == 1" / "== 2" on the dependencies and on <build_type> in <export>.
    • CMakeLists.txt: keep the ROS1 lines byte-identical (no re-indentation), e.g. prepend the ROS2 build and wrap the original in else()/endif():
    if("$ENV{ROS_VERSION}" EQUAL 2)
      cmake_minimum_required(VERSION 3.8)
      project(foo)
      find_package(ament_cmake REQUIRED)
      find_package(jsk_ros1_ros2_compat REQUIRED)
      jsk_ros1_ros2_compat_install_python(PROGRAMS scripts/foo_node.py)
      ament_package()
    else() # if("$ENV{ROS_VERSION}" EQUAL 2)
    cmake_minimum_required(VERSION 2.8.3)
    project(foo)
    ...  # the ROS1 original, unchanged
    endif() # if("$ENV{ROS_VERSION}" EQUAL 2)
    
  • Python nodes call ros_compat.xxx(node, ...) instead of rospy.xxx(...), where node is None on ROS1 and the rclpy.node.Node on ROS2.

Python: jsk_ros1_ros2_compat.rospy_rclpy_compat

from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION

if __name__ == '__main__':
    node = ros_compat.init_node('foo')  # None on ROS1
    Foo(node)
    ros_compat.spin(node)

  ROS1 ROS2
get_param(node, '~name', default), has_param rospy.get_param declares a (dynamically typed) parameter
init_node(name, anonymous=False, multi_threaded=False) rospy.init_node, returns None rclpy.init() + a new node, returned (multi_threaded: see below)
spin(node), spin_once(node, timeout_sec), shutdown(node) (after an own while not is_shutdown(node) loop) rospy.spin, rospy.sleep, - spin_and_shutdown, rclpy.spin_once, cleanup
loginfo/logwarn/logerr/logdebug/logfatal(node, msg) rospy.log* node.get_logger().* (msg must be a str; node=None uses a logger named after the script)
loginfo/logwarn/logerr_throttle(node, period, msg), loginfo/logwarn/logerr_once(node, msg) like rospy.log*_throttle/_once like throttle_duration_sec=/once=True (per call site, done in compat)
create_publisher(node, topic, type, queue_size=1, latch=False) rospy.Publisher node.create_publisher (depth queue_size, default reliable QoS; latch: transient-local QoS; ~foo -> ~/foo)
create_subscription(node, topic, type, cb, queue_size=None, latch=False, callback_group=None, qos=None) rospy.Subscriber (None: unbounded; latch, qos ignored) node.create_subscription (None: depth 1; QoS: see below; ~foo -> ~/foo)
wait_for_service(node, name, type, timeout) (returns bool), set_param(node, name, value) rospy.wait_for_service, rospy.set_param a client’s wait_for_service, node.set_parameters
create_service, create_trigger_service, call_service, create_request/response, get_response_class (FooResponse(*values) on both) rospy.Service/ServiceProxy node.create_service/create_client
create_timer(node, period, cb) rospy.Timer node.create_timer (cb(None))
create_simple_action_client(node, name, type) actionlib.SimpleActionClient same subset over rclpy.action.ActionClient
create_simple_action_server(node, name, type, execute_cb) actionlib.SimpleActionServer same subset over rclpy.action.ActionServer
callback_group= of create_subscription/service/trigger_service/timer/simple_action_client/simple_action_server ignored (rospy runs each callback in its own thread) the rclpy callback group, e.g. ReentrantCallbackGroup() with a MultiThreadedExecutor
init_node(name, multi_threaded=True), for callbacks waiting for other callbacks (e.g. a service callback waiting for a topic) ignored (as above) create_* default to a ReentrantCallbackGroup and spin() uses a MultiThreadedExecutor
create_reconfigure_server(node, Config, cb, defaults) dynamic_reconfigure.server.Server parameters declared from defaults + on-set callback
now_sec, stamp_now, stamp_to_sec, duration_from_sec, sleep, Rate rospy.Time/Duration/... node.get_clock(), …
get_name, is_shutdown, on_shutdown, signal_shutdown rospy.* node name / rclpy context
create_tf_buffer_and_listener, create_tf_broadcaster tf2_ros tf2_ros with node
spin_and_shutdown(node, executor=None) - spin until SIGINT/SIGTERM/signal_shutdown, then clean up
private_name(name), message_type_name(msg), resolve_message_class('pkg/Type') name unchanged, msg._type, roslib.message ~foo -> ~/foo, 'pkg/Type', get_message (accepts pkg/Type and pkg/msg/Type)
declare_params(node, defaults), get_params(node, names) - ROS2 only: declare / read several parameters at once

QoS of create_subscription() on ROS2 (ignored on ROS1), from the qos argument:

qos QoS
None (default) 'any', or transient-local with depth queue_size if latch=True
'any' BEST_EFFORT + VOLATILE with depth queue_size: reads the topic of any publisher, whenever it joins
'best_available' BEST_AVAILABLE reliability and durability (Iron and later) of the publishers discovered when the subscription is created; a publisher with a weaker QoS that joins later is not read. Falls back to 'any' on Humble
a QoSProfile (e.g. rclpy.qos.qos_profile_sensor_data) as given
an int that depth, rclpy’s default (reliable) QoS

So by default a subscriber receives from both reliable and best-effort publishers, but delivery is best effort. Pass qos= (e.g. a depth for reliable delivery) where lost messages matter, and latch=True for the last message of a create_publisher(..., latch=True) topic.

File truncated at 100 lines see the full file

CHANGELOG

Changelog for package jsk_ros1_ros2_compat

3.0.5 (2026-11-10)

  • Merge pull request #1841 from k-okada/rosdistro-55117-review rosdistro#55117 review: add LICENSE to each package, use SPDX license identifiers
  • Merge pull request #1840 from k-okada/rhel-ambiguous-shebang Fix RHEL rpm build (ambiguous python shebang) of image_view2 and uv venv
  • use SPDX license identifiers (BSD-3-Clause, Apache-2.0) in package.xml BSD -> BSD-3-Clause and "Apache License 2.0" -> Apache-2.0 in all packages (ros/rosdistro#55117 review: "BSD is ambiguous. The headers show the 3-clause variant, so BSD-3-Clause (SPDX) is preferred."). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • add LICENSE to each package (BSD-3-Clause, jsk_tools: Apache-2.0) The ROS2 release review of jsk_common in ros/rosdistro#55117 says (https://github.com/ros/rosdistro/pull/55117#issuecomment-6757665510): > - [ ] At least one of the following must be present > - [ ] Top level license file: None. There is no LICENSE/COPYING at > the repo root (tree @ cbbd0ab). > - [ ] Per package license files: None. No package directory has a > license file. The license text only appears in source-file headers > (e.g. deprecated_relay.h#L1-L33, BSD-3-Clause, "JSK Lab"). Since jsk_tools is Apache-2.0 and the others are BSD-3-Clause, add a license file to each package instead of one at the top level. The BSD ones use the same text as the source headers, "Copyright (c) <year>-, JSK Lab" where <year> is when the package.xml was added, and jsk_tools has the Apache License 2.0 text from apache.org. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • jsk_ros1_ros2_compat: drop exec bits of python modules in uv venv (RHEL ambiguous shebang) Some wheels (e.g. protobuf's _parameterized.py) ship modules executable with a "#!/usr/bin/env python" shebang, which makes brp-mangle-shebangs fail the RHEL rpm build of packages using jsk_ros1_ros2_compat_generate_uv_venv(). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • Contributors: Kei Okada

3.0.4 (2026-11-04)

3.0.3 (2026-11-03)

  • Merge pull request #1835 from k-okada/ros-version-fallback-ament Fix ROS2 buildfarm binary jobs: ROS_VERSION without ros_environment, boost for jsk_topic_tools

  • Merge pull request #1834 from pazeshun/array-to-heatmap [jsk_ros1_ros2_compat, jsk_topic_tools, jsk_rosbag_tools] Add array heatmap tools with ROS 1 and ROS 2 support

  • Guess ROS_VERSION from AMENT_PREFIX_PATH when unset, depend on ros_environment The ROS2 binary jobs of the buildfarm failed at find_package(catkin): they install only the build dependencies, none of which pulls in ros_environment, so $ENV{ROS_VERSION} is empty and the fallback at the top of CMakeLists.txt chose ROS1.

    - package.xml: add a ROS2 buildtool_depend on ros_environment, which sets ROS_VERSION.

    - CMakeLists.txt: when ROS_VERSION is still unset, guess it from AMENT_PREFIX_PATH (bloom's ROS2 debian/rules passes it to cmake, setup.sh and colcon set the environment variable, catkin never does) instead of always assuming ROS1, and warn about it. jsk_tools had no fallback at all and gets the same block. Applies to jsk_ros1_ros2_compat, jsk_tools, jsk_topic_tools, jsk_common, jsk_data, jsk_rosbag_tools, dynamic_tf_publisher, audio_video_recorder and image_view2. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Merge pull request #1 from k-okada/array-to-heatmap-old-distros Support indigo/kinetic in array heatmap tools (OpenCV 2.4, numpy < 1.9, rosbag < 1.13)

  • [jsk_ros1_ros2_compat] rosbag: raw messages with connection headers on rosbag < 1.13 rosbag of indigo/kinetic has neither read_messages(..., return_connection_header=) nor write(..., connection_header=), which failed test_add_heatmap on the kinetic CI. There, read_raw_messages() takes the header of each topic's connection from the bag, and write_raw() registers a new topic's connection with the given header before writing, as write(..., connection_header=) does on newer rosbag. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Add array heatmap tools with ROS 1 and ROS 2 support

    • Render numeric MultiArray and scalar Image topics as heatmap images with optional cell values and configurable color scales
    • Add heatmap topics to bags while preserving original messages, recording timestamps, and connection or QoS metadata
    • Extend the compatibility layer with raw bag I/O and shared message type helpers
    • Add installation rules, documentation, and tests for both ROS versions
  • Merge pull request

File truncated at 100 lines see the full file

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged jsk_ros1_ros2_compat at Robotics Stack Exchange

Package Summary

Version 3.0.5
License BSD-3-Clause
Build type CATKIN
Use RECOMMENDED

Repository Summary

Description
Checkout URI https://github.com/jsk-ros-pkg/jsk_common.git
VCS Type git
VCS Version master
Last Updated 2026-11-18
Dev Status UNKNOWN
Released RELEASED
Contributing Help Wanted (-)
Good First Issues (-)
Pull Requests to Review (-)

Package Description

Shared ROS1(roscpp/rospy)/ROS2(rclcpp/rclpy) compatibility helpers used across jsk_common's ROS2-ported packages, so that individual packages don't each maintain their own copy.

Maintainers

  • Kei Okada

Authors

No additional authors.

jsk_ros1_ros2_compat

Shared ROS1 (roscpp/rospy) / ROS2 (rclcpp/rclpy) compatibility helpers, so that a package can keep one source tree that builds and runs on both, with the ROS1 code left as close to the original as possible.

ROS 1 / ROS 2

This is a library package (no nodes, scripts or launch files). It builds for both ROS 1 (catkin) and ROS 2 (ament), selected by $ROS_VERSION:

  ROS 1 ROS 2
C++ headers (include/jsk_ros1_ros2_compat/*.h) yes yes
Python package jsk_ros1_ros2_compat (rospy_rclpy_compat, rosbag, log_utils) yes yes
CMake jsk_ros1_ros2_compat_install_python() defined, but meant for ROS 2 builds yes
CMake jsk_ros1_ros2_compat_generate_uv_venv() and the bundled uv binary (lib/jsk_ros1_ros2_compat/uv) no (use catkin_virtualenv) yes

ROS_VERSION in the Python modules is read from the ROS_VERSION environment variable (default 1). The C++ headers detect ROS 1 by whether <ros/ros.h> can be included, so no compile definition is needed.

Porting style

  • One package.xml / CMakeLists.txt branched on $ROS_VERSION.
    • package.xml: condition="$ROS_VERSION == 1" / "== 2" on the dependencies and on <build_type> in <export>.
    • CMakeLists.txt: keep the ROS1 lines byte-identical (no re-indentation), e.g. prepend the ROS2 build and wrap the original in else()/endif():
    if("$ENV{ROS_VERSION}" EQUAL 2)
      cmake_minimum_required(VERSION 3.8)
      project(foo)
      find_package(ament_cmake REQUIRED)
      find_package(jsk_ros1_ros2_compat REQUIRED)
      jsk_ros1_ros2_compat_install_python(PROGRAMS scripts/foo_node.py)
      ament_package()
    else() # if("$ENV{ROS_VERSION}" EQUAL 2)
    cmake_minimum_required(VERSION 2.8.3)
    project(foo)
    ...  # the ROS1 original, unchanged
    endif() # if("$ENV{ROS_VERSION}" EQUAL 2)
    
  • Python nodes call ros_compat.xxx(node, ...) instead of rospy.xxx(...), where node is None on ROS1 and the rclpy.node.Node on ROS2.

Python: jsk_ros1_ros2_compat.rospy_rclpy_compat

from jsk_ros1_ros2_compat import rospy_rclpy_compat as ros_compat
from jsk_ros1_ros2_compat.rospy_rclpy_compat import ROS_VERSION

if __name__ == '__main__':
    node = ros_compat.init_node('foo')  # None on ROS1
    Foo(node)
    ros_compat.spin(node)

  ROS1 ROS2
get_param(node, '~name', default), has_param rospy.get_param declares a (dynamically typed) parameter
init_node(name, anonymous=False, multi_threaded=False) rospy.init_node, returns None rclpy.init() + a new node, returned (multi_threaded: see below)
spin(node), spin_once(node, timeout_sec), shutdown(node) (after an own while not is_shutdown(node) loop) rospy.spin, rospy.sleep, - spin_and_shutdown, rclpy.spin_once, cleanup
loginfo/logwarn/logerr/logdebug/logfatal(node, msg) rospy.log* node.get_logger().* (msg must be a str; node=None uses a logger named after the script)
loginfo/logwarn/logerr_throttle(node, period, msg), loginfo/logwarn/logerr_once(node, msg) like rospy.log*_throttle/_once like throttle_duration_sec=/once=True (per call site, done in compat)
create_publisher(node, topic, type, queue_size=1, latch=False) rospy.Publisher node.create_publisher (depth queue_size, default reliable QoS; latch: transient-local QoS; ~foo -> ~/foo)
create_subscription(node, topic, type, cb, queue_size=None, latch=False, callback_group=None, qos=None) rospy.Subscriber (None: unbounded; latch, qos ignored) node.create_subscription (None: depth 1; QoS: see below; ~foo -> ~/foo)
wait_for_service(node, name, type, timeout) (returns bool), set_param(node, name, value) rospy.wait_for_service, rospy.set_param a client’s wait_for_service, node.set_parameters
create_service, create_trigger_service, call_service, create_request/response, get_response_class (FooResponse(*values) on both) rospy.Service/ServiceProxy node.create_service/create_client
create_timer(node, period, cb) rospy.Timer node.create_timer (cb(None))
create_simple_action_client(node, name, type) actionlib.SimpleActionClient same subset over rclpy.action.ActionClient
create_simple_action_server(node, name, type, execute_cb) actionlib.SimpleActionServer same subset over rclpy.action.ActionServer
callback_group= of create_subscription/service/trigger_service/timer/simple_action_client/simple_action_server ignored (rospy runs each callback in its own thread) the rclpy callback group, e.g. ReentrantCallbackGroup() with a MultiThreadedExecutor
init_node(name, multi_threaded=True), for callbacks waiting for other callbacks (e.g. a service callback waiting for a topic) ignored (as above) create_* default to a ReentrantCallbackGroup and spin() uses a MultiThreadedExecutor
create_reconfigure_server(node, Config, cb, defaults) dynamic_reconfigure.server.Server parameters declared from defaults + on-set callback
now_sec, stamp_now, stamp_to_sec, duration_from_sec, sleep, Rate rospy.Time/Duration/... node.get_clock(), …
get_name, is_shutdown, on_shutdown, signal_shutdown rospy.* node name / rclpy context
create_tf_buffer_and_listener, create_tf_broadcaster tf2_ros tf2_ros with node
spin_and_shutdown(node, executor=None) - spin until SIGINT/SIGTERM/signal_shutdown, then clean up
private_name(name), message_type_name(msg), resolve_message_class('pkg/Type') name unchanged, msg._type, roslib.message ~foo -> ~/foo, 'pkg/Type', get_message (accepts pkg/Type and pkg/msg/Type)
declare_params(node, defaults), get_params(node, names) - ROS2 only: declare / read several parameters at once

QoS of create_subscription() on ROS2 (ignored on ROS1), from the qos argument:

qos QoS
None (default) 'any', or transient-local with depth queue_size if latch=True
'any' BEST_EFFORT + VOLATILE with depth queue_size: reads the topic of any publisher, whenever it joins
'best_available' BEST_AVAILABLE reliability and durability (Iron and later) of the publishers discovered when the subscription is created; a publisher with a weaker QoS that joins later is not read. Falls back to 'any' on Humble
a QoSProfile (e.g. rclpy.qos.qos_profile_sensor_data) as given
an int that depth, rclpy’s default (reliable) QoS

So by default a subscriber receives from both reliable and best-effort publishers, but delivery is best effort. Pass qos= (e.g. a depth for reliable delivery) where lost messages matter, and latch=True for the last message of a create_publisher(..., latch=True) topic.

File truncated at 100 lines see the full file

CHANGELOG

Changelog for package jsk_ros1_ros2_compat

3.0.5 (2026-11-10)

  • Merge pull request #1841 from k-okada/rosdistro-55117-review rosdistro#55117 review: add LICENSE to each package, use SPDX license identifiers
  • Merge pull request #1840 from k-okada/rhel-ambiguous-shebang Fix RHEL rpm build (ambiguous python shebang) of image_view2 and uv venv
  • use SPDX license identifiers (BSD-3-Clause, Apache-2.0) in package.xml BSD -> BSD-3-Clause and "Apache License 2.0" -> Apache-2.0 in all packages (ros/rosdistro#55117 review: "BSD is ambiguous. The headers show the 3-clause variant, so BSD-3-Clause (SPDX) is preferred."). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • add LICENSE to each package (BSD-3-Clause, jsk_tools: Apache-2.0) The ROS2 release review of jsk_common in ros/rosdistro#55117 says (https://github.com/ros/rosdistro/pull/55117#issuecomment-6757665510): > - [ ] At least one of the following must be present > - [ ] Top level license file: None. There is no LICENSE/COPYING at > the repo root (tree @ cbbd0ab). > - [ ] Per package license files: None. No package directory has a > license file. The license text only appears in source-file headers > (e.g. deprecated_relay.h#L1-L33, BSD-3-Clause, "JSK Lab"). Since jsk_tools is Apache-2.0 and the others are BSD-3-Clause, add a license file to each package instead of one at the top level. The BSD ones use the same text as the source headers, "Copyright (c) <year>-, JSK Lab" where <year> is when the package.xml was added, and jsk_tools has the Apache License 2.0 text from apache.org. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • jsk_ros1_ros2_compat: drop exec bits of python modules in uv venv (RHEL ambiguous shebang) Some wheels (e.g. protobuf's _parameterized.py) ship modules executable with a "#!/usr/bin/env python" shebang, which makes brp-mangle-shebangs fail the RHEL rpm build of packages using jsk_ros1_ros2_compat_generate_uv_venv(). Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>
  • Contributors: Kei Okada

3.0.4 (2026-11-04)

3.0.3 (2026-11-03)

  • Merge pull request #1835 from k-okada/ros-version-fallback-ament Fix ROS2 buildfarm binary jobs: ROS_VERSION without ros_environment, boost for jsk_topic_tools

  • Merge pull request #1834 from pazeshun/array-to-heatmap [jsk_ros1_ros2_compat, jsk_topic_tools, jsk_rosbag_tools] Add array heatmap tools with ROS 1 and ROS 2 support

  • Guess ROS_VERSION from AMENT_PREFIX_PATH when unset, depend on ros_environment The ROS2 binary jobs of the buildfarm failed at find_package(catkin): they install only the build dependencies, none of which pulls in ros_environment, so $ENV{ROS_VERSION} is empty and the fallback at the top of CMakeLists.txt chose ROS1.

    - package.xml: add a ROS2 buildtool_depend on ros_environment, which sets ROS_VERSION.

    - CMakeLists.txt: when ROS_VERSION is still unset, guess it from AMENT_PREFIX_PATH (bloom's ROS2 debian/rules passes it to cmake, setup.sh and colcon set the environment variable, catkin never does) instead of always assuming ROS1, and warn about it. jsk_tools had no fallback at all and gets the same block. Applies to jsk_ros1_ros2_compat, jsk_tools, jsk_topic_tools, jsk_common, jsk_data, jsk_rosbag_tools, dynamic_tf_publisher, audio_video_recorder and image_view2. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Merge pull request #1 from k-okada/array-to-heatmap-old-distros Support indigo/kinetic in array heatmap tools (OpenCV 2.4, numpy < 1.9, rosbag < 1.13)

  • [jsk_ros1_ros2_compat] rosbag: raw messages with connection headers on rosbag < 1.13 rosbag of indigo/kinetic has neither read_messages(..., return_connection_header=) nor write(..., connection_header=), which failed test_add_heatmap on the kinetic CI. There, read_raw_messages() takes the header of each topic's connection from the bag, and write_raw() registers a new topic's connection with the given header before writing, as write(..., connection_header=) does on newer rosbag. Co-Authored-By: Claude Opus 5.5 <<noreply@anthropic.com>>

  • Add array heatmap tools with ROS 1 and ROS 2 support

    • Render numeric MultiArray and scalar Image topics as heatmap images with optional cell values and configurable color scales
    • Add heatmap topics to bags while preserving original messages, recording timestamps, and connection or QoS metadata
    • Extend the compatibility layer with raw bag I/O and shared message type helpers
    • Add installation rules, documentation, and tests for both ROS versions
  • Merge pull request

File truncated at 100 lines see the full file

Launch files

No launch files found

Messages

No message files found.

Services

No service files found

Plugins

No plugins found.

Recent questions tagged jsk_ros1_ros2_compat at Robotics Stack Exchange