Skip to content

Commit

Permalink
clang-tidy fixes for trajopt
Browse files Browse the repository at this point in the history
  • Loading branch information
rjoomen committed Jul 12, 2024
1 parent 53a3de9 commit b2bbade
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 41 deletions.
21 changes: 11 additions & 10 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ BreakBeforeBraces: Custom

# Control of individual brace wrapping cases
BraceWrapping: {
AfterClass: 'true'
AfterControlStatement: 'true'
AfterEnum : 'true'
AfterFunction : 'true'
AfterNamespace : 'true'
AfterStruct : 'true'
AfterUnion : 'true'
BeforeCatch : 'true'
BeforeElse : 'true'
IndentBraces : 'false'
AfterCaseLabel: 'true',
AfterClass: 'true',
AfterControlStatement: 'true',
AfterEnum : 'true',
AfterFunction : 'true',
AfterNamespace : 'true',
AfterStruct : 'true',
AfterUnion : 'true',
BeforeCatch : 'true',
BeforeElse : 'true',
IndentBraces : 'false',
}
...
1 change: 0 additions & 1 deletion trajopt/include/trajopt/json_marshal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
TRAJOPT_IGNORE_WARNINGS_PUSH
#include <Eigen/Eigen>
#include <boost/format.hpp>
#include <sstream>
#include <string>
#include <vector>
TRAJOPT_IGNORE_WARNINGS_POP
Expand Down
7 changes: 3 additions & 4 deletions trajopt/include/trajopt/problem_description.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <trajopt_common/macros.h>
TRAJOPT_IGNORE_WARNINGS_PUSH
#include <unordered_map>
#include <type_traits>
TRAJOPT_IGNORE_WARNINGS_POP

Expand Down Expand Up @@ -99,7 +98,7 @@ class TrajOptProb : public sco::OptProb

private:
/** @brief If true, the last column in the optimization matrix will be 1/dt */
bool has_time;
bool has_time{ false };
VarArray m_traj_vars;
std::shared_ptr<const tesseract_kinematics::JointGroup> m_kin;
std::shared_ptr<const tesseract_environment::Environment> m_env;
Expand Down Expand Up @@ -314,7 +313,7 @@ struct DynamicCartPoseTermInfo : public TermInfo
EIGEN_MAKE_ALIGNED_OPERATOR_NEW

/** @brief Timestep at which to apply term */
int timestep;
int timestep{ 0 };
/** @brief Coefficients for position and rotation */
Eigen::Vector3d pos_coeffs, rot_coeffs;
/** @brief Link which should reach desired pos */
Expand Down Expand Up @@ -354,7 +353,7 @@ struct CartPoseTermInfo : public TermInfo
EIGEN_MAKE_ALIGNED_OPERATOR_NEW

/** @brief Timestep at which to apply term */
int timestep;
int timestep{ 0 };
Eigen::Vector3d pos_coeffs, rot_coeffs;

/** @brief Link which should reach desired pos */
Expand Down
1 change: 0 additions & 1 deletion trajopt/include/trajopt/typedefs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <trajopt_common/macros.h>
TRAJOPT_IGNORE_WARNINGS_PUSH
#include <Eigen/Core>
#include <map>
#include <vector>
#include <tesseract_visualization/fwd.h>
TRAJOPT_IGNORE_WARNINGS_POP
Expand Down
1 change: 0 additions & 1 deletion trajopt/include/trajopt/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <trajopt_common/macros.h>
TRAJOPT_IGNORE_WARNINGS_PUSH
#include <unordered_map>
#include <Eigen/Geometry>
TRAJOPT_IGNORE_WARNINGS_POP

Expand Down
10 changes: 5 additions & 5 deletions trajopt/src/collision_terms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ void SingleTimestepCollisionEvaluator::Plot(const std::shared_ptr<tesseract_visu

tesseract_collision::ContactResultVector dist_results_copy(dist_results.size());
Eigen::VectorXd safety_distance(dist_results.size());
for (auto i = 0u; i < dist_results.size(); ++i)
for (auto i = 0U; i < dist_results.size(); ++i)
{
const tesseract_collision::ContactResult& res = dist_results[i].get();
dist_results_copy[i] = res;
Expand Down Expand Up @@ -1206,7 +1206,7 @@ void DiscreteCollisionEvaluator::Plot(const std::shared_ptr<tesseract_visualizat

tesseract_collision::ContactResultVector dist_results_copy(dist_results.size());
Eigen::VectorXd safety_distance(dist_results.size());
for (auto i = 0u; i < dist_results.size(); ++i)
for (auto i = 0U; i < dist_results.size(); ++i)
{
const tesseract_collision::ContactResult& res = dist_results[i].get();
dist_results_copy[i] = res;
Expand Down Expand Up @@ -1401,11 +1401,11 @@ void CastCollisionEvaluator::CalcCollisions(const Eigen::Ref<const Eigen::Vector
if (dist > longest_valid_segment_length_)
{
// Calculate the number state to interpolate
size_t cnt = static_cast<size_t>(std::ceil(dist / longest_valid_segment_length_)) + 1;
auto cnt = static_cast<long>(std::ceil(dist / longest_valid_segment_length_)) + 1;

// Create interpolated trajectory between two states that satisfies the longest valid segment length.
tesseract_common::TrajArray subtraj(cnt, dof_vals0.size());
for (size_t i = 0; i < dof_vals0.size(); ++i)
for (long i = 0; i < dof_vals0.size(); ++i)
subtraj.col(i) = Eigen::VectorXd::LinSpaced(cnt, dof_vals0(i), dof_vals1(i));

// Perform casted collision checking for sub trajectory and store results in contacts_vector
Expand Down Expand Up @@ -1461,7 +1461,7 @@ void CastCollisionEvaluator::Plot(const std::shared_ptr<tesseract_visualization:

tesseract_collision::ContactResultVector dist_results_copy(dist_results.size());
Eigen::VectorXd safety_distance(dist_results.size());
for (auto i = 0u; i < dist_results.size(); ++i)
for (auto i = 0U; i < dist_results.size(); ++i)
{
const tesseract_collision::ContactResult& res = dist_results[i].get();
dist_results_copy[i] = res;
Expand Down
4 changes: 3 additions & 1 deletion trajopt/src/file_write_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ std::function<void(sco::OptProb*, sco::OptResults&)> WriteCallback(std::shared_p
*file << std::endl;

// return callback function
return bind(&WriteFile, file, prob->GetKin(), std::ref(prob->GetVars()), std::placeholders::_2);
return [file, capture0 = prob->GetKin(), &capture1 = prob->GetVars()](auto&&, auto&& PH2) {
WriteFile(file, capture0, capture1, std::forward<decltype(PH2)>(PH2));
};
}
} // namespace trajopt
12 changes: 6 additions & 6 deletions trajopt/src/kinematic_terms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ CartPoseJacCalculator::CartPoseJacCalculator(
, source_frame_offset_(source_frame_offset)
, target_frame_(std::move(target_frame))
, target_frame_offset_(target_frame_offset)
, is_target_active_(manip_->isActiveLinkName(target_frame_))
, indices_(indices)
, epsilon_(DEFAULT_EPSILON)
{
is_target_active_ = manip_->isActiveLinkName(target_frame_);
assert(indices_.size() <= 6);

if (is_target_active_)
Expand Down Expand Up @@ -459,16 +459,16 @@ Eigen::VectorXd JointVelErrCalculator::operator()(const VectorXd& var_vals) cons
MatrixXd JointVelJacCalculator::operator()(const VectorXd& var_vals) const
{
// var_vals = (theta_t1, theta_t2, theta_t3 ... 1/dt_1, 1/dt_2, 1/dt_3 ...)
auto num_vals = static_cast<int>(var_vals.rows());
int half = num_vals / 2;
int num_vels = half - 1;
auto num_vals = var_vals.rows();
auto half = num_vals / 2;
auto num_vels = half - 1;
MatrixXd jac = MatrixXd::Zero(num_vels * 2, num_vals);

for (int i = 0; i < num_vels; i++)
for (auto i = 0; i < num_vels; i++)
{
// v = (j_i+1 - j_i)*(1/dt)
// We calculate v with the dt from the second pt
int time_index = i + half + 1;
auto time_index = i + half + 1;
// dv_i/dj_i = -(1/dt)
jac(i, i) = -1.0 * var_vals(time_index);
// dv_i/dj_i+1 = (1/dt)
Expand Down
24 changes: 12 additions & 12 deletions trajopt/src/problem_description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ TermInfo::Ptr TermInfo::fromName(const std::string& type)
return (*name2maker[type])();

// RAVELOG_ERROR("There is no cost of type %s\n", type.c_str());
return TermInfo::Ptr();
return {};
}

void ProblemConstructionInfo::readBasicInfo(const Json::Value& v)
Expand Down Expand Up @@ -165,7 +165,7 @@ void ProblemConstructionInfo::readCosts(const Json::Value& v)
for (const auto& it : v)
{
std::string type;
bool use_time;
bool use_time{ false };
json_marshal::childFromJson(it, type, "type");
json_marshal::childFromJson(it, use_time, "use_time", false);
LOG_DEBUG("reading term: %s", type.c_str());
Expand Down Expand Up @@ -195,7 +195,7 @@ void ProblemConstructionInfo::readConstraints(const Json::Value& v)
for (const auto& it : v)
{
std::string type;
bool use_time;
bool use_time{ false };
json_marshal::childFromJson(it, type, "type");
json_marshal::childFromJson(it, use_time, "use_time", false);
LOG_DEBUG("reading term: %s", type.c_str());
Expand Down Expand Up @@ -553,7 +553,7 @@ TrajOptProb::TrajOptProb(int n_steps, const ProblemConstructionInfo& pci)
: OptProb(pci.basic_info.convex_solver, pci.basic_info.convex_solver_config), m_kin(pci.kin), m_env(pci.env)
{
const Eigen::MatrixX2d& limits = m_kin->getLimits().joint_limits;
auto n_dof = static_cast<int>(m_kin->numJoints());
auto n_dof = m_kin->numJoints();
Eigen::VectorXd lower, upper;
lower = limits.col(0);
upper = limits.col(1);
Expand Down Expand Up @@ -587,7 +587,7 @@ TrajOptProb::TrajOptProb(int n_steps, const ProblemConstructionInfo& pci)
}
}
sco::VarVector trajvarvec = createVariables(names, vlower, vupper);
m_traj_vars = VarArray(n_steps, n_dof + (pci.basic_info.use_time ? 1 : 0), trajvarvec.data());
m_traj_vars = VarArray(n_steps, static_cast<int>(n_dof) + (pci.basic_info.use_time ? 1 : 0), trajvarvec.data());
}

void UserDefinedTermInfo::fromJson(ProblemConstructionInfo& /*pci*/, const Json::Value& /*v*/)
Expand Down Expand Up @@ -1224,7 +1224,7 @@ void JointVelTermInfo::hatch(TrajOptProb& prob)

if (term_type == (TermType::TT_COST | TermType::TT_USE_TIME))
{
auto num_vels = static_cast<unsigned>(last_step - first_step);
auto num_vels = static_cast<size_t>(last_step - first_step);

// Apply seperate cost to each joint b/c that is how the error function is currently written
for (size_t j = 0; j < n_dof; j++)
Expand Down Expand Up @@ -1263,7 +1263,7 @@ void JointVelTermInfo::hatch(TrajOptProb& prob)
}
else if (term_type == (TermType::TT_CNT | TermType::TT_USE_TIME))
{
auto num_vels = static_cast<unsigned>(last_step - first_step);
auto num_vels = static_cast<size_t>(last_step - first_step);

// Apply seperate cnt to each joint b/c that is how the error function is currently written
for (size_t j = 0; j < n_dof; j++)
Expand Down Expand Up @@ -1599,7 +1599,7 @@ void CollisionTermInfo::fromJson(ProblemConstructionInfo& pci, const Json::Value
const Json::Value& params = v["params"];

int n_steps = pci.basic_info.n_steps;
int collision_evaluator_type;
int collision_evaluator_type{ 0 };
json_marshal::childFromJson(params, collision_evaluator_type, "evaluator_type", 0);
json_marshal::childFromJson(params, use_weighted_sum, "use_weighted_sum", false);
json_marshal::childFromJson(params, first_step, "first_step", 0);
Expand Down Expand Up @@ -1738,7 +1738,7 @@ void CollisionTermInfo::hatch(TrajOptProb& prob)
bool current_fixed = std::find(fixed_steps.begin(), fixed_steps.end(), i) != fixed_steps.end();
bool next_fixed = std::find(fixed_steps.begin(), fixed_steps.end(), i + 1) != fixed_steps.end();

CollisionExpressionEvaluatorType expression_evaluator_type;
CollisionExpressionEvaluatorType expression_evaluator_type{};
if (!current_fixed && !next_fixed)
{
expression_evaluator_type = (use_weighted_sum) ?
Expand Down Expand Up @@ -1810,7 +1810,7 @@ void CollisionTermInfo::hatch(TrajOptProb& prob)
bool current_fixed = std::find(fixed_steps.begin(), fixed_steps.end(), i) != fixed_steps.end();
bool next_fixed = std::find(fixed_steps.begin(), fixed_steps.end(), i + 1) != fixed_steps.end();

CollisionExpressionEvaluatorType expression_evaluator_type;
CollisionExpressionEvaluatorType expression_evaluator_type{};
if (!current_fixed && !next_fixed)
{
expression_evaluator_type = (use_weighted_sum) ?
Expand Down Expand Up @@ -1899,8 +1899,8 @@ void TotalTimeTermInfo::hatch(TrajOptProb& prob)
}

// Get correct penalty type
sco::PenaltyType penalty_type;
sco::ConstraintType constraint_type;
sco::PenaltyType penalty_type{};
sco::ConstraintType constraint_type{};
if (trajopt_common::doubleEquals(limit, 0.0))
{
penalty_type = sco::SQUARED;
Expand Down

0 comments on commit b2bbade

Please sign in to comment.