Skip to content

580 task thrust allocator auv#661

Open
Q3rkses wants to merge 18 commits intomainfrom
580-task-Thrust-Allocator-AUV
Open

580 task thrust allocator auv#661
Q3rkses wants to merge 18 commits intomainfrom
580-task-Thrust-Allocator-AUV

Conversation

@Q3rkses
Copy link
Contributor

@Q3rkses Q3rkses commented Feb 1, 2026

Refactored the thrust allocator module to be easier to build upon. Added more documentation in the readme file and some basic unit testing of the thrust allocator functionality. Added a new solver using CasADi and Fossen's formulation of the QP thrust allocation problem. Whenever i find time again i will add more comprehensible unit testing.

Lastly it would be nice to have simulator testing and perform some analysis on computation time vs accuracy tradeoff for both pseudoinverse and the QP solver but that is outside of the scope of this PR.

@Q3rkses Q3rkses linked an issue Feb 1, 2026 that may be closed by this pull request
3 tasks
@Q3rkses Q3rkses requested a review from jorgenfj February 1, 2026 23:03
@Q3rkses Q3rkses force-pushed the 580-task-Thrust-Allocator-AUV branch from f792d80 to a531809 Compare February 2, 2026 13:06
@Q3rkses Q3rkses requested a review from kluge7 February 2, 2026 13:06
@Q3rkses Q3rkses self-assigned this Feb 2, 2026
@Q3rkses Q3rkses added the AUV label Feb 2, 2026
Q3rkses and others added 3 commits February 2, 2026 14:20
…ubious and not testing the expected functionality. These are mostly tests for moments as sometimes the desired wrench and actual wrench will not physically be able to match given the constraints.
Comment on lines +12 to +16
/**
* @brief The Allocator class structure that the solvers will inherit and
* override.
*/
class Allocator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider naming it IAllocator or similar to make it clear it is an interface class

Comment on lines +18 to +30
class Factory {
public:
/**
* @brief A function that makes an allocator based on a string
* defining the desired type.
*
* @param allocator_type String of the desired allocator type.
* @return unique pointer to the created allocator.
*/
static std::unique_ptr<Allocator> make_allocator(
const std::string& allocator_type,
const AllocatorConfig& config);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a class? Why not a free function inside a namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question, i was inspired by the concept of factories and decided to use it here. Its something along the lines that thrust_allocator does not create itself. The factory is sent an order for a QP allocator and makes a qp allocator not a pseudoinverse allocator type of thing

Comment on lines +36 to +37
Eigen::MatrixXd calculate_pseudoinverse(const Eigen::MatrixXd &T,
const Eigen::MatrixXd &W);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, if a class method doesnt have any dependencies to the class it would be better off as a free function. guideline

Comment on lines 12 to 14
void QPAllocator::formulate_as_qp(const AllocatorConfig &cfg) {
const int r = cfg.input_weight_matrix.rows(); // number of thrusters = 8
const int n = cfg.slack_weight_matrix.rows(); // degrees of freedom = 6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the comments stating the values? Surely either a) the comments are wrong and they can be other values, or b) the comments are right and they are better off as constexpr values? 😄 In either case the comments are goners

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was mostly to remind myself what the actual value was :D

Comment on lines 21 to 24
// create and set the square term matrix.
Eigen::MatrixXd phi = Eigen::MatrixXd::Zero(r + n, r + n);
phi.block(0, 0, r, r) = cfg.input_weight_matrix;
phi.block(r, r, n, n) = cfg.slack_weight_matrix;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just be aware that potential readers may not have access to the book, so names like r and n, and greek letters may not be very descriptive 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r and n are commented above as number of thrusters and degrees of freedom. Fossens book is at the office

Comment on lines 131 to 134
if (!casadi_solver_initialized_) {
throw std::runtime_error("CasADi QP solver not initialized "
"(formulate_as_qp_CasADi not called).");
}
Copy link
Contributor

@Andeshog Andeshog Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps using std::optional would be safer and easier to handle than throwing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look up the difference and look into this

the qp allocator and refactored some code because the node dies
everytime i try to launch it and use it in the simulator
@codecov
Copy link

codecov bot commented Feb 5, 2026

Codecov Report

❌ Patch coverage is 54.01460% with 252 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.16%. Comparing base (8bd1fb4) to head (da7c14d).

Files with missing lines Patch % Lines
...ust_allocator_auv/tests/thrust_allocator_tests.cpp 54.63% 3 Missing and 134 partials ⚠️
.../thrust_allocator_auv/src/thrust_allocator_ros.cpp 0.00% 98 Missing ⚠️
...lude/thrust_allocator_auv/thrust_allocator_ros.hpp 0.00% 5 Missing ⚠️
...tion/thrust_allocator_auv/solvers/qp_allocator.cpp 95.23% 2 Missing and 3 partials ⚠️
...thrust_allocator_auv/solvers/allocator_factory.cpp 62.50% 3 Missing ⚠️
..._allocator_auv/solvers/pseudoinverse_allocator.cpp 83.33% 1 Missing and 1 partial ⚠️
...e/thrust_allocator_auv/pseudoinverse_allocator.hpp 0.00% 1 Missing ⚠️
..._auv/include/thrust_allocator_auv/qp_allocator.hpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #661      +/-   ##
==========================================
+ Coverage   33.79%   38.16%   +4.36%     
==========================================
  Files          44       49       +5     
  Lines        3003     3438     +435     
  Branches      780     1148     +368     
==========================================
+ Hits         1015     1312     +297     
+ Misses       1805     1802       -3     
- Partials      183      324     +141     
Flag Coverage Δ
unittests 38.16% <54.01%> (+4.36%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...de/thrust_allocator_auv/thrust_allocator_utils.hpp 86.66% <100.00%> (+86.66%) ⬆️
...e/thrust_allocator_auv/pseudoinverse_allocator.hpp 0.00% <0.00%> (ø)
..._auv/include/thrust_allocator_auv/qp_allocator.hpp 0.00% <0.00%> (ø)
..._allocator_auv/solvers/pseudoinverse_allocator.cpp 83.33% <83.33%> (ø)
...thrust_allocator_auv/solvers/allocator_factory.cpp 62.50% <62.50%> (ø)
...lude/thrust_allocator_auv/thrust_allocator_ros.hpp 0.00% <0.00%> (ø)
...tion/thrust_allocator_auv/solvers/qp_allocator.cpp 95.23% <95.23%> (ø)
.../thrust_allocator_auv/src/thrust_allocator_ros.cpp 0.96% <0.00%> (+0.96%) ⬆️
...ust_allocator_auv/tests/thrust_allocator_tests.cpp 54.63% <54.63%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task & Research] Thrust allocation / interface for new drone

3 participants