controls  3.0.0
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
Vehicle Class Reference

Central vehicle abstraction managing the controller state machine, trajectory execution, force computation, and thrust allocation. More...

#include <Vehicle.h>

Classes

struct  ControllerStatus
 Snapshot of controller status exposed to external callers. More...
 

Public Types

enum class  ControllerState { DISABLED , STATIONKEEP , RUNNING }
 Possible operational states of the controller. More...
 

Public Member Functions

 Vehicle (std::shared_ptr< SystemDynamicsBase > system_dynamics, std::shared_ptr< ControllerConfig > controller_config, std::shared_ptr< VehicleControllerInterface > vehicle_controller, std::unique_ptr< ThrustAllocator > thrust_allocator)
 Constructs the vehicle with all required subsystems. More...
 
 ~Vehicle ()
 Drains the pending request queue, fulfilling all unfulfilled promises. More...
 
 Vehicle (const Vehicle &)=delete
 
Vehicleoperator= (const Vehicle &)=delete
 
 Vehicle (Vehicle &&)=delete
 
Vehicleoperator= (Vehicle &&)=delete
 
request::RequestHandle< request::RequestHandleState::PENDINGrequest_stationkeep ()
 Enqueues a request to enter the STATIONKEEP state. More...
 
request::RequestHandle< request::RequestHandleState::PENDINGrequest_disable ()
 Enqueues a request to enter the DISABLED state. More...
 
request::RequestHandle< request::RequestHandleState::PENDINGrequest_trajectory (std::unique_ptr< TrajectoryBase > trajectory)
 Enqueues a request to execute a trajectory. More...
 
ControllerStatus get_controller_status () const
 Returns a thread-safe snapshot of the current controller status. More...
 
bool is_disabled () const
 Returns true if the controller is currently in the DISABLED state. More...
 
bool is_stationkeeping () const
 
void process_pending (double t, const State &current_state, moodycamel::ConcurrentQueue< DebugMessage > &debug_queue)
 Drains the pending request queue and performs state transitions. More...
 
Vector6d get_force (double t, double dt, const State &current_state)
 Samples the active trajectory and runs the controller to compute a body force. More...
 
std::tuple< bb_controls_msgs::msg::Thrusters, bb_controls_msgs::msg::ThrusterForces, Vector6dallocate_force (const Vector6d &force) const
 Allocates a body force vector to per-thruster PWM commands. More...
 
void update_controller_status (const ControllerStatus &status)
 Writes a new controller status snapshot. More...
 
std::tuple< State, double > get_state () const
 Returns the most recently stored vehicle state and its timestamp. More...
 
void set_state (const State &state, double t)
 Stores a new vehicle state with its timestamp. More...
 
float get_battery_voltage () const
 Returns the most recently stored battery voltage. More...
 
void set_battery_voltage (float battery_voltage)
 Stores the current battery voltage. More...
 
double get_trajectory_progress (double t) const
 Returns fractional trajectory progress for the active trajectory. More...
 
Vector6d get_body_pose_error () const
 Returns the most recent body-frame pose error from the active controller. More...
 
void update_saturation_cost (double yaw_xy, double z_rp)
 Updates the per-axis thruster saturation cost used for integral anti-windup. More...
 

Public Attributes

std::shared_ptr< SystemDynamicsBasesystem
 Shared vehicle dynamics model (set once in ctor, mutated via setters only) More...
 
std::shared_ptr< ControllerConfigcontroller_config
 Shared controller tuning parameters (set once in ctor, fields mutated by param callback) More...
 
std::shared_ptr< VehicleControllerInterfacecontroller
 Active vehicle controller implementation (set once in ctor, called from control loop only) More...
 
std::unique_ptr< ThrustAllocatorthrust_allocator
 Thrust allocator (set once in ctor, called from control loop and teleop callback) More...
 
std::shared_ptr< Trajectory6DOFLimitsvehicle_limits
 Velocity and acceleration limits (set once in ctor, fields mutated by param callback) More...
 

Detailed Description

Central vehicle abstraction managing the controller state machine, trajectory execution, force computation, and thrust allocation.

Exposes two distinct APIs:

Thread safety: state and battery voltage are protected by shared mutexes. The request queue is protected by a plain mutex. All Consumer API methods must be called from a single thread.

Member Enumeration Documentation

◆ ControllerState

Possible operational states of the controller.

Enumerator
DISABLED 
STATIONKEEP 
RUNNING 

Constructor & Destructor Documentation

◆ Vehicle() [1/3]

Vehicle::Vehicle ( std::shared_ptr< SystemDynamicsBase system_dynamics,
std::shared_ptr< ControllerConfig controller_config,
std::shared_ptr< VehicleControllerInterface vehicle_controller,
std::unique_ptr< ThrustAllocator thrust_allocator 
)

Constructs the vehicle with all required subsystems.

Parameters
system_dynamics[in] Vehicle dynamics model
controller_config[in] Controller tuning parameters
vehicle_controller[in] Controller implementation
thrust_allocator[in] Thrust allocation subsystem

◆ ~Vehicle()

Vehicle::~Vehicle ( )

Drains the pending request queue, fulfilling all unfulfilled promises.

Prevents broken promises if any futures are still alive when the Vehicle is destroyed.

◆ Vehicle() [2/3]

Vehicle::Vehicle ( const Vehicle )
delete

◆ Vehicle() [3/3]

Vehicle::Vehicle ( Vehicle &&  )
delete

Member Function Documentation

◆ allocate_force()

std::tuple< bb_controls_msgs::msg::Thrusters, bb_controls_msgs::msg::ThrusterForces, Vector6d > Vehicle::allocate_force ( const Vector6d force) const

Allocates a body force vector to per-thruster PWM commands.

Parameters
force[in] 6-element body force/torque vector in N and Nm
Returns
Tuple of (PWM command message, per-thruster force message, achieved body force)

◆ get_battery_voltage()

float Vehicle::get_battery_voltage ( ) const

Returns the most recently stored battery voltage.

Returns
Battery voltage in volts, or FLT_MAX if not yet set

◆ get_body_pose_error()

Vector6d Vehicle::get_body_pose_error ( ) const

Returns the most recent body-frame pose error from the active controller.

Returns
6-element body-frame pose error vector

◆ get_controller_status()

Vehicle::ControllerStatus Vehicle::get_controller_status ( ) const

Returns a thread-safe snapshot of the current controller status.

Returns
Current ControllerStatus

◆ get_force()

Vector6d Vehicle::get_force ( double  t,
double  dt,
const State current_state 
)

Samples the active trajectory and runs the controller to compute a body force.

Parameters
t[in] Current ROS time in seconds
dt[in] Time step in seconds since the last control tick
current_state[in] Current vehicle state
Returns
6-element body force/torque vector in N and Nm

◆ get_state()

std::tuple< State, double > Vehicle::get_state ( ) const

Returns the most recently stored vehicle state and its timestamp.

Returns
Tuple of (State, timestamp in seconds)

◆ get_trajectory_progress()

double Vehicle::get_trajectory_progress ( double  t) const

Returns fractional trajectory progress for the active trajectory.

Parameters
t[in] Current ROS time in seconds
Returns
Progress in [0, 1], or -1 if no trajectory is running

◆ is_disabled()

bool Vehicle::is_disabled ( ) const

Returns true if the controller is currently in the DISABLED state.

Returns
True if disabled

◆ is_stationkeeping()

bool Vehicle::is_stationkeeping ( ) const

◆ operator=() [1/2]

Vehicle& Vehicle::operator= ( const Vehicle )
delete

◆ operator=() [2/2]

Vehicle& Vehicle::operator= ( Vehicle &&  )
delete

◆ process_pending()

void Vehicle::process_pending ( double  t,
const State current_state,
moodycamel::ConcurrentQueue< DebugMessage > &  debug_queue 
)

Drains the pending request queue and performs state transitions.

Priority: DISABLE > STATIONKEEP > TRAJECTORY. Automatically transitions a RUNNING trajectory to STATIONKEEP when the trajectory finishes.

Parameters
t[in] Current ROS time in seconds
current_state[in] Most recent vehicle state
debug_queue[in,out] Queue to which trajectory visualisation messages are pushed

◆ request_disable()

Enqueues a request to enter the DISABLED state.

Returns
Handle containing the request UUID and an activation future

◆ request_stationkeep()

request::RequestHandle< request::RequestHandleState::PENDING > Vehicle::request_stationkeep ( )

Enqueues a request to enter the STATIONKEEP state.

Returns
Handle containing the request UUID and an activation future

◆ request_trajectory()

request::RequestHandle< request::RequestHandleState::PENDING > Vehicle::request_trajectory ( std::unique_ptr< TrajectoryBase trajectory)

Enqueues a request to execute a trajectory.

The request is rejected (future resolved to false) if the controller is currently DISABLED when the control loop processes it.

Parameters
trajectory[in] Trajectory to execute; ownership is transferred
Returns
Handle containing the request UUID and an activation future

◆ set_battery_voltage()

void Vehicle::set_battery_voltage ( float  battery_voltage)

Stores the current battery voltage.

Parameters
battery_voltage[in] Battery voltage in volts

◆ set_state()

void Vehicle::set_state ( const State state,
double  t 
)

Stores a new vehicle state with its timestamp.

Parameters
state[in] New vehicle state
t[in] State timestamp in seconds

◆ update_controller_status()

void Vehicle::update_controller_status ( const ControllerStatus status)

Writes a new controller status snapshot.

Parameters
status[in] Status snapshot to store

◆ update_saturation_cost()

void Vehicle::update_saturation_cost ( double  yaw_xy,
double  z_rp 
)

Updates the per-axis thruster saturation cost used for integral anti-windup.

Parameters
yaw_xy[in] Saturation cost for the X, Y, and Yaw axes
z_rp[in] Saturation cost for the Z, Roll, and Pitch axes

Member Data Documentation

◆ controller

std::shared_ptr<VehicleControllerInterface> Vehicle::controller

Active vehicle controller implementation (set once in ctor, called from control loop only)

◆ controller_config

std::shared_ptr<ControllerConfig> Vehicle::controller_config

Shared controller tuning parameters (set once in ctor, fields mutated by param callback)

◆ system

std::shared_ptr<SystemDynamicsBase> Vehicle::system

Shared vehicle dynamics model (set once in ctor, mutated via setters only)

◆ thrust_allocator

std::unique_ptr<ThrustAllocator> Vehicle::thrust_allocator

Thrust allocator (set once in ctor, called from control loop and teleop callback)

◆ vehicle_limits

std::shared_ptr<Trajectory6DOFLimits> Vehicle::vehicle_limits

Velocity and acceleration limits (set once in ctor, fields mutated by param callback)


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