|
controls
3.0.0
|
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 | |
| Vehicle & | operator= (const Vehicle &)=delete |
| Vehicle (Vehicle &&)=delete | |
| Vehicle & | operator= (Vehicle &&)=delete |
| request::RequestHandle< request::RequestHandleState::PENDING > | request_stationkeep () |
| Enqueues a request to enter the STATIONKEEP state. More... | |
| request::RequestHandle< request::RequestHandleState::PENDING > | request_disable () |
| Enqueues a request to enter the DISABLED state. More... | |
| request::RequestHandle< request::RequestHandleState::PENDING > | request_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 ¤t_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 ¤t_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, Vector6d > | allocate_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< SystemDynamicsBase > | system |
| Shared vehicle dynamics model (set once in ctor, mutated via setters only) More... | |
| std::shared_ptr< ControllerConfig > | controller_config |
| Shared controller tuning parameters (set once in ctor, fields mutated by param callback) More... | |
| std::shared_ptr< VehicleControllerInterface > | controller |
| Active vehicle controller implementation (set once in ctor, called from control loop only) More... | |
| std::unique_ptr< ThrustAllocator > | thrust_allocator |
| Thrust allocator (set once in ctor, called from control loop and teleop callback) More... | |
| std::shared_ptr< Trajectory6DOFLimits > | vehicle_limits |
| Velocity and acceleration limits (set once in ctor, fields mutated by param callback) More... | |
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.
|
strong |
| 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.
| 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 | ( | ) |
Drains the pending request queue, fulfilling all unfulfilled promises.
Prevents broken promises if any futures are still alive when the Vehicle is destroyed.
|
delete |
|
delete |
| 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.
| force | [in] 6-element body force/torque vector in N and Nm |
| float Vehicle::get_battery_voltage | ( | ) | const |
Returns the most recently stored battery voltage.
| Vector6d Vehicle::get_body_pose_error | ( | ) | const |
Returns the most recent body-frame pose error from the active controller.
| Vehicle::ControllerStatus Vehicle::get_controller_status | ( | ) | const |
Returns a thread-safe snapshot of the current controller status.
Samples the active trajectory and runs the controller to compute a body force.
| t | [in] Current ROS time in seconds |
| dt | [in] Time step in seconds since the last control tick |
| current_state | [in] Current vehicle state |
| std::tuple< State, double > Vehicle::get_state | ( | ) | const |
Returns the most recently stored vehicle state and its timestamp.
| double Vehicle::get_trajectory_progress | ( | double | t | ) | const |
Returns fractional trajectory progress for the active trajectory.
| t | [in] Current ROS time in seconds |
| bool Vehicle::is_disabled | ( | ) | const |
Returns true if the controller is currently in the DISABLED state.
| bool Vehicle::is_stationkeeping | ( | ) | const |
| 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.
| 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::RequestHandle< request::RequestHandleState::PENDING > Vehicle::request_disable | ( | ) |
Enqueues a request to enter the DISABLED state.
| request::RequestHandle< request::RequestHandleState::PENDING > Vehicle::request_stationkeep | ( | ) |
Enqueues a request to enter the STATIONKEEP state.
| 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.
| trajectory | [in] Trajectory to execute; ownership is transferred |
| void Vehicle::set_battery_voltage | ( | float | battery_voltage | ) |
Stores the current battery voltage.
| battery_voltage | [in] Battery voltage in volts |
| void Vehicle::set_state | ( | const State & | state, |
| double | t | ||
| ) |
Stores a new vehicle state with its timestamp.
| state | [in] New vehicle state |
| t | [in] State timestamp in seconds |
| void Vehicle::update_controller_status | ( | const ControllerStatus & | status | ) |
Writes a new controller status snapshot.
| status | [in] Status snapshot to store |
| void Vehicle::update_saturation_cost | ( | double | yaw_xy, |
| double | z_rp | ||
| ) |
Updates the per-axis thruster saturation cost used for integral anti-windup.
| yaw_xy | [in] Saturation cost for the X, Y, and Yaw axes |
| z_rp | [in] Saturation cost for the Z, Roll, and Pitch axes |
| std::shared_ptr<VehicleControllerInterface> Vehicle::controller |
Active vehicle controller implementation (set once in ctor, called from control loop only)
| std::shared_ptr<ControllerConfig> Vehicle::controller_config |
Shared controller tuning parameters (set once in ctor, fields mutated by param callback)
| std::shared_ptr<SystemDynamicsBase> Vehicle::system |
Shared vehicle dynamics model (set once in ctor, mutated via setters only)
| std::unique_ptr<ThrustAllocator> Vehicle::thrust_allocator |
Thrust allocator (set once in ctor, called from control loop and teleop callback)
| std::shared_ptr<Trajectory6DOFLimits> Vehicle::vehicle_limits |
Velocity and acceleration limits (set once in ctor, fields mutated by param callback)