TypeError: las_callback() takes exactly 2 arguments (1 given)
I try to make spatial median filtering that uses in sensor_msgs/LaserScan.msg. this is my python code:
#!/usr/bin/env python
"""
"""
import rospy
from sensor_msgs.msg import LaserScan
def las_callback(self, msg):
data_list=list(msg.ranges)
self.median_ranges=[]
self.median_filter_size=3
for i in range(0, len(data_list)):
if (i>= self.median_filter_size and i<(len(data_list)-self.median_filter_size)):
media_call=median(data_list[i-self.median_filter_size:i+self.median_filter_size+1])
self.median_ranges.append(median_call)
print(media_call)
rospy.init_node('laser_readings')
sub = rospy.Subscriber('/base_scan', LaserScan, las_callback)
rospy.spin()
when I try to rosrun this code, it shows me a worrying message is:
[ERROR] [1607831425.437657, 1678.699000]: bad callback: <function las_callback at 0x7fb50adbddd0>
Traceback (most recent call last):
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
TypeError: las_callback() takes exactly 2 arguments (1 given)
How can I solve this problem? thanks for your help!