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

ROS Callback counter [closed]

asked 2014-08-19 08:52:20 -0600

PaTTo gravatar image

updated 2014-08-19 10:52:17 -0600

Hey there,

I need to make a node, where if a position message arrives make a vector with the actual position in x and the 4 previous values. But it doesn't work, I think is a easy code, but I am a beginner.

I cant even work with a simpler vector. I only can work with the last message position. Hope anyone can help me.

import roslib
import rospy
import math
import numpy as np
from posotion.msg import RobotPos

v = np.zeros(5)

def callback(msg):

    print v

# Intializes everything
def start():
    global count
    rospy.Subscriber("robot_pos", RobotPos, callback)
    count += 1 #I also tried to use this in callback function but it doesnt work

if __name__ == '__main__':
    except rospy.ROSInterruptException:
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by PaTTo
close date 2014-08-19 14:19:58.176964


What line does it say this error is on? Did you typo "count" as "cont" somewhere that isn't included in your post?

Dan Lazewatsky gravatar image Dan Lazewatsky  ( 2014-08-19 09:47:15 -0600 )edit

Added the full code, I obtain only the first field of the vector as the actual value. v[0] = msg.position the rest are zeros. count += 1 doesnt works there in each spin. And if I print count, it always has the same value

PaTTo gravatar image PaTTo  ( 2014-08-19 10:22:08 -0600 )edit

Is it possible that you couldn't import the right message types? Because you wrote: From posOtion.msg import RobotPos

MaxM gravatar image MaxM  ( 2020-07-07 06:40:48 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-08-19 11:43:37 -0600

PaTTo gravatar image

updated 2014-08-19 11:43:57 -0600

"global count" must be set in callback function.

edit flag offensive delete link more

Question Tools


Asked: 2014-08-19 08:52:20 -0600

Seen: 662 times

Last updated: Aug 19 '14