0

I would like to improve turtlebot3 LDS-01 sensor by applying some algorithm to the sensor. So my strategy is to improve and modify the value of Laserscan.ranges (which is the distance between the sensor to the obstacles) by subscribing the “/scan” topic, applying the algorithm to the Laserscan.ranges and publish it again to the “/scan” topic. How can I do that?. I have some idea in my mind like:

  1. Create new topic, publish the sensor value to the new topic, subscribe the new topic and applying the algorithm and lastly, publish it to the “/scan” topic. But this first idea, I cannot find the cpp or python file that publish to “/scan” topic. Where can I find that file? So that I can change the coding to publish the Laserscan.ranges to the new topic.

  2. Modify the sensor_msgs/LaserScan by applying the algorithm to the float32 range. But this second idea, I dont know is it the message can be modified? If can, how to modify the sensor_msgs/LaserScan to apply the algorithm?

And lastly, if there are any suggestion, tutorial or online courses that I can take related to this question, I would be very happy to hear.

This image is summary for the idea 1

Summary for the idea 1

AmirulJ
  • 118
  • 1
  • 11

1 Answers1

0

You shouldn't ever publish back out on a sensor topic after modifying the message. If you do this other subscribers will just see a mixture of the modified and non-modified messages. Instead publish it out on a separate topic like this:

scan_msg_pub = rospy.Publisher('/scan/edited', LaserScan, queue_size=10)
def scan_msg_cb(msg):
    #Edit message here
    msg.header.frame_id = "new_frame_id" #You can change msg fields like this
    scan_msg_pub.publish(msg)

def main():
    rospy.Subscriber('/scan', LaserScan, scan_msg_cb)

    rospy.spin()

if __name__ == '__main__':
    rospy.init_node('scan_edit')
    main()
BTables
  • 4,413
  • 2
  • 11
  • 30
  • Thank you very much for the answer. I would like to ask. if I use Gmapping package, where can I edit to subscribe a new topic? Because I have search and didnt find the file that I can modified to subscribe the new topic – AmirulJ Sep 08 '21 at 15:06
  • 1
    You can create a subscriber anywhere as long as the correct imports/headers are used. I'd recommend making a new question with further details. – BTables Sep 08 '21 at 16:15
  • Thank you very much sir for your help. If you don't mind can you help me answer this question also which is related to this question. https://stackoverflow.com/q/69120186/16594158 – AmirulJ Sep 09 '21 at 14:58
  • I will take a look in a minute. Glad it helped, feel free to choose it as the accepted answer if you think it answered your question appropriately. – BTables Sep 09 '21 at 15:10