controls  3.0.0
ThrustAllocator.h
Go to the documentation of this file.
1 #ifndef CONTROLS_ALLOCATOR_THRUST_ALLOCATOR_H
2 #define CONTROLS_ALLOCATOR_THRUST_ALLOCATOR_H
3 
7 #include <utils/Transforms.h>
8 #include <yaml-cpp/yaml.h>
9 
10 #include <bb_controls_msgs/msg/thruster_forces.hpp>
11 #include <bb_controls_msgs/msg/thrusters.hpp>
12 #include <geometry_msgs/msg/wrench_stamped.hpp>
13 
25  static constexpr double QP_WEIGHT_XY = 1.0;
26  static constexpr double QP_WEIGHT_Z = 2.0;
27  static constexpr double QP_WEIGHT_ROLL = 8.0;
28  static constexpr double QP_WEIGHT_PITCH = 8.0;
29  static constexpr double QP_WEIGHT_YAW = 6.0;
30 
31 public:
41  ThrustAllocator(std::unique_ptr<ThrusterLookupInterface> thruster_lookup,
42  std::unique_ptr<ThrustAllocationSolverInterface> solver, const std::string& yaml_config_filename);
43 
54  std::tuple<bb_controls_msgs::msg::Thrusters, bb_controls_msgs::msg::ThrusterForces, Vector6d> allocate(
55  const Vector6d& force, float battery_voltage);
56 
64  void update_cg_offset(const Vector3d& updated_cg_offset);
65 
66 private:
67  ThrusterLayout thruster_layout_{};
68 
69  std::unique_ptr<ThrusterLookupInterface> thruster_lookup_;
70  std::unique_ptr<ThrustAllocationSolverInterface> solver_;
71 
72  Vector3d cg_offset_{};
73  bool cg_offset_changed_{false};
74 
82  void load_configuration(const std::string& yaml_config_filename);
83 
87  void init_allocator();
88 };
89 
90 #endif // CONTROLS_ALLOCATOR_THRUST_ALLOCATOR_H
Eigen::Matrix< double, 6, 1 > Vector6d
Definition: Types.h:29
Converts a 6DOF body force vector to per-thruster PWM commands.
Definition: ThrustAllocator.h:23
void update_cg_offset(const Vector3d &updated_cg_offset)
Updates the centre-of-gravity offset applied to all thruster positions.
Definition: ThrustAllocator.cpp:117
ThrustAllocator(std::unique_ptr< ThrusterLookupInterface > thruster_lookup, std::unique_ptr< ThrustAllocationSolverInterface > solver, const std::string &yaml_config_filename)
Constructs the allocator, loads YAML config, and initialises the QP solver.
Definition: ThrustAllocator.cpp:11
std::tuple< bb_controls_msgs::msg::Thrusters, bb_controls_msgs::msg::ThrusterForces, Vector6d > allocate(const Vector6d &force, float battery_voltage)
Allocates a body force to per-thruster commands at the given battery voltage.
Definition: ThrustAllocator.cpp:84
Manages a collection of Thruster objects and builds the allocation matrix.
Definition: ThrusterLayout.h:11