vehicles package

Overview

Vehicles package provides with classes and methods to create vehicles of different types, and a base Vehicle class that contains all the basic functionalities of any vehicle. We adopted a factory design pattern for the creation of a vehicle wherein, the creation of every Vehicle is forced through a common factory class VehicleFactory which has a build_vehicle method, which takes the vehicle config such as vehicle type, sensors, engine and instantiates the corresponding Vehicle object, and place_on_map which takes a start node and end node of type CATS.maps.Node and places it on the map.

We implemented different types of vehicles which inherit the base Vehicle class. As of now, we have Car, Truck, Bus and Intelligent Car. The different types of vehicles differ in their physical attributes like length, width, engine, sensors, decision modules, etc. IntelligentCar is the utopian smart car with complete autonomy, V2X communication, adherence to traffic rules etc. Developing the decision module of this type of vehicle is the main goal of this software.

vehicles.vehicle module

class core.lib.vehicles.vehicle.Vehicle(_id, name, physics, driver, adas, sensor_suite, _type)

Contains the basic functionalities of most vehicles. It provides methods to create vehicles of different types.

_ID

int – unique id of the vehicle

_name

str – name of the vehicle if any

_physics

object – physics object that simulates a two wheel or four wheel drive

_sensor_suite

dict – dict of various sensors

_adas

object – instantiation of ADAS class

_type

str – type of the vehicle

_v2x

object – communication module

_x

float – coordinate

_y

float – coordinate

_length

float – length

_width

float – width

_color

str – color

_perceived_attr

dict – sensor readings

_localized_attr

dict – inferences from the sensor readings

_traffic_graph

object – maps class

_trip_start_time

int – start time

_current_node

object – present node

_next_node

object – next node

_current road

object – current road

calculate_route(source, destination, weight='time')

Calculates a shortest route with preference on certain aspect.

Parameters:
  • source (int) – starting point node id
  • destination (int) – ending point node id
  • weight (str) – parameters based on which the cost is calculated
Returns:

a list of the node ids along the shortest path from the source to the destination

Return type:

list

driving_decision(reroute_flag=True)

This is the intelligence module which decides what to do based on the perceived and localized attributes. Decisions include lane change, cruise control, overtake, etc.

Parameters:reroute_flag (Optional[bool]) – a flag which determines if the vehicle has to be rerouted
Returns:(steering_angle, gas, brake)
Return type:tuple
get_distance_from_last_segment()
Returns:the distance from the vehicle to the last segment
Return type:float
get_distance_from_next_segment()
Returns:the distance from the vehicle to the next segment
Return type:float
get_distance_from_next_subnode()

Calculates the distance between the vehicle position and the next subnode.

get_distance_from_road_end()

Calculates the distance between the vehicle position and the end of the road.

get_next_turn_direction()
Returns:direction for the next turn
Return type:str
localize()

Fuses sensor readings and data from communication module to localize the vehicle, e.g. distance from front vehicle, distance from lane end etc.

move(steering_angle, gas, brake)

Uses the control signal and passes to the physics/engine module to update the coordinates of the vehicle

Parameters:
  • steering_angle (float) – in radians
  • gas (float) – acceleration to give. Normalized in 0 to 1
  • brake (float) – brake to give. Normalized in 0 to 1
perceive()

Perceives the environment through the available sensors such as GPS, speed etc.

place_on_map(trip_start_node, trip_destination_node, traffic_graph)

It assigns a trip start node and destination node. Also it places the vehicle on the map.

Parameters:
  • trip_start_node (object) – start node object
  • trip_destination_node (object) – destination node object
  • traffic_graph (object) – Traffic Graph that contains all the nodes and roads
step()

Combines all the functionalities of a vehicle to a set of actions while the vehicle is moving.

update_road_string()

Updates the road string attribute of a vehicle to the current road.

vehicles.vehicle_factory module

class core.lib.vehicles.vehicle_factory.VehicleFactory

A factory design pattern for the creation of a vehicle wherein, the creation of every Vehicle is forced through this class.

static build_vehicle(_id, _type, config)

Takes the vehicle config such as vehicle type, sensors, engine and instantiates the corresponding Vehicle object.

Parameters:
  • _id (int) – unique id of the vehicle
  • _type (str) – type of the vehicle
  • config (dict) – information about the vehicles
static place_vehicle(vehicle, start_node, end_node, map_2d)

Takes a start node and end node of type CATS.maps.Node and places it on the map (adds to CATS.maps.TrafficGraph). It is analogous to starting a trip, by setting the source and destination.

Parameters:
  • vehicle (object) – vehicle object that has to be placed on the map
  • start_node (object) – start node object
  • end_node (object) – end node object
  • map_2d (object) – TrafficGraph object on which the vehicle is placed