Exemple #1
0
def test_analzyer_on_field_model():
    """
    Create a model of the field, then ask the laser to compute
    the range for sweep.  Then move the robot and ask again.
    """
    robot = Robot()
    field = FieldModel()
    tower_range = field.tower_range_from_origin()
    rotation = FakeRotation(field, robot)
    heading, sweep_range = Analyzer.range_at_heading(rotation.polar_data(), (-10,11))

    #  closest point should be dead ahead
    assert heading == 0
    assert sweep_range == tower_range

    movement = 100
    robot.move(movement)
    rotation = FakeRotation(field, robot)
    heading, sweep_range = Analyzer.range_at_heading(rotation.polar_data(), (-10,11))

    #  closest point should be dead ahead
    assert heading == 0
    assert sweep_range == (tower_range - movement)
Exemple #2
0
def update_all_results (lidar_viewer, field_model, robot, factor):
    """generate synthetic lidar data based on model and analyze/plot"""
    rotation = FakeRotation(field_model, robot)

    # do simple sweep analysis and report
    sweep_heading, sweep_range = Analyzer.range_at_heading(rotation.polar_data(), (-5, 6))
    print("Closest point in (-5,6) sweep is ({:d},{:.2f})".format(sweep_heading, sweep_range))

    # do some analysis and gather up the results so they can be plotted
    # run a 4-point r-squared and collect those less than threshold value
    cart_data = rotation.cartesian_data()

    # try out the analyzer find_wall
    (heading, distance, orientation) = find_wall_midpoint(cart_data)
    print("Analyzer.find_wall() heading {:.1f}, range {:.1f}, orientation {:.1f})".format(heading, distance, orientation))

    #  plot the polar data for reference
    lidar_viewer.plot_polar(rotation.polar_data())

    #  plot the rectangular data
    lidar_viewer.plot_cartesian(cart_data)

    #  polar markers (heading in degrees)
    find_wall_markers = [ (-heading, distance) ]

    #
    # display the average distance of data points
    # might be used to dynamically choose the r2 thresholds
    # or dynamically select the r-factor for analysis?
    avg_dist = avg_distance(cart_data)
    print("Average distance: {:.1f}\n".format(avg_dist))

    # plot any calculated markers in their specified color
    #lidar_viewer.plot_markers(r2_markers, 'g')

    lidar_viewer.plot_polar_markers(find_wall_markers, 'r')