def sensor_info_callback(data, bhi_pub):
    rospy.loginfo('Distance reading from the sensor is: %f',
                  data.sensor_data.range)

    # Compute the height of the box.
    box_height = 2.0 - data.sensor_data.range
    rospy.loginfo('box_height: %f', box_height)

    # Boxes that are detected to be shorter than 10cm are due to sensor noise. Don't publish!
    if ((box_height < 0.1) | (box_height > 1.9)):
        rospy.loginfo('NO BOX')
        rospy.loginfo('===========================')
        pass
    else:
        rospy.loginfo('BOX ON BELT')
        rospy.loginfo('===========================')

        #Create message object for publishing the box height information.
        box_height_info = BoxHeightInformation()

        #Update height of box.
        box_height_info.box_height = 2.0 - data.sensor_data.range

        # Publish box height using the publisher argument passed to the callback function.
        #        bhi_publisher.publish(bhi_pub)
        bhi_publisher.publish(box_height_info)
def sensor_info_callback(data, bhi_pub):
    # Compute the height of the box.
    height_box = data.sensor_data.range
    # Boxes that are detected to be shorter than 10cm are due to sensor noise.
    # Do not publish information about them.
    if height_box < 1.9:
        pass
    else:
        # Declare a message object for publishing the box height information.
        box_height_info = BoxHeightInformation()
        # Update height of box.
        box_height_info.box_height = height_box
        # Publish box height using the publisher argument passed to the callback function.
        bhi_pub.publish(box_height_info)
Exemplo n.º 3
0
def sensor_info_callback(data, bhi_pub):
    height_box = 2 - data.sensor_data.range
    # Compute the height of the box.
    # Boxes that are detected to be shorter than 10cm are due to sensor noise. Do not publish information about them.
    if height_box < 0.1:
        pass
    else:
        # Declare a message object for publishing the box height information.
        box_height_info = BoxHeightInformation()
        # Update height of box.
        box_height_info.box_height = height_box
        box_height_info.units_measurement = "meters"
        # Publish box height using the publisher argument passed to the callback function.
        bhi_pub.publish(box_height_info)
        print("published: ", box_height_info.box_height,
              box_height_info.units_measurement)
def sensor_info_callback(data, bhi_pub):

    height_box = 2 - data.sensor_data.range
    #print(height_box)
    #print(data)
    #time.sleep(2)

    # Compute the height of the box.
    # Boxes that are detected to be shorter than 10cm are due to sensor noise.
    # Do not publish information about them.
    if (height_box == 0.0 and height_box <= 0.1):
        #print("Box is not there")
        pass
    else:
        # Declare a message object for publishing the box height information.
        box_height_info = BoxHeightInformation()
        # Update height of box
        box_height_info.box_height = height_box
        # Publish box height using the publisher argument passed to the callback function.
        bhi_publisher.publish(box_height_info)
        print(height_box)
Exemplo n.º 5
0
        rospy.loginfo("The process was a success with value of %f",
                      service_response.distance_feet)
        bhif.box_height = service_response.distance_feet
        print(bhif.box_height)
        bhif_publisher.publish(bhif)
    except rospy.ServiceException, e:
        print "Service call failed: %s" % e


if __name__ == '__main__':
    # Initialize the ROS node here.
    rospy.init_node('box_height_in_feet', anonymous=True)
    bhif_publisher = rospy.Publisher('box_height_in_feet_info',
                                     BoxHeightInformation)
    bhif = BoxHeightInformation()
    bhif.box_height = 3.25
    print(bhif.box_height)
    rospy.sleep(3)

    # First wait for the service to become available - Part2.
    rospy.loginfo("Waiting for service...")
    rospy.wait_for_service('metres_to_feet')
    rospy.loginfo("Service %s is now available", 'metres_to_feet')

    # Create a subscriber to the box height topic - Part1.
    rospy.Subscriber('box_height_info', BoxHeightInformation,
                     box_height_info_callback)

    # Prevent this ROS node from terminating until Ctrl+C is pressed.
    rospy.spin()