Skip to content

Commit 666dc35

Browse files
committed
clang tidy fixes
1 parent c315d92 commit 666dc35

File tree

6 files changed

+41
-33
lines changed

6 files changed

+41
-33
lines changed

ik_solvers/include/ik_solvers/task_priority_solver.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ class Constraint
4343
{
4444
public:
4545
/// Create a new constraint given the current primal value, constraint value, task priority and feedback gain.
46-
Constraint(const Eigen::MatrixXd & primal, const Eigen::MatrixXd & constraint, int priority, double gain)
47-
: primal_(primal),
48-
constraint_(constraint),
46+
Constraint(Eigen::MatrixXd primal, Eigen::MatrixXd constraint, int priority, double gain)
47+
: primal_(std::move(primal)),
48+
constraint_(std::move(constraint)),
4949
priority_(priority),
50-
gain_(gain) {};
50+
gain_(gain){};
5151

5252
/// Destructor.
5353
virtual ~Constraint() = default;
@@ -167,7 +167,7 @@ class JointConstraint : public SetConstraint
167167
/// If the priorities are equal, the constraints are sorted based on their memory address.
168168
struct ConstraintCompare
169169
{
170-
bool operator()(const std::shared_ptr<Constraint> & lhs, const std::shared_ptr<Constraint> & rhs) const
170+
auto operator()(const std::shared_ptr<Constraint> & lhs, const std::shared_ptr<Constraint> & rhs) const -> bool
171171
{
172172
return lhs->priority() == rhs->priority() ? std::less<>{}(lhs, rhs) : lhs->priority() < rhs->priority();
173173
}
@@ -211,7 +211,7 @@ class TaskPriorityIKSolver : public IKSolver
211211
public:
212212
TaskPriorityIKSolver() = default;
213213

214-
virtual auto initialize(
214+
auto initialize(
215215
const std::shared_ptr<rclcpp_lifecycle::LifecycleNode> & node,
216216
const std::shared_ptr<pinocchio::Model> & model,
217217
const std::shared_ptr<pinocchio::Data> & data,

ik_solvers/src/task_priority_solver.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ auto tpik(const hierarchy::ConstraintSet & tasks, size_t nv, double damping)
214214
Eigen::MatrixXd nullspace = Eigen::MatrixXd::Identity(nv, nv);
215215

216216
for (const auto & task : tasks) {
217-
const Eigen::MatrixXd J_inv = pinv::damped_least_squares(task->jacobian(), damping);
218-
vel += nullspace * J_inv * (task->gain() * task->error());
217+
const Eigen::MatrixXd jacobian_inv = pinv::damped_least_squares(task->jacobian(), damping);
218+
vel += nullspace * jacobian_inv * (task->gain() * task->error());
219219

220220
jacobians.push_back(task->jacobian());
221221
nullspace = compute_nullspace(construct_augmented_jacobian(jacobians));
@@ -227,15 +227,13 @@ auto tpik(const hierarchy::ConstraintSet & tasks, size_t nv, double damping)
227227
/// Check if the solution is feasible.
228228
auto is_feasible(const hierarchy::ConstraintSet & constraints, const Eigen::VectorXd & solution) -> bool
229229
{
230-
for (const auto & constraint : constraints) {
230+
return std::ranges::all_of(constraints, [&solution](const auto & constraint) {
231231
auto set_task = std::dynamic_pointer_cast<hierarchy::SetConstraint>(constraint);
232232
const double pred = (constraint->jacobian() * solution).value();
233-
if (!((set_task->primal() > set_task->lower_threshold() && pred < 0) ||
234-
(set_task->primal() < set_task->upper_threshold() && pred > 0))) {
235-
return false;
236-
}
237-
}
238-
return true;
233+
return (
234+
(set_task->primal() > set_task->lower_threshold() && pred < 0) ||
235+
(set_task->primal() < set_task->upper_threshold() && pred > 0));
236+
});
239237
}
240238

241239
/// Search for the feasible solutions to the task hierarchy and return the one with the smallest norm.
@@ -316,7 +314,7 @@ auto TaskPriorityIKSolver::configure_parameters() -> void
316314
}
317315

318316
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
319-
auto TaskPriorityIKSolver::solve_ik(const Eigen::Affine3d & target_pose, const Eigen::VectorXd & q)
317+
auto TaskPriorityIKSolver::solve_ik(const Eigen::Affine3d & goal, const Eigen::VectorXd & q)
320318
-> std::expected<Eigen::VectorXd, SolverError>
321319
{
322320
configure_parameters();
@@ -328,7 +326,7 @@ auto TaskPriorityIKSolver::solve_ik(const Eigen::Affine3d & target_pose, const E
328326

329327
// insert the pose constraint
330328
const double gain = params_.end_effector_pose_task.gain;
331-
hierarchy_.insert(std::make_shared<hierarchy::PoseConstraint>(model_, data_, ee_pose, target_pose, ee_frame_, gain));
329+
hierarchy_.insert(std::make_shared<hierarchy::PoseConstraint>(model_, data_, ee_pose, goal, ee_frame_, gain));
332330

333331
for (const auto & joint_name : params_.constrained_joints) {
334332
// get the joint index in the configuration vector

topic_sensors/src/odom_sensor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ auto OdomSensor::on_configure(const rclcpp_lifecycle::State & /*previous_state*/
5757
}
5858

5959
state_sub_ = node_->create_subscription<nav_msgs::msg::Odometry>(
60-
topic, rclcpp::SensorDataQoS(), [this, &transform_message](const std::shared_ptr<nav_msgs::msg::Odometry> msg) {
60+
topic,
61+
rclcpp::SensorDataQoS(),
62+
[this, &transform_message](const std::shared_ptr<nav_msgs::msg::Odometry> msg) { // NOLINT
6163
if (transform_message) {
6264
m2m::transform_message(*msg, "map_ned", "base_link_fsd");
6365
}

velocity_controllers/src/adaptive_integral_terminal_sliding_mode_controller.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,19 @@ auto AdaptiveIntegralTerminalSlidingModeController::on_configure(const rclcpp_li
117117

118118
// NOLINTNEXTLINE(performance-unnecessary-value-param)
119119
reference_sub_ = get_node()->create_subscription<geometry_msgs::msg::Twist>(
120-
"~/reference", rclcpp::SystemDefaultsQoS(), [this](const std::shared_ptr<geometry_msgs::msg::Twist> msg) {
120+
"~/reference",
121+
rclcpp::SystemDefaultsQoS(),
122+
[this](const std::shared_ptr<geometry_msgs::msg::Twist> msg) { // NOLINT
121123
reference_.writeFromNonRT(*msg);
122124
});
123125

124126
// use the tf interface when we aren't getting the state from a topic
125127
if (params_.use_external_measured_states) {
126128
RCLCPP_INFO(logger_, "Using external measured states"); // NOLINT
127129
system_state_sub_ = get_node()->create_subscription<nav_msgs::msg::Odometry>(
128-
"~/system_state", rclcpp::SystemDefaultsQoS(), [this](const std::shared_ptr<nav_msgs::msg::Odometry> msg) {
130+
"~/system_state",
131+
rclcpp::SystemDefaultsQoS(),
132+
[this](const std::shared_ptr<nav_msgs::msg::Odometry> msg) { // NOLINT
129133
system_state_.writeFromNonRT(*msg);
130134
});
131135
} else {

velocity_controllers/src/integral_sliding_mode_controller.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,19 @@ auto IntegralSlidingModeController::on_configure(const rclcpp_lifecycle::State &
109109
RCLCPP_INFO(logger_, "Commands won't be sent until both reference and state messages are received."); // NOLINT
110110

111111
reference_sub_ = get_node()->create_subscription<geometry_msgs::msg::Twist>(
112-
"~/reference", rclcpp::SystemDefaultsQoS(), [this](const std::shared_ptr<geometry_msgs::msg::Twist> msg) {
112+
"~/reference",
113+
rclcpp::SystemDefaultsQoS(),
114+
[this](const std::shared_ptr<geometry_msgs::msg::Twist> msg) { // NOLINT
113115
reference_.writeFromNonRT(*msg);
114116
});
115117

116118
// use the tf interface when we aren't getting the state from a topic
117119
if (params_.use_external_measured_states) {
118120
RCLCPP_INFO(logger_, "Using external measured states"); // NOLINT
119121
system_state_sub_ = get_node()->create_subscription<nav_msgs::msg::Odometry>(
120-
"~/system_state", rclcpp::SystemDefaultsQoS(), [this](const std::shared_ptr<nav_msgs::msg::Odometry> msg) {
122+
"~/system_state",
123+
rclcpp::SystemDefaultsQoS(),
124+
[this](const std::shared_ptr<nav_msgs::msg::Odometry> msg) { // NOLINT
121125
system_state_.writeFromNonRT(*msg);
122126
});
123127
} else {

whole_body_controllers/src/ik_controller.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ auto to_eigen(const std::vector<double> & vec) -> Eigen::Affine3d
4242
if (vec.size() != 7) {
4343
throw std::invalid_argument("Invalid size for pose vector");
4444
}
45-
Eigen::Translation3d translation = {vec[0], vec[1], vec[2]};
45+
const Eigen::Translation3d translation = {vec[0], vec[1], vec[2]};
4646
Eigen::Quaterniond rotation = {vec[6], vec[3], vec[4], vec[5]};
4747
rotation.normalize();
48-
return Eigen::Affine3d(translation * rotation);
48+
return {translation * rotation};
4949
}
5050

5151
} // namespace
@@ -161,15 +161,17 @@ auto IKController::on_configure(const rclcpp_lifecycle::State & /*previous_state
161161
velocity_state_values_.resize(velocity_interface_names_.size(), std::numeric_limits<double>::quiet_NaN());
162162

163163
reference_sub_ = get_node()->create_subscription<geometry_msgs::msg::Pose>(
164-
"~/reference", rclcpp::SystemDefaultsQoS(), [this](const std::shared_ptr<geometry_msgs::msg::Pose> msg) {
164+
"~/reference", rclcpp::SystemDefaultsQoS(), [this](const std::shared_ptr<geometry_msgs::msg::Pose> msg) { // NOLINT
165165
m2m::transform_message(*msg);
166166
reference_.writeFromNonRT(*msg);
167167
});
168168

169169
if (params_.use_external_measured_vehicle_states) {
170170
RCLCPP_INFO(logger_, "Using external measured vehicle states"); // NOLINT
171171
vehicle_state_sub_ = get_node()->create_subscription<nav_msgs::msg::Odometry>(
172-
"~/vehicle_state", rclcpp::SystemDefaultsQoS(), [this](const std::shared_ptr<nav_msgs::msg::Odometry> msg) {
172+
"~/vehicle_state",
173+
rclcpp::SystemDefaultsQoS(),
174+
[this](const std::shared_ptr<nav_msgs::msg::Odometry> msg) { // NOLINT
173175
m2m::transform_message(*msg, "map", "base_link");
174176
vehicle_state_.writeFromNonRT(*msg);
175177
});
@@ -221,9 +223,8 @@ auto IKController::command_interface_configuration() const -> controller_interfa
221223
position_interface_names_, std::back_inserter(config.names), [this, &format_interface](const auto & name) {
222224
if (std::ranges::find(free_flyer_pos_dofs_, name) != free_flyer_pos_dofs_.end()) {
223225
return format_interface(name, hardware_interface::HW_IF_POSITION, params_.vehicle_reference_controller);
224-
} else {
225-
return format_interface(name, hardware_interface::HW_IF_POSITION, params_.manipulator_reference_controller);
226226
}
227+
return format_interface(name, hardware_interface::HW_IF_POSITION, params_.manipulator_reference_controller);
227228
});
228229
}
229230

@@ -232,9 +233,8 @@ auto IKController::command_interface_configuration() const -> controller_interfa
232233
velocity_interface_names_, std::back_inserter(config.names), [this, &format_interface](const auto & name) {
233234
if (std::ranges::find(free_flyer_vel_dofs_, name) != free_flyer_vel_dofs_.end()) {
234235
return format_interface(name, hardware_interface::HW_IF_VELOCITY, params_.vehicle_reference_controller);
235-
} else {
236-
return format_interface(name, hardware_interface::HW_IF_VELOCITY, params_.manipulator_reference_controller);
237236
}
237+
return format_interface(name, hardware_interface::HW_IF_VELOCITY, params_.manipulator_reference_controller);
238238
});
239239
}
240240

@@ -327,7 +327,7 @@ auto IKController::update_system_state_values() -> controller_interface::return_
327327
const auto position_interfaces = std::span(state_interfaces_.begin(), position_interfaces_end);
328328
const auto velocity_interfaces = std::span(velocity_interfaces_start, velocity_interfaces_end);
329329

330-
std::vector<double> position_states, velocity_states;
330+
std::vector<double> position_states, velocity_states; // NOLINT(readability-isolate-declaration)
331331
position_states.reserve(position_interfaces.size());
332332
velocity_states.reserve(velocity_interfaces.size());
333333

@@ -411,11 +411,11 @@ auto IKController::update_and_write_commands(const rclcpp::Time & /*time*/, cons
411411
configure_parameters();
412412

413413
const Eigen::VectorXd q = Eigen::VectorXd::Map(position_state_values_.data(), position_state_values_.size());
414-
const Eigen::Affine3d target_pose = to_eigen(reference_interfaces_);
414+
const Eigen::Affine3d goal = to_eigen(reference_interfaces_);
415415

416416
// TODO(anyone): add solver support for velocity states
417417
// right now we only use the positions for the solver
418-
const auto result = solver_->solve(period, target_pose, q);
418+
const auto result = solver_->solve(period, goal, q);
419419

420420
if (!result.has_value()) {
421421
const auto err = result.error();

0 commit comments

Comments
 (0)