Hi
Is it possible to plot values from a ros topic in python ? For example I want to leverage matplotlibs draw function and look at more than one topic as well as add some values of my own on the graph
I know I could use rqt plot but that means I have to plot evening outside of my code as well as publish whatever extra values I want to a topic and then use rqt plot to plot those too.
I want to be able to plot stuff in the callback for the topic I subscribed to or something similar so data is updated the second I get it.
For example I subscribed to the odometry topic (msg type nav_msgs/Odometry) and want to plot the x y z of the position. I haven't been able to plot data as it comes.
What I have been able to do is the following: Collect all my data in a vector and then plot it at the end
Here's my plotting function:
def plot_odom(self):
x = []
y = []
plt.ion()
plt.show()
#self.odom.pose.pose.position.x
print "in plot_odom"
for odomx in self.odom_vec:
#print "x ", x
#print "y ", y
#raw_input("continue")
x.append(odomx.header.stamp.to_sec())
y.append(odomx.pose.pose.position.x)
plt.plot(x,y,'bo')
plt.ylabel("odom")
plt.draw()
time.sleep(0.05)`
This seems to work okay in terms of giving an animation which is similar to what I would want if this were in the callback function.
I hope I've been able to explain myself well.
↧