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

Read a topic from inside a launch or urdf file

asked 2018-11-23 10:16:17 -0600

hbaqueiro gravatar image

updated 2018-11-23 10:17:36 -0600

Hi everyone,

I would like to read a value from a message in a topic (say the message is of type std_msgs/Bool) from inside a urdf or launch file so that I can, for example, turn on or turn off a sensor in runtime just writing true of false into that topic.

Just to contextualize: I want to toggle a sensor when pressing a button in a joystick. For that, I created a subscriber to read the button and a publisher for publishing into the topic /state the state of the sensor. If it was off, when I press the button it turns on and vice-versa. For that I created also a subscriber to read the current state in /state. All of this is already implemented and I can toggle the boolean value in the /state topic every time I press the button.

My question is how can I read the value from this topic, so that I can use it in a xacro urdf file? What I wanted to do is the same as we do with parameters and arguments in a xacro file, but with the ability to "change the parameter/argument value" in runtime (that's why I thought of reading from a topic, but I don't know if it is possible). I am using ROS Kinetic and Gazebo7.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-11-23 12:11:49 -0600

That is not how xacro or launch files work I'm afraid. They are read once and in the case of xacro the robot model is created, or for a launch file a set of nodes is started. As soon as this startup activity is complete the xacro or launch file are no longer active.

If you are working with a real robot then the best way of going about this would be to modify the driver node for the sensor so it can be activated and deactivated directly. The most appropriate communication method for this would be a service not a topic since you want guaranteed delivery.

If you're working with a gazebo simulation then it will be a case of making a simple plugin to create and destroy the sensor based upon the service requests.

Hope this helps.

edit flag offensive delete link more

Comments

1

Thanks (and sorry for this non-sense question). For the sensor I was working, which was the gazebo_ros_projector (libgazebo_ros_projector.so), I've found out that publishing 0 in the topic given by the tag <projectortopicname> turns off the projector and any value different from 0 turns it back on.

hbaqueiro gravatar image hbaqueiro  ( 2018-11-30 12:31:06 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2018-11-23 10:16:17 -0600

Seen: 274 times

Last updated: Nov 23 '18