-
Notifications
You must be signed in to change notification settings - Fork 0
Rename vortex util types #22
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22 +/- ##
==========================================
- Coverage 98.11% 98.06% -0.06%
==========================================
Files 5 5
Lines 425 413 -12
Branches 97 84 -13
==========================================
- Hits 417 405 -12
Misses 4 4
Partials 4 4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Andeshog
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still really dont see the need to do this so complicated. We have two types, ROS has a couple, and all of them are pre-known. Why not just use std::variant for example? (eta is used for example only, I support the twist and pose renaming)
Something along these lines
#include <variant>
template <class ... Ts>
struct VisitorOverloader : Ts... { using Ts::operator()...; };
Eigen::Vector<double, 3> get_eta_position(const std::variant<Eta, EtaQuat>& eta_variant) {
return std::visit(
VisitorOverloader{
[](const Eta& eta) {
return Eigen::Vector3d{eta.x, eta.y, eta.z};
},
[](const EtaQuat& eta_quat) {
return Eigen::Vector3d{eta_quat.x, eta_quat.y, eta_quat.z};
}
},
eta_variant
);
}This does what you want, but without the heavy templating, and also means you dont have to define accessors for public members.
If it wasnt clear, this is just used like // gets eta position
const auto eta = Eta{};
const Eigen::Vector<double, 3> eta_pos = get_eta_position(eta);
// get eta_quat position
const auto eta_quat = EtaQuat{};
const Eigen::Vector<double, 3> eta_quat_pos = get_eta_position(eta_quat); |
|
With the current setup there is no need to define the accessors for public members. Also with the current setup the ros conversion function also works for types like vortex_msgs::msg::ReferenceFilter and such. |
|
If you are referring to the functions in "views.hpp" then I agree they are not strictly needed, so they can be removed, but I would like to keep the current setup for the ros conversion functions |
|
My two cents were requested:
|
|
The accessors could make sense if we had many templated functions and wanted to support "Eigen like" pose types in the future. As it stands now we probably wouldn't have ended up with that many templated functions anyways, so I agree that they might be overkill with the current functions. |
| template <ROSPoseLike T> | ||
| inline Eigen::Matrix<double, 6, Eigen::Dynamic> ros_to_eigen6d(const T& msg) { | ||
| std::vector<vortex::utils::types::Pose> ros_to_pose_vec(const T& msg) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to me this function is only really meant for PoseArray? Could that be used directly instead of templating here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll have to wait and see😉
| /** | ||
| * @brief Struct to represent the state vector nu according to eq. 2.5 in | ||
| * Fossen, 2021, containing the linear and angular velocities. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cant mark the other docs since they are not changed, but the mention of eta and nu could probably go as well? I think it is sufficient to ref the eq.
/**
* @brief Struct to represent the velocity vector according to eq. 2.5 in
* Fossen, 2021, containing the linear and angular velocities.
*/
/**
* @brief Struct to represent the pose vector according to eq. 2.3 in
* Fossen, 2021, containing the position and orientation as quaternion.
*/
Andeshog
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approval with suggestions
Renamed types:
Eta -> PoseEuler
EtaQuat -> Pose
Nu -> Twist
Added generic conversion function when converting to ros types from arbitrary "poselike" types . The types just need to expose accessor functions to their "pose fields" to satisy the requirements for the function.
POD structs that already expose the fields directly as members already satisfy the concepts in "member_concepts.hpp" and expose accessors functions automatically in "accessors.hpp".
This setup gives types like vortex_msgs::msg::ReferenceFilter access to the conversion function, and to add support for more complex Eigen-like types in the future you just need to define its accessor functions.
This concept setup abstracts the accessor function logic away from the simple POD, while still being able to support more complex types in the future, that also don't have to be defined in vortex utils.