ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Dynamic reconfigure

asked 2017-02-05 21:43:57 -0500

Azhar gravatar image

updated 2017-02-05 21:45:46 -0500

this is my client.py

#!/usr/bin/env python

PACKAGE = 'dynamic_tutorials'
import roslib;roslib.load_manifest(PACKAGE)
import rospy
import dynamic_reconfigure.client

from geometry_msgs.msg import Vector3, Twist

def callback(config):
    rospy.loginfo("Config set to {bool_param}".format(**config))

if __name__ == "__main__":
    rospy.init_node("dynamic_client")
    pub = rospy.Publisher('/turtle1/cmd_vel', Twist)
    rospy.wait_for_service("/dynamic_tutorials/set_parameters")
    tw = Twist(Vector3(1,2,0), Vector3(0,0,1))
    client = dynamic_reconfigure.client.Client("dynamic_tutorials", timeout=30, config_callback=callback)

    r = rospy.Rate(1)
    x = 0
    b = True

    while not rospy.is_shutdown():

        x = x+1
        if x >5:  
            pub.publish(tw) 
            x=0   

        client.update_configuration({"bool_param":b})
        r.sleep()

When i run my server.py and client.py and turtlesim_node and dynamic_reconfigure, the turtle in the turtlesim node goes in circle every 5 seconds(regardless if the bool_param in dynamic reconfigure is ticked or unticked). If i click the bool_param, it becomes unticked immediately.

Intended action: When i click on a button(bool_param, in this case is ticked) in rqt_dynamic_reconfigure , it should publish the command and remain publishing the command untill i give further instructions.

How can i implement this action? I need to control the turtle movement using dynamic_reconfigure.

Thank you!

edit retag flag offensive close merge delete

Comments

Can you clarify why you want to do this with dynamic_reconfigure?

gvdhoorn gravatar image gvdhoorn  ( 2017-02-06 02:44:07 -0500 )edit

Basically I want an on/off button in my dynamic_reconfigure, to publish my customized data. So if the button is "on", it would publish the data.

Current problem : 1) the button in the dynamic configure does not have any effect on the turtle when turned "on" or "off".

Azhar gravatar image Azhar  ( 2017-02-06 04:25:25 -0500 )edit

That sounds like a strange thing to do with dynamic_reconfigure. More something for a service. Why do you feel dynamic_reconfigure should be used for something like this?

re: no effect: well, your callback doesn't do anything besides printing the config. It doesn't update anything.

gvdhoorn gravatar image gvdhoorn  ( 2017-02-06 04:59:07 -0500 )edit

i need dynamic_reconfigure to able to change between modes for an autonomous vehicle, which is the ultimate goal. I am using turtlesim to find out how it can be done first.

Is it possible for you to guide me what i should have in my callback, to get the intended function? Any form of guide! :)

Azhar gravatar image Azhar  ( 2017-02-06 05:24:35 -0500 )edit
1

I still think this is not something you'd want to do with dynamic_reconfigure, but see amcl/src/amcl_node.cpp for how AMCL uses dyn rcfg. Mimic that in Python.

gvdhoorn gravatar image gvdhoorn  ( 2017-02-06 06:10:35 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-02-13 02:37:28 -0500

Azhar gravatar image

THANKS @gvdhoom!

i managed to get what i want using the dynamic_reconfigure!

General info: The config is a dictionary which stores the True/False value of the parameter. So by playing with it , you can control what you want to do!

#!/usr/bin/env python
PACKAGE = 'dynamic_tutorials'
import roslib;roslib.load_manifest(PACKAGE)
import rospy
import dynamic_reconfigure.client

from geometry_msgs.msg import Vector3, Twist

def callback(config):
    global pub,tw,cw,global_name, client
    print config
    global_name = config['bool_param']

pub = rospy.Publisher('/turtle1/cmd_vel', Twist)    
tw = Twist(Vector3(1,2,0), Vector3(0,0,1))
cw = Twist(Vector3(1,2,0),Vector3(0,0,-1))

if __name__ == "__main__":
    rospy.init_node("dynamic_client")
    rospy.wait_for_service("/dynamic_tutorials/set_parameters")

    client = dynamic_reconfigure.client.Client("dynamic_tutorials", timeout=30, config_callback=callback)

   r = rospy.Rate(1)
   global_name = rospy.get_param("/dynamic_tutorials/bool_param")
   while not rospy.is_shutdown():              
   if global_name:
        pub.publish(tw)
    else:
        pub.publish(cw)

    r.sleep()
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-02-05 21:43:57 -0500

Seen: 1,711 times

Last updated: Feb 13 '17