Set dynamically reconfigurable parameters when message arrives

asked 2020-04-24 07:27:14 -0500

cheesee61 gravatar image

Hello dear ROS developers,

I have a possibly easily solvable question. I want to listen/subscribe to a topic (let's say LaserScan) and every time a message is arriving, I want to set/get dynamically reconfigurable parameters of a node (let's say speed parameters of nav stack) in the callback function. I assume that this can be accomplished using the Dynamic Reconfigure Python Client, is that right?

As far as I understood, this Tutorial covers other things as it isn't subscribing to a topic.

Can you give me a minimal working example in Python, because I am a little bit confused about having two callback functions then, one for the subscribed topic and one for the dynamic_reconfigure client?

I would like to do something like this:

import rospy
import dynamic_reconfigure.client

rospy.init_node("set_param_message_arrival")
rospy.Subscriber("/scan", LaserScan, callback)
client = dynamic_reconfigure.client.Client("dwa_local_planner", timeout=30)
rospy.spin()

def callback(laser):
    if laser.range_min > 0.3:
        v = 1; a = 1
    else:
        v = 1.5; a = 1.5
    client.update_configuration({"max_vel_x": v, "acc_lim_x": a})  # leave other params unchanged

I would appreciate every help and hint, thanks guys.

edit retag flag offensive close merge delete