Autopysta
Loading...
Searching...
No Matches
vehicle Class Reference

Class representing a moving vehicle on the road. More...

#include <vehicle.h>

Inheritance diagram for vehicle:
road_object

Public Member Functions

 vehicle (std::vector< double > x, int l)
 Create a vehicle with a predefined trajectory and a single lane.
 
 vehicle (std::vector< double > x, std::vector< int > l)
 Create a vehicle with a predefined trajectory across multiple lanes.
 
 vehicle (std::vector< point * > p)
 Create a vehicle with a predefined trajectory based on points.
 
 vehicle (model *m, double x, double v, int l)
 Create a vehicle with a model, initial position, speed, and lane.
 
 vehicle (model *m, point *p)
 Create a vehicle with a model and a starting point.
 
void initialize_vehicle ()
 Initialize the vehicle’s trajectory with real points.
 
paramsp ()
 Get the model parameters associated with the vehicle.
 
pointcurrent () override
 Get the current point of the vehicle.
 
void update (road_object *leader) override
 Update the vehicle's state based on a leader vehicle.
 
 ~vehicle ()
 Destructor for the vehicle class.
 
- Public Member Functions inherited from road_object
virtual ~road_object ()
 Virtual destructor for the road_object class.
 

Public Attributes

bool needs_initialization = false
 Flag indicating if the vehicle requires initialization within the simulation.
 
std::vector< point * > placeholder_points
 A vector of placeholder points used before simulation starts.
 
- Public Attributes inherited from road_object
modelm = nullptr
 Pointer to the model associated with the object (optional).
 
generalized_trajectorytraj = nullptr
 Object's trajectory, which defines its movement and positions over time.
 
std::queue< point * > defined_t
 A queue of defined trajectory points provided by the user.
 

Detailed Description

Class representing a moving vehicle on the road.

The vehicle class models a moving vehicle, which can either follow a predefined trajectory or behave according to a dynamic model. It offers multiple constructors to accommodate different ways of specifying the vehicle’s movement, including position history, points, or models that dictate its behavior.

Constructor & Destructor Documentation

◆ vehicle() [1/5]

vehicle::vehicle ( std::vector< double > x,
int l )

Create a vehicle with a predefined trajectory and a single lane.

This constructor initializes a vehicle with a list of X positions and a single lane. It assumes that the positions are equally spaced in time, with a fixed delta time between points.

Parameters
xA vector of X positions representing the vehicle’s position over time.
lThe lane in which the vehicle is moving.

◆ vehicle() [2/5]

vehicle::vehicle ( std::vector< double > x,
std::vector< int > l )

Create a vehicle with a predefined trajectory across multiple lanes.

This constructor initializes a vehicle with a list of X positions and a list of lane positions. It assumes that the positions are equally spaced in time, with a fixed delta time between points.

Parameters
xA vector of X positions representing the vehicle’s position over time.
lA vector of lane positions corresponding to each X position.
Exceptions
ExceptionIf the size of x and l do not match.

◆ vehicle() [3/5]

vehicle::vehicle ( std::vector< point * > p)

Create a vehicle with a predefined trajectory based on points.

This constructor initializes a vehicle with a list of point objects that define its trajectory over time.

Parameters
pA vector of pointers to point objects representing the vehicle's trajectory.
Exceptions
ExceptionIf the size of the trajectory is too short.

◆ vehicle() [4/5]

vehicle::vehicle ( model * m,
double x,
double v,
int l )

Create a vehicle with a model, initial position, speed, and lane.

This constructor initializes a vehicle with a dynamic model that dictates its behavior, along with its initial position, speed, and lane.

Parameters
mPointer to the model that will describe the vehicle's behavior.
xThe initial X position of the vehicle.
vThe initial speed of the vehicle.
lThe lane in which the vehicle starts.

◆ vehicle() [5/5]

vehicle::vehicle ( model * m,
point * p )

Create a vehicle with a model and a starting point.

This constructor initializes a vehicle with a dynamic model and a starting point, which contains information about its position, speed, and lane.

Parameters
mPointer to the model that will describe the vehicle's behavior.
pPointer to the initial point of the vehicle.

◆ ~vehicle()

vehicle::~vehicle ( )

Destructor for the vehicle class.

Cleans up dynamically allocated memory associated with the vehicle's trajectory.

Member Function Documentation

◆ current()

point * vehicle::current ( )
overridevirtual

Get the current point of the vehicle.

This method returns the vehicle's current position and state based on its trajectory.

Returns
A pointer to the current point.

Implements road_object.

◆ initialize_vehicle()

void vehicle::initialize_vehicle ( )

Initialize the vehicle’s trajectory with real points.

This method initializes the placeholder points of a vehicle that was created with a predefined trajectory, replacing them with real points in the simulation.

◆ p()

params * vehicle::p ( )

Get the model parameters associated with the vehicle.

Returns
A pointer to the model parameters (params).

◆ update()

void vehicle::update ( road_object * leader)
overridevirtual

Update the vehicle's state based on a leader vehicle.

This method updates the vehicle's state (position, speed, etc.) based on the trajectory of a leading vehicle. If no leader is provided, the vehicle's state is updated according to its model or predefined trajectory.

Parameters
leaderA pointer to the road object acting as the leader vehicle.
Exceptions
ExceptionIf the vehicle runs out of predefined points for the simulation.

Implements road_object.


The documentation for this class was generated from the following file: