How to modify a model plugin to publish data to a rostopic or ros node?
I am trying to work with gazebomotormodel.cpp. I need to visual some data that is calculated inside the plugin such as force, drag_torque etc. Is there a way i can publish this data to a topic or node so that i can visualize it using rqt.
P.S. - I am working on ROS kinetic with gazebo 7
Asked by zaccer on 2019-10-07 04:55:48 UTC
Answers
If the plugin doesn't provide the necessary Publisher
s yet, and the data you're after is internal to the plugin, you'll probably have to add ros::Publisher
s yourself. Basically extend the plugin to create additional publishers for the data you're interested in.
A quick look shows that apart from this single Publisher that publishes motor velocity, there are no others.
You could follow a similar pattern to add your own (and if you want to be nice, add some configuration settings for them as well).
Asked by gvdhoorn on 2019-10-07 05:01:41 UTC
Comments
thanks for the answer, I am fairly new to ROS, is there any example I can reference from to understand the method in depth?
Asked by zaccer on 2019-10-07 05:20:09 UTC
is there any example I can reference from to understand the method in depth?
which "method" exactly? Could you clarify?
The code of the plugin you reference could already be thought of as an example. If you consider the "motor velocity" publisher, you could duplicate that for every bit of information you want out of the plugin.
You could debate whether "internal state" is something that could be published as a single message or whether multiple different publishers (each carrying only a single piece of information) would make sense. The former may make it easier to time-sync plots, but not necessarily (if you timestamp everything correctly).
Asked by gvdhoorn on 2019-10-07 05:32:13 UTC
I tried creating a publisher following the example,i created a variable force_pub_topic_ to publish the data but while compiling the code, error occurs that 'force_pub_topic_ is not declared in the scope.'
on further search i found that motorspeed_pub_topic_ is declared in motor_model.hlink text file,which has referenced for other . h files for motor speed.
what is a possible solution to solve above error?
Asked by zaccer on 2019-10-07 05:43:30 UTC
This would appear to be more a C++ issue than a ROS one: you'll have to properly declare and define the variables that you need/want to use, as well as any other resources.
You already found the correct place to do that. The class definition is in the header. The implementation is (mostly) in the .cpp
.
By carefully studying how the current publisher is created and used, you should be able to add the one for your data.
Asked by gvdhoorn on 2019-10-07 06:17:31 UTC
Thanks for the help.I will look into the header file.
Asked by zaccer on 2019-10-07 06:23:57 UTC
Comments