Example #1
0
def car_obstacles(frontview, cars):
    """
    Determines if there are any other_cars within the car's bin and then calculates the distance to the
    nearest car in the same bin

    Parameters
    __________
    :param frontview:    object: FrontView object
    :param      cars: dataframe:

    Returns
    _______
    :return distance: list: double or False (returns False if no car obstacle found)
    """
    x_space, y_space = models.upcoming_linspace(frontview)
    if x_space.any() and y_space.any():
        other_cars = cars.drop(frontview.car.name)
        obstacles = (frontview.car['xbin'] == other_cars['xbin']) & (frontview.car['ybin'] == other_cars['ybin'])
        if obstacles.any():
            nearby_cars = other_cars[obstacles]
            for car in nearby_cars.iterrows():
                car_within_xlinspace = np.isclose(x_space, car[1]['x'], rtol=1.0e-6).any()
                car_within_ylinspace = np.isclose(y_space, car[1]['y'], rtol=1.0e-6).any()

                if car_within_xlinspace and car_within_ylinspace:
                    first_x, first_y = car[1]['x'], car[1]['y']
                    vector = (first_x - frontview.car['x'], first_y - frontview.car['y'])
                    distance = models.magnitude(vector)
                    return distance
                else:
                    return False
        else:
            return False
    else:
        return False
Example #2
0
    def distance_to_node(self):
        """
        Determines the distance to the most immediate node

        :return distance: double
        """
        next_node = np.array(self.upcoming_node_position())
        distance_vector = next_node - self.position
        distance = models.magnitude(distance_vector)
        return distance
Example #3
0
def light_obstacles(frontview, lights):
    """
    Determines the distance to red traffic lights. If light is green, returns False

    Parameters
    __________
    :param  frontview:    object: FrontView object
    :param     lights: dataframe:

    Returns
    _______
    :return distance: list: double for False (returns False if no red light is found)
    """
    x_space, y_space = models.upcoming_linspace(frontview)
    if x_space.any() and y_space.any():
        obstacles = (frontview.car['xbin'] == lights['xbin']) & (
            frontview.car['ybin'] == lights['ybin'])
        if obstacles.any():
            nearby_lights = lights[obstacles]
            for light in nearby_lights.iterrows():
                light_within_xlinspace = np.isclose(x_space[1:],
                                                    light[1]['x'],
                                                    rtol=1.0e-6).any()
                light_within_ylinspace = np.isclose(y_space[1:],
                                                    light[1]['y'],
                                                    rtol=1.0e-6).any()

                if light_within_xlinspace and light_within_ylinspace:
                    car_vector = [
                        light[1]['x'] - frontview.car['x'],
                        light[1]['y'] - frontview.car['y']
                    ]
                    face_values = light[1]['go-values']
                    face_vectors = [(light[1]['out-xvectors'][i],
                                     light[1]['out-yvectors'][i])
                                    for i in range(light[1]['degree'])]

                    for value, vector in zip(face_values, face_vectors):
                        if not value and models.determine_anti_parallel_vectors(
                                car_vector, vector):
                            distance = models.magnitude(car_vector)
                            return distance
                        else:
                            continue
                else:
                    return False
        else:
            return False
    else:
        return False