IE-482-582 / spring2023

5 stars 8 forks source link

Homework 1 - Lidar Functions #7

Open cmurray3 opened 1 year ago

cmurray3 commented 1 year ago

Your assignment is to write 3 Python functions that will use Lidar data in the format sensor_msgs/LaserScan.

  1. Get the distance at a particular angle.
  2. Get the distances over a range of angles.
    • For this, your function should return a list of distances.
  3. Get size of gap/opening x meters ahead.
    • The idea is to use this function to determine if the space in front of your robot is "open".

Assumptions


Some sample code

import math
TWO_PI = math.pi*2
PI     = math.pi

# Limit the input angle to be no more than 360-degrees (2pi radians):
inputAngleRad = inputAngleRad % TWO_PI

def degrees2radians(deg):
    # Convert a given number of degrees to radians
    return deg * (TWO_PI/360)
cmurray3 commented 1 year ago

Some code from today's class:

def getIndex(angle_desired, incr, min_angle, max_angle, is_cw):

    returns the index for a given angle

def f(angle_desired, ranges, incr, min_angle, max_angle, is_cw):
    '''
    This function returns the distance (in meters) at an angle of `angle_desired`.

    INPUTS:
        - angle_desired.  
        - ranges.  List of distances.  See LaserScan.ranges for example
    OUTPUT:
    '''

    myIndex = getIndex(angle_desired, incr, min_angle, max_angle, is_cw)

    return ranges[myIndex]

def g(angle_start, angle_end, ranges, incr, min_angle, max_angle, is_cw):
    myStartIndex = getIndex(angle_start, incr, min_angle, max_angle, is_cw)
    myEndIndex   = getIndex(angle_end,   incr, min_angle, max_angle, is_cw)

    return ranges[myStartIndex : myEndIndex + 1]
cmurray3 commented 1 year ago

Use this link to submit your assignment: https://classroom.github.com/a/QKnftk6K