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

Revision history [back]

click to hide/show revision 1
initial version

The quick and dirty way to do this would be to create a global variable for last odom. You could save thiis variable at the end of every loop. It would look something like this

last_odom = Odometry()


def listener():
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber("/odom", Odometry, simple_callback)
    rospy.spin()

def simple_callback(data):
    global last_odom


if __name__== '__main__':
    listener()

The quick and dirty way to do this would be to create a global variable for last odom. You could save thiis variable at the end of every loop. It would look something like this

last_odom = Odometry()


def listener():
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber("/odom", Odometry, simple_callback)
    rospy.spin()

def simple_callback(data):
    global last_odom


if __name__== '__main__':
    listener()

The quick and dirty way to do this would be to create a global variable for last odom. You could save thiis variable at the end of every loop. It would look something like this

The quick and dirty way to do this would be to create a global variable for last odom. You could save thiis variable at the end of every loop. It would look something like this 

last_odom = Odometry()
 current_odom = Odometry()

def listener():
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber("/odom", Odometry, simple_callback)
    rospy.spin()

def simple_callback(data):
    global last_odom
last_odom      global current_odom
    last_odom = current_odom
    current_odom = data

if __name__== '__main__':
    listener()

The quick and dirty way to do this would be to create a global variable for last odom. You could save thiis this variable at the end of every loop. It would look something like this

The quick and dirty way to do this would be to create a global variable for last odom. You could save thiis variable at the end of every loop. It would look something like this 

last_odom = Odometry()
current_odom = Odometry()

def listener():
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber("/odom", Odometry, simple_callback)
    rospy.spin()

def simple_callback(data):
    global last_odom 
    global current_odom
    last_odom = current_odom
    current_odom = data

if __name__== '__main__':
    listener()

The quick and dirty way to do this would be to create a global variable for last and current odom. You could save this variable at the end of every loop. It would look something like this

last_odom = Odometry()
current_odom = Odometry()

def listener():
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber("/odom", Odometry, simple_callback)
    rospy.spin()

def simple_callback(data):
    global last_odom 
    global current_odom
    last_odom = current_odom
    current_odom = data

if __name__== '__main__':
    listener()