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

I think you can wait for the first LaserScan message before setting up your publisher in the class constructor...something like this:

    def __init__(self):
        self.sub2 = rospy.Subscriber("tb3_1/scan",LaserScan,self.lidar_callback)
        rospy.wait_for_message("tb3_1/scan,LaserScan)
        self.pub = rospy.Publisher("tb3_1/cmd_vel",Twist,queue_size=100)

That returns the first message but you can just ignore it if you want.

I think you can wait for the first LaserScan message before setting up your publisher in the class constructor...something like this:

    def __init__(self):
        self.sub2 = rospy.Subscriber("tb3_1/scan",LaserScan,self.lidar_callback)
        rospy.wait_for_message("tb3_1/scan,LaserScan)
rospy.wait_for_message("tb3_1/scan",LaserScan)
        self.pub = rospy.Publisher("tb3_1/cmd_vel",Twist,queue_size=100)

That returns the first message but you can just ignore it if you want. want.