Refactor/reference filter dp#687
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #687 +/- ##
==========================================
+ Coverage 31.54% 33.47% +1.92%
==========================================
Files 63 68 +5
Lines 4710 4840 +130
Branches 1180 1245 +65
==========================================
+ Hits 1486 1620 +134
+ Misses 2957 2925 -32
- Partials 267 295 +28
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
| rclcpp_action::GoalResponse ReferenceFilterNode::handle_goal( | ||
| const rclcpp_action::GoalUUID& uuid, | ||
| std::shared_ptr<const vortex_msgs::action::ReferenceFilterWaypoint::Goal> | ||
| goal) { | ||
| (void)uuid; | ||
| (void)goal; | ||
| spdlog::info("Accepted goal request"); | ||
| return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE; | ||
| } |
There was a problem hiding this comment.
Personally I think it looks better to comment out the unused parameters instead of void cast
rclcpp_action::GoalResponse ReferenceFilterNode::handle_goal(
const rclcpp_action::GoalUUID& /*uuid*/,
std::shared_ptr<const vortex_msgs::action::ReferenceFilterWaypoint::Goal> /*goal*/)
{
spdlog::info("Accepted goal request");
return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE;
}Ref https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#f9-unused-parameters-should-be-unnamed
| rclcpp_action::CancelResponse ReferenceFilterNode::handle_cancel( | ||
| const std::shared_ptr<rclcpp_action::ServerGoalHandle< | ||
| vortex_msgs::action::ReferenceFilterWaypoint>> goal_handle) { | ||
| spdlog::info("Received request to cancel goal"); | ||
| (void)goal_handle; | ||
| return rclcpp_action::CancelResponse::ACCEPT; | ||
| } |
There was a problem hiding this comment.
rclcpp_action::CancelResponse ReferenceFilterNode::handle_cancel(
const std::shared_ptr<rclcpp_action::ServerGoalHandle<
vortex_msgs::action::ReferenceFilterWaypoint>> /*goal_handle*/) {
spdlog::info("Received request to cancel goal");
return rclcpp_action::CancelResponse::ACCEPT;
}| Waypoint wp = waypoint_from_ros(goal_handle->get_goal()->waypoint); | ||
|
|
||
| PoseEuler pose; | ||
| Twist twist; | ||
| { | ||
| std::lock_guard<std::mutex> lock(sensor_mutex_); | ||
| pose = current_pose_; | ||
| twist = current_twist_; | ||
| } | ||
| follower_->start(pose, twist, wp, convergence_threshold); |
There was a problem hiding this comment.
Could rewrite to something like
const auto wp = waypoint_from_ros(goal_handle->get_goal()->waypoint);
const auto [pose, twist] = [this] {
std::lock_guard lock(sensor_mutex_);
return std::pair{current_pose_, current_twist_};
}();
follower_->start(pose, twist, wp, convergence_threshold);really just a cosmetic change though
| Eigen::Vector6d current_pose_vector; | ||
| { | ||
| std::lock_guard<std::mutex> lock(sensor_mutex_); | ||
| current_pose_vector = current_pose_.to_vector(); | ||
| } |
There was a problem hiding this comment.
Consider using an IIFE here as well
const auto current_pose_vector = [this] {
std::lock_guard lock(sensor_mutex_);
return current_pose_.to_vector();
}();| inline vortex_msgs::msg::ReferenceFilter fill_reference_msg( | ||
| const Eigen::Vector18d& x) { | ||
| vortex_msgs::msg::ReferenceFilter msg; | ||
| msg.x = x(0); | ||
| msg.y = x(1); | ||
| msg.z = x(2); | ||
| msg.roll = vortex::utils::math::ssa(x(3)); | ||
| msg.pitch = vortex::utils::math::ssa(x(4)); | ||
| msg.yaw = vortex::utils::math::ssa(x(5)); | ||
| msg.x_dot = x(6); | ||
| msg.y_dot = x(7); | ||
| msg.z_dot = x(8); | ||
| msg.roll_dot = x(9); | ||
| msg.pitch_dot = x(10); | ||
| msg.yaw_dot = x(11); | ||
| return msg; | ||
| } |
There was a problem hiding this comment.
Could put a using vortex::utils::math::ssa in here just to reduce words
inline vortex_msgs::msg::ReferenceFilter fill_reference_msg(
const Eigen::Vector18d& x) {
using vortex::utils::math::ssa;
vortex_msgs::msg::ReferenceFilter msg;
msg.x = x(0);
msg.y = x(1);
msg.z = x(2);
msg.roll = ssa(x(3));
msg.pitch = ssa(x(4));
msg.yaw = ssa(x(5));
msg.x_dot = x(6);
msg.y_dot = x(7);
msg.z_dot = x(8);
msg.roll_dot = x(9);
msg.pitch_dot = x(10);
msg.yaw_dot = x(11);
return msg;
}| ea(0) = vortex::utils::math::ssa(measured_pose(3) - reference(3)); | ||
| ea(1) = vortex::utils::math::ssa(measured_pose(4) - reference(4)); | ||
| ea(2) = vortex::utils::math::ssa(measured_pose(5) - reference(5)); |
There was a problem hiding this comment.
Could add a local using vortex::utils::math::ssa here too
| double err = 0.0; | ||
|
|
||
| switch (mode) { | ||
| case WaypointMode::ONLY_POSITION: | ||
| err = ep.norm(); | ||
| break; | ||
|
|
||
| case WaypointMode::ONLY_ORIENTATION: | ||
| err = ea.norm(); | ||
| break; | ||
|
|
||
| case WaypointMode::FORWARD_HEADING: | ||
| err = std::sqrt(ep.squaredNorm() + ea(2) * ea(2)); | ||
| break; | ||
|
|
||
| case WaypointMode::FULL_POSE: | ||
| default: | ||
| err = std::sqrt(ep.squaredNorm() + ea.squaredNorm()); | ||
| break; | ||
| } |
There was a problem hiding this comment.
Would drop the default, so that you get a warning/error if a new mode is added, but not supported here.
Also, instead of the "initialize then assign" pattern, you could wrap the switch in an IIFE to assign err once
const double err = [&] {
switch (mode) {
case WaypointMode::ONLY_POSITION:
return ep.norm();
case WaypointMode::ONLY_ORIENTATION:
return ea.norm();
case WaypointMode::FORWARD_HEADING:
return std::sqrt(ep.squaredNorm() + ea(2) * ea(2));
case WaypointMode::FULL_POSE:
return std::sqrt(ep.squaredNorm() + ea.squaredNorm());
}
}();| std::bind(&ReferenceFilterNode::handle_goal, this, | ||
| std::placeholders::_1, std::placeholders::_2), | ||
| std::bind(&ReferenceFilterNode::handle_cancel, this, | ||
| std::placeholders::_1), | ||
| std::bind(&ReferenceFilterNode::handle_accepted, this, | ||
| std::placeholders::_1), |
There was a problem hiding this comment.
Prefer lambdas over bind 😀
There was a problem hiding this comment.
For example like this
action_server_ = rclcpp_action::create_server
vortex_msgs::action::ReferenceFilterWaypoint>(
this, action_server_name,
[this](const auto& uuid, auto goal) {
return handle_goal(uuid, std::move(goal));
},
[this](auto& goal_handle) {
return handle_cancel(std::move(goal_handle));
},
[this](auto& goal_handle) {
handle_accepted(std::move(goal_handle));
},
rcl_action_server_get_default_options());|
🎉 This PR is included in version 2.7.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
lib/) and a ROS integration layer (ros/)execute_mutex_, ensuring only one thread accesses the follower at a time