Skip to content

Instantly share code, notes, and snippets.

@agrueneberg
Last active May 3, 2023 08:23
Show Gist options
  • Save agrueneberg/d76fff493753fa531f1b5d33be0f07ed to your computer and use it in GitHub Desktop.
Save agrueneberg/d76fff493753fa531f1b5d33be0f07ed to your computer and use it in GitHub Desktop.
Complex ROS2 parameters via undeclared, namespaced parameters
import rclpy
import rclpy.node
def main():
rclpy.init()
node = rclpy.node.Node('mappings', allow_undeclared_parameters=True)
def mappings():
mappingsParam = node.get_parameters_by_prefix('mappings')
mappings = {}
for key, value in mappingsParam.items():
namespace, name = key.split('.', maxsplit=1)
if namespace not in mappings:
mappings[namespace] = {}
mappings[namespace][name] = value.get_parameter_value().string_value
node.get_logger().info(f'mappings: {str(mappings)}')
node.create_timer(1, mappings)
rclpy.spin(node)
if __name__ == '__main__':
main()
/mappings:
ros__parameters:
mappings:
m1:
from: "t1"
to: "t1"
m2:
from: "t2"
to: "t2"
use_sim_time: false
ros2 param load /mappings mappings2.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment