Пример #1
0
def main():
    # read in tire data
    config = configparser.ConfigParser()
    config.read('data/tire/hoosier_lc0_sorted.ini')

    # Extract coefficients
    general = {key: float(config['general'][key]) for key in config['general']}
    py = {key: float(config['lateral'][key]) for key in config['lateral']}
    qz = {key: float(config['self_aligning'][key]) for key in config['self_aligning']}
    px = {key: float(config['longitudinal'][key]) for key in config['longitudinal']}
    qx = {key: float(config['overturning'][key]) for key in config['overturning']}
    rx = {key: float(config['longitudinal_combined'][key]) for key in config['longitudinal_combined']}
    ry = {key: float(config['lateral_combined'][key]) for key in config['lateral_combined']}
    sz = {key: float(config['self_aligning_combined'][key]) for key in config['self_aligning_combined']}
    qy = {key: float(config['roll_moment'][key]) for key in config['roll_moment']}

    # build tire model
    tire_model = Pacejka(general, py, qz, px, qx, rx, ry, sz, qy)

    # read in vehicle data
    config.read('data/vehicle/generic_fsae.ini')
    dimensions = {key: float(config['dimensions'][key]) for key in config['dimensions']}

    # build vehicle class
    car = Vehicle(tire_model, tire_model, tire_model, tire_model,
            dimensions)

    # do some basic tasks
    car.velocity = 50/3.6

    delta_sweep = np.arange(-20,20)  # in degrees
    forces = [car.resolve_forces(math.radians(delta)).flat[1] for delta in delta_sweep]

    import pdb; pdb.set_trace()
Пример #2
0
    def read_vehicle(self):
        if not self.read_boolean():
            return None

        return Vehicle(
            self.read_long(), self.read_double(), self.read_double(), self.read_double(), self.read_long(),
            self.read_int(), self.read_int(), self.read_double(), self.read_double(), self.read_double(),
            self.read_double(), self.read_double(), self.read_double(), self.read_double(), self.read_int(),
            self.read_int(), self.read_int(), self.read_int(), self.read_int(), self.read_int(),
            self.read_enum(VehicleType), self.read_boolean(), self.read_boolean(), self.read_ints()
        )
    def read_vehicle(self):
        if not self.read_boolean():
            return None

        byte_array = self.read_bytes(128)
        vehicle = RemoteProcessClient.VEHICLE_STRUCT.unpack(byte_array)

        return Vehicle(vehicle[0], vehicle[1], vehicle[2], vehicle[3],
                       vehicle[4], vehicle[5], vehicle[6], vehicle[7],
                       vehicle[8], vehicle[9], vehicle[10], vehicle[11],
                       vehicle[12], vehicle[13], vehicle[14], vehicle[15],
                       vehicle[16], vehicle[17], vehicle[18], vehicle[19],
                       self.read_enum(VehicleType), self.read_boolean(),
                       self.read_boolean(), self.read_ints())
Пример #4
0
def build_vehicle_model(vehicle_config, tire_config):
    '''Builds a vehicle model instance using parameters in vehicle_config and tire_config'''

    config = configparser.ConfigParser(inline_comment_prefixes=';')
    config.read(vehicle_config)

    mass = {key: float(config['mass'][key]) for key in config['mass']}
    geometry = {key: float(config['geometry'][key]) for key in config['geometry']}
    suspension = {key: float(config['suspension'][key]) for key in config['suspension']}

    # TODO: allow flexible way to specify tires on all tires
    tire_model = build_tire_model(tire_config)

    return Vehicle(tire_model, tire_model, tire_model, tire_model, mass, geometry, suspension)
Пример #5
0
    def read_vehicle(self):
        if not self.read_boolean():
            return None

        byte_array = self.read_bytes(128)
        vehicle = struct.unpack(
            RemoteProcessClient.BYTE_ORDER_FORMAT_STRING + "q3dq2i7d6i",
            byte_array)

        return Vehicle(vehicle[0], vehicle[1], vehicle[2], vehicle[3],
                       vehicle[4], vehicle[5], vehicle[6], vehicle[7],
                       vehicle[8], vehicle[9], vehicle[10], vehicle[11],
                       vehicle[12], vehicle[13], vehicle[14], vehicle[15],
                       vehicle[16], vehicle[17], vehicle[18], vehicle[19],
                       self.read_enum(VehicleType), self.read_boolean(),
                       self.read_boolean(), self.read_ints())
Пример #6
0
def simulate(cars_no):
    # env = simpy.rt.RealtimeEnvironment()
    env = simpy.Environment()
    light_groups = [[13, 15], [17, 19], [12, 14], [16, 18]]

    lightManager = TrafficLightManager(env, light_groups, 20)
    graph = Graph(lightManager)

    vehicles = []

    for c in range(cars_no):
        vehicle = Vehicle(env, c, random.choice(graph.start_nodes),
                          random.choice(graph.end_nodes), graph,
                          max(numpy.random.normal(loc=20.0, scale=2.0), 20.0))
        vehicles.append(vehicle)

    env.run(until=60 * 60 * 2)

    return vehicles
Пример #7
0
def dispatch_vehicle(vehicle: Vehicle):
    with Client(
            transport=backend_transport,
            fetch_schema_from_transport=True,
    ) as session:
        vehicle.image = base64.b64encode(
            cv2.imencode('.jpg', vehicle.image)[1])

        session.execute(
            gql('''
            query{
                fuckCrossroad(vehicle: {
                image:"''' + vehicle.image.decode('utf-8') + '''",
                licensePlate: ''' + 'null' + ''',
                color: "''' + vehicle.color + '''",
                speed: ''' + str(vehicle.speed) + '''
            }){
                    licensePlate
                }
            }
            '''))
def draw_bounding_box_on_image(current_frame_number,
                               image,
                               ymin,
                               xmin,
                               ymax,
                               xmax,
                               color='red',
                               thickness=4,
                               display_str_list=(),
                               use_normalized_coordinates=True,
                               roi_position=200):
    """Adds a bounding box to an image.

  Each string in display_str_list is displayed on a separate line above the
  bounding box in black text on a rectangle filled with the input 'color'.
  If the top of the bounding box extends to the edge of the image, the strings
  are displayed below the bounding box.

  Args:
    image: a PIL.Image object.
    ymin: ymin of bounding box.
    xmin: xmin of bounding box.
    ymax: ymax of bounding box.
    xmax: xmax of bounding box.
    color: color to draw bounding box. Default is red.
    thickness: line thickness. Default value is 4.
    display_str_list: list of strings to display in box
                      (each to be shown on its own line).
    use_normalized_coordinates: If True (default), treat coordinates
      ymin, xmin, ymax, xmax as relative to the image.  Otherwise treat
      coordinates as absolute.
      :param roi_position:
  """
    csv_line = ""  # to create new csv line consists of vehicle type, predicted_speed, color and predicted_direction
    update_csv = False  # update csv for a new vehicle that are passed from ROI - just one new line for each vehicles
    is_vehicle_detected = [0]
    draw = ImageDraw.Draw(image)
    im_width, im_height = image.size
    if use_normalized_coordinates:
        (left, right, top, bottom) = (xmin * im_width, xmax * im_width,
                                      ymin * im_height, ymax * im_height)
    else:
        (left, right, top, bottom) = (xmin, xmax, ymin, ymax)
    draw.line([(left, top), (left, bottom), (right, bottom), (right, top),
               (left, top)],
              width=thickness,
              fill=color)

    predicted_speed = None  # means not available, it is just initialization
    predicted_direction = None  # means not available, it is just initialization
    vehicle = None
    image_temp = numpy.array(image)
    detected_vehicle_image = image_temp[int(top):int(bottom),
                                        int(left):int(right)]
    predicted_color = color_recognition_api.color_recognition(
        detected_vehicle_image)
    if (
            bottom > roi_position
    ):  # if the vehicle get in ROI area, vehicle predicted_speed predicted_color algorithms are called - 200 is an arbitrary value, for my case it looks very well to set position of ROI line at y pixel 200
        predicted_direction, predicted_speed, is_vehicle_detected, update_csv = speed_prediction.predict_speed(
            top, bottom, right, left, current_frame_number,
            detected_vehicle_image, roi_position)
        vehicle = Vehicle(color=predicted_color,
                          speed=predicted_speed,
                          image={
                              "left": left / image_temp.shape[1],
                              "right": right / image_temp.shape[1],
                              "top": top / image_temp.shape[0],
                              "bottom": bottom / image_temp.shape[0]
                          },
                          direction=predicted_direction)

    try:
        font = ImageFont.truetype('arial.ttf', 16)
    except IOError:
        font = ImageFont.load_default()

    # If the total height of the display strings added to the top of the bounding
    # box exceeds the top of the image, stack the strings below the bounding box
    # instead of above.
    display_str_list[0] = predicted_color + " " + display_str_list[0]
    csv_line = predicted_color + "," + str(predicted_direction) + "," + str(
        predicted_speed)  # csv line created
    display_str_heights = [font.getsize(ds)[1] for ds in display_str_list]

    # Each display_str has a top and bottom margin of 0.05x.
    total_display_str_height = (1 + 2 * 0.05) * sum(display_str_heights)

    if top > total_display_str_height:
        text_bottom = top
    else:
        text_bottom = bottom + total_display_str_height

    # Reverse list and print from bottom to top.
    for display_str in display_str_list[::-1]:
        text_width, text_height = font.getsize(display_str)
        margin = np.ceil(0.05 * text_height)
        draw.rectangle([(left, text_bottom - text_height - 2 * margin),
                        (left + text_width, text_bottom)],
                       fill=color)
        draw.text((left + margin, text_bottom - text_height - margin),
                  display_str,
                  fill='black',
                  font=font)
        text_bottom -= text_height - 2 * margin
        return is_vehicle_detected, csv_line, update_csv, vehicle
Пример #9
0
def main():
    # read in tire data
    config = configparser.ConfigParser()
    config.read('data/tire/hoosier_lc0_sorted.ini')

    # Extract coefficients
    general = {key: float(config['general'][key]) for key in config['general']}
    py = {key: float(config['lateral'][key]) for key in config['lateral']}
    qz = {
        key: float(config['self_aligning'][key])
        for key in config['self_aligning']
    }
    px = {
        key: float(config['longitudinal'][key])
        for key in config['longitudinal']
    }
    qx = {
        key: float(config['overturning'][key])
        for key in config['overturning']
    }
    rx = {
        key: float(config['longitudinal_combined'][key])
        for key in config['longitudinal_combined']
    }
    ry = {
        key: float(config['lateral_combined'][key])
        for key in config['lateral_combined']
    }
    sz = {
        key: float(config['self_aligning_combined'][key])
        for key in config['self_aligning_combined']
    }
    qy = {
        key: float(config['roll_moment'][key])
        for key in config['roll_moment']
    }

    # build tire model
    tire_model = Pacejka(general, py, qz, px, qx, rx, ry, sz, qy)

    # read in vehicle data
    config.read('data/vehicle/generic_fsae.ini')
    dimensions = {
        key: float(config['dimensions'][key])
        for key in config['dimensions']
    }

    # build vehicle class
    car = Vehicle(tire_model, tire_model, tire_model, tire_model, dimensions)

    # do some basic tasks
    car.velocity = 50 / 3.6

    delta_sweep = np.arange(-20, 20)  # in degrees
    forces = [
        car.resolve_forces(math.radians(delta)).flat[1]
        for delta in delta_sweep
    ]

    import pdb
    pdb.set_trace()