rospy

Python real time plotting ROS data

假如想象 提交于 2019-12-07 22:24:02
问题 I am trying to plot real time data coming to the computer using python. Data comes in a ROS topic and I use 'rospy' to subscribe to the topic in order to get data. This is the code I wrote import rospy from sensor_msgs.msg import ChannelFloat32 import matplotlib.pyplot as plt N = 200 i = 0 topic = "chatter" x = range(N) lmotor = [0]*N rmotor = [0]*N plt.ion() fig = plt.figure() ax = fig.add_subplot(111) ax.set_xlim([0,N]) ax.set_ylim([-1,1]) line1, = ax.plot(lmotor, 'r-') line2, = ax.plot

Update the global variable in Rospy

别来无恙 提交于 2019-12-06 16:31:06
i have the problem. I have two node, node 1 and node2, where node1 send a float number in node2 and node2 send a float number in node1. In the function callback, I want sum the information received with other value and update the variable. But the problem is that i don't succeed the information sent, because the terminal prints in output only first update(for node 1 i get 2.9, and node 2 2.0) These code for node1 and node2 Node1 !/usr/bin/env python import rospy import time from std_msgs.msg import Float64 global x1 global a x1 = 1.5 def callback(msg): #print 'Sto ricevendo informazioni da %s