0
$\begingroup$

Rosanswers logo

Hi,

I am using two laser hokuyo, one on top of the other to make a 360 degrees scan. I am working in python and i am making a node that simply join the information that come from the different topics.

However i don't know how to make to callbacks in the same node.I simply want that each call back calls from one topic, so that i can read both ranges and join them.

Can you help me?

Edit:

The error is:

[ERROR] [WallTime: 1384088332.419696] bad callback: <function callback2 at 0x29cbed8> Traceback (most recent call last): File "/opt/ros/groovy/lib/python2.7/dist-packages/rospy/topics.py", line 681, in _invoke_callback cb(msg) File "/home/tiago/catkin_ws/src/test_python/listener.py", line 32, in callback2 cerebro(); File "/home/tiago/catkin_ws/src/test_python/listener.py", line 38, in cerebro copy(); File "/home/tiago/catkin_ws/src/test_python/listener.py", line 68, in copy pub.publish(LaserScan(laser)) File "/opt/ros/groovy/lib/python2.7/dist-packages/sensor_msgs/msg/_LaserScan.py", line 80, in init super(LaserScan, self).init(*args, **kwds) File "/opt/ros/groovy/lib/python2.7/dist-packages/genpy/message.py", line 271, in init raise TypeError("Invalid number of arguments, args should be %s"%str(self.slots)+" args are"+str(args)) TypeError: Invalid number of arguments, args should be ['header', 'angle_min', 'angle_max', 'angle_increment', 'time_increment', 'scan_time', 'range_min', 'range_max', 'ranges', 'intensities'] args are(header:

And here is my code:

#!/usr/bin/env python import rospy from sensor_msgs.msg import LaserScan from std_msgs.msg import String from std_msgs.msg import Header import genpy

valores=[]
valores2=[]
valores_total=[]
idx=0;
flag=0;


def callback(header):
    global valores
    global flag
    flag=flag+1;
    valores=header.ranges
    if flag==2:
    cerebro();

def callback2(header): 
    global valores2
    global flag
    flag=flag+1; 
    valores2=header.ranges
    if flag==2:
    cerebro();

    
def cerebro():
    global valores_total
    valores_total=valores+valores2
    copy();



def copy():

    
    laser = LaserScan();
    header = Header();
    global idx
    global flag
    #creating header
    header.seq = idx;
    ftime_now = rospy.get_time();
    header.stamp = genpy.rostime.Time(int(ftime_now) // 1, int((ftime_now % 1.0)*1000000000)); 
    header.frame_id = "laser";

    laser.header = header;
    laser.angle_min = -3.14159;
    laser.angle_max = 3.14159;
    laser.angle_increment= 0.00613592332229;
    laser.time_increment= 9.76562514552e-05;
    laser.scan_time= 0.10000000149;
    laser.range_min= 0.019999999553;
    laser.range_max= 5.59999990463;
    laser.ranges=valores_total;
 

    pub = rospy.Publisher('chatter', LaserScan)
    rospy.loginfo(laser)
    pub.publish(LaserScan(laser))
   
    flag=0;
    idx=idx+1;


def listener():
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber("/scan", LaserScan, callback)
    rospy.Subscriber("/scan_front", LaserScan, callback2)
    rospy.spin()
    



if __name__ == '__main__':
    listener()
    

Thank you

EDIT:

Ok guys i think that i have solved the problem:

Instead of this:

pub = rospy.Publisher('chatter', LaserScan)
    rospy.loginfo(laser)
    pub.publish(LaserScan(laser))

i made this:

pub = rospy.Publisher('chatter', LaserScan)

    pub.publish(laser)

don't ask me why, i am new in ROS so some times i do things by intuition.

Thank you for your time!


Originally posted by trbf on ROS Answers with karma: 16 on 2013-11-09

Post score: 0


Original comments

Comment by BennyRe on 2013-11-10:
Does your code not work? Seems correct to me.

Comment by trbf on 2013-11-10:
I think that it is wrong because i made it by intuition. I am gonna put the error and the all code in the topic. Thank you

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

The error message says you provide not the correct number of arguments.

Please try:

def callback(header, angle_min, angle_max, angle_increment, time_increment, scan_time, range_min, range_max, ranges, intensities):

Not really sure about this. But you could try.


Originally posted by BennyRe with karma: 2949 on 2013-11-10

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by trbf on 2013-11-10:
I tried that but this error appear:

TypeError: callback() takes exactly 10 arguments (1 given)

[ERROR] [WallTime: 1384098176.620008] bad callback: <function callback2 at 0x2572ed8> Traceback (most recent call last): File "/opt/ros/groovy/lib/python2.7/dist-packages/rospy/topics.py", line 681, in _invoke_callback cb(msg) TypeError: callback2() takes exactly 10 arguments (1 given)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.