Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the LFController unit tests #46

Merged
Merged
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
3ae60ce
[lf_controller] Add dummy initial unittest for the LF Controller
ArthurVal Dec 11, 2024
3411e2b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 11, 2024
9bb4851
[lf_controller] Add Ctor test
ArthurVal Dec 16, 2024
2dd175c
[lf_controller] Add Init with empty model test
ArthurVal Dec 16, 2024
71c4dcb
[lf_controller] Add Init with nullptr test
ArthurVal Dec 16, 2024
a5fb97e
[lf_controller] Comment out EXAMPLE_ROBOT_DATA_MODEL_DIR
ArthurVal Dec 16, 2024
8e57ee4
[lf_controller] Define test fixture (empty for now)
ArthurVal Dec 18, 2024
3090752
[lf_controller] Add unit test for .initialize() with valid model
ArthurVal Dec 19, 2024
0e4a8e8
[lf_controller] Rename utils/file to file_operation
ArthurVal Dec 19, 2024
af2cc97
[lf_controller] Add FileToString from filesystem::path directly
ArthurVal Dec 19, 2024
fff3c54
[lf_controller] Refactor out talos'reduced file path into a function
ArthurVal Dec 19, 2024
c0a4331
[lf_controller] Add ComputeControlNotInitialized unit test
ArthurVal Dec 19, 2024
8be4dbe
[lf_controller] Add ComputeControlNoInput test
ArthurVal Dec 19, 2024
b8b0af5
[lf_controller] Fix missing EXAMPLE_ROBOT..._DIR definition
ArthurVal Dec 20, 2024
0a16c43
[lf_controller] Minor format updates
ArthurVal Jan 7, 2025
2010a10
[lf_controller] Use fixture with static talos urdf string
ArthurVal Jan 7, 2025
cb13cdc
[lf_controller] Add som template TBD for compute control tests
ArthurVal Jan 7, 2025
ba9e6d4
[lf_controller] Update inline doc of FileOpen
ArthurVal Jan 8, 2025
590e839
[lf_controller] Move using ::Eigen stuff on top of src file
ArthurVal Jan 8, 2025
9d49491
[lf_controller] Rename ComputeControlValid to ComputeControl
ArthurVal Jan 8, 2025
9e9b9a7
[lf_controller] Rename IsJointType* function to Is*
ArthurVal Jan 9, 2025
4d6ef41
[lf_controller] Add the MakeValidRandom* functions (still WIP)
ArthurVal Jan 10, 2025
9cb7ec0
[lf_controller] Default VectorPrintFormat inside struct directly
ArthurVal Jan 10, 2025
463ec79
[lf_controller] Use simplified URDF + Add eigen_conv helper
ArthurVal Jan 10, 2025
9fadb46
[lf_controller] Update the UnknownJoints test
ArthurVal Jan 10, 2025
fa4fa02
[lf_controller] Add Grow() to eigen utils
ArthurVal Jan 13, 2025
aef647a
[lf_controller] Add PushNewJointState function to utils
ArthurVal Jan 13, 2025
332796b
[lf_controller] Implement a SizeMismatch test (on sensor)
ArthurVal Jan 13, 2025
e707f4e
[lf_controller] Add missing MakeRandomControlForJoints inline doc
ArthurVal Jan 13, 2025
47bc072
[lf_controller] Remove pedantic ';'
ArthurVal Jan 13, 2025
4d3478b
[lf_controller] Add a UnaryOp getter to Make* functions
ArthurVal Jan 14, 2025
4f33f62
[tests] Add Grow for Eigen Matrices (NUmDimensions = 2)
ArthurVal Jan 15, 2025
0ddd46c
[lf_controller] Refactor the tests with parameters
ArthurVal Jan 15, 2025
d9e43b6
[lf_controller] Remove ternary operator
ArthurVal Jan 15, 2025
d24269c
[tests] Update Mutation with nodiscard and friend PrintTo
ArthurVal Jan 15, 2025
d323484
[lf_controller] Add ComputeControlSpecialDouble test
ArthurVal Jan 15, 2025
28d0bbd
[lf_controller] Remove SCOPE_TRACE from SpecialDouble tests
ArthurVal Jan 15, 2025
fde8554
[tests] Remove utils/array & utils/file_operation (not used)
ArthurVal Jan 15, 2025
c37c6b1
[lf_controller] Fix the size issues with free flyer tests
ArthurVal Jan 15, 2025
99b399c
[lf_controller] Disable the SpecialDouble test
ArthurVal Jan 15, 2025
e0c4838
[lf_controller] Remove un-used headers
ArthurVal Jan 15, 2025
eac4e70
[lf_controller] Clean up the expected_control (still WIP)
ArthurVal Jan 15, 2025
0e8622c
[tests] Update print_to with meta functions + fix TryToPrintTo API
ArthurVal Jan 16, 2025
1f33867
[lf_controller] Refactor to use ModelDescription as Test params
ArthurVal Jan 17, 2025
3b323f2
[lf_controller] Update the Valid ComputeControl test
ArthurVal Jan 20, 2025
758fba3
[test utils] Change the Eigen Vector PrintTo default strip
ArthurVal Jan 20, 2025
ddcf5b0
[lf_controller] Move Make* LFController function into utils/
ArthurVal Jan 20, 2025
1a998db
[lf_controller] Update to cleaner Push* implementation
ArthurVal Jan 20, 2025
d625e6a
[lf_controller] Fix wrong_control feedforward vs feedback_gains
ArthurVal Jan 20, 2025
e3d6482
[lf_controller] MakeRobotModelBuilderFrom use 'const ref'
ArthurVal Jan 20, 2025
1de6d9e
[utils] Fix std::is_base_of<> usage
ArthurVal Jan 20, 2025
8f2c6ef
[lf_controller] Remove View and ModelDescr template stuff
ArthurVal Jan 21, 2025
bf2e2b5
[utils] Fix internale doc/comment of ConcatenateAs
ArthurVal Jan 21, 2025
ea21689
[utils] Fix wrong MakeAllModelDescription documentation
ArthurVal Jan 21, 2025
efb8c80
[lf_controller] Add JointState size mismatch test for control x_0
ArthurVal Jan 22, 2025
b5a5149
[lf_controller] Remove unused commented index prints
ArthurVal Jan 22, 2025
3c677f1
[utils] Refactor out the init statement of the if(...) for RMB
ArthurVal Jan 30, 2025
fc9e52b
[utils] Replace #pragma once with header guards
ArthurVal Jan 30, 2025
554d46d
[utils] Remove the ConcatenateAs function
ArthurVal Jan 30, 2025
2b3def1
[lf_controller] Refactor expected computation into utils/
ArthurVal Jan 27, 2025
2049ffe
[lf_controller] Fix the error computation (using pinocchio)
ArthurVal Jan 30, 2025
7b939b7
[lf_controller] Fix wrong inline doc
ArthurVal Jan 31, 2025
7200daa
[lf_controller] Fix missing doc for ExpectedLFControllerFrom
ArthurVal Jan 31, 2025
80dac66
[lf_controller] Refactor ExpectedLFControllerFrom args order
ArthurVal Jan 31, 2025
ad767dc
[lf_controller] Remove irrelevant TODO comment
ArthurVal Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[lf_controller] Update the Valid ComputeControl test
  • Loading branch information
ArthurVal committed Jan 31, 2025
commit 3b323f23e51c9111e02f7a34678af30f288b3115
22 changes: 13 additions & 9 deletions tests/test_lf_controller.cpp
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ using tests::utils::ModelDescription;
using linear_feedback_controller_msgs::Eigen::Control;
using linear_feedback_controller_msgs::Eigen::JointState;
using linear_feedback_controller_msgs::Eigen::Sensor;
using tests::utils::GetCompleteStateFrom;
using tests::utils::PushNewJointStateTo;

#include "linear_feedback_controller/lf_controller.hpp"
@@ -94,7 +95,7 @@ auto MakeValidRandomControlFor(const RobotModelBuilder& model) -> Control {
control.feedforward = Eigen::VectorXd::Random(model.get_nv());
control.feedback_gain = Eigen::MatrixXd::Random(
/* rows = */ model.get_nv(),
/* cols = */ model.get_nv() * 2);
/* cols = */ model.get_nv() + model.get_nq());

control.initial_state = MakeValidRandomSensorFor(model);

@@ -256,13 +257,16 @@ TEST_P(LFControllerTest, ComputeControl) {
const auto sensor = MakeValidRandomSensorFor(*model_ptr);
const auto control = MakeValidRandomControlFor(*model_ptr);

// FIXME: Replace Random with the expected stuff...
const auto error = Eigen::VectorXd::Random(control.feedback_gain.cols());
const auto x =
GetCompleteStateFrom(sensor, model_ptr->get_robot_has_free_flyer());

const Eigen::VectorXd expected_control =
control.feedforward + (control.feedback_gain * error);
const auto x_0 = GetCompleteStateFrom(control.initial_state,
model_ptr->get_robot_has_free_flyer());

EXPECT_EQ(expected_control, ctrl.compute_control(sensor, control));
// FIXME: Compute the error differently based on free flyer ?
const auto error = x_0 - x;
EXPECT_EQ((control.feedforward + (control.feedback_gain * error)),
ctrl.compute_control(sensor, control));
}

constexpr auto dummy_urdf =
@@ -298,9 +302,9 @@ INSTANTIATE_TEST_SUITE_P(
JointListType{
{.name = "l01", .type = JointType::Controlled},
},
JointListType{
{.name = "l01", .type = JointType::Moving},
},
// JointListType{
// {.name = "l01", .type = JointType::Moving},
// },
JointListType{
{.name = "l01"},
{.name = "l12"},
45 changes: 43 additions & 2 deletions tests/utils/eigen.hpp
Original file line number Diff line number Diff line change
@@ -68,8 +68,49 @@ constexpr auto Grow(Eigen::PlainObjectBase<MatrixType> &matrix,
matrix.cols() + col_inc.value_or(row_inc));
}

/// Inside a vector, represents a strip using the expected number of head/tail
/// elements needed
/**
* @brief Creates an OutVector from the concatenation of all given \a vectors
*
* @note SFINAE: Only available for Vectors (NumDimension equals to 1)
*
* @tparam OutVector The output vector type returned
* @tparam ...VectorTypes All input vectors
*
* @param[in] ...vectors All vectors we wish to concatenates
*
* @return OutVector With coefs set as the concatenation of all input vectors
*/
template <typename OutVector, typename... VectorTypes>
constexpr auto ConcatenateAs(const Eigen::DenseBase<VectorTypes> &...vectors)
-> std::enable_if_t<details::IsEigenVector_v<OutVector> and
(details::IsEigenVector_v<VectorTypes> and ...),
OutVector> {
// NOTE: Couldn't find a way to use the fold expression with the Eigen
// stream + comma operators initialization shenanigans...
// 'out << (vectors, ...);' doesn't work ??
// Therefore we use the segment(i, n) with i begin updated through the comma
// operator, which should be the same as 'out << A, B, C, ...;'

OutVector out((0 + ... + vectors.size()));
std::size_t i = 0;

// NOTE: the void(...) here is just because of comma operator of Eigen...
((void(out.segment(i, vectors.size()) = vectors), i += vectors.size()), ...);

// This evaluates to:
// out.segment(i, vectors[0].size());
// i += vectors[0].size();
// out.segment(i, vectors[1].size());
// i += vectors[1].size();
// ...
// out.segment(i, vectors[N].size());
// i += vectors[N].size();

return out;
}

/// Inside a vector, represents a strip using the expected number of
/// head/tail elements needed
struct Strip {
std::size_t head; /*!< Number of elements at the head of the vector */
std::size_t tail; /*!< Number of elements at the tail of the vector */
21 changes: 21 additions & 0 deletions tests/utils/eigen_conversions.hpp
Original file line number Diff line number Diff line change
@@ -132,4 +132,25 @@ inline auto PushNewJointStateTo(
joint_state.effort.tail<1>()[0] = new_joint_state.effort;
}

/**
* @brief Reconstruct the expected state X (= [q, v]) from the given sensor
*
* @param[in] sensor The complete sensor data
* @param[in] with_free_flyer Indicates if we have a free flyer or not
*
* @return Eigen::VectorXd Containing the complete state X
*/
inline auto GetCompleteStateFrom(
const linear_feedback_controller_msgs::Eigen::Sensor& sensor,
bool with_free_flyer) -> Eigen::VectorXd {
if (with_free_flyer) {
return ConcatenateAs<Eigen::VectorXd>(
sensor.base_pose, sensor.joint_state.position, sensor.base_twist,
sensor.joint_state.velocity);
} else {
return ConcatenateAs<Eigen::VectorXd>(sensor.joint_state.position,
sensor.joint_state.velocity);
}
}

} // namespace tests::utils