From 3b4d0cfd1feef7417e089e35b6ceb6133bd4d036 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Thu, 31 Mar 2022 18:31:59 -0700 Subject: [PATCH 1/5] Fix implicit conversion warnings These were caught as MSBuild warnings on Windows. In most cases, acknowledge that the conversions may lose precision by doing a static cast. In one case we change the type of an argument to be more accurate. Signed-off-by: Jacob Perron --- orocos_kdl/src/chainiksolvervel_pinv_givens.cpp | 8 ++++---- orocos_kdl/src/jacobian.cpp | 4 ++-- orocos_kdl/src/jntarray.cpp | 4 ++-- orocos_kdl/src/jntspaceinertiamatrix.cpp | 4 ++-- orocos_kdl/src/tree.cpp | 2 +- orocos_kdl/src/treeiksolverpos_online.cpp | 2 +- orocos_kdl/src/treeiksolverpos_online.hpp | 2 +- orocos_kdl/src/utilities/ldl_solver_eigen.cpp | 2 +- orocos_kdl/src/utilities/svd_eigen_HH.cpp | 4 ++-- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/orocos_kdl/src/chainiksolvervel_pinv_givens.cpp b/orocos_kdl/src/chainiksolvervel_pinv_givens.cpp index b38ce04ba..fbf102b40 100644 --- a/orocos_kdl/src/chainiksolvervel_pinv_givens.cpp +++ b/orocos_kdl/src/chainiksolvervel_pinv_givens.cpp @@ -30,8 +30,8 @@ namespace KDL jnt2jac(chain), jac(nj), transpose(nj>6),toggle(true), - m(max(6,nj)), - n(min(6,nj)), + m(static_cast(max(6,nj))), + n(static_cast(min(6,nj))), jac_eigen(m,n), U(Eigen::MatrixXd::Identity(m,m)), V(Eigen::MatrixXd::Identity(n,n)), @@ -50,8 +50,8 @@ namespace KDL jnt2jac.updateInternalDataStructures(); jac.resize(nj); transpose = (nj > 6); - m = max(6,nj); - n = min(6,nj); + m = static_cast(max(6,nj)); + n = static_cast(min(6,nj)); jac_eigen.conservativeResize(m,n); U.conservativeResizeLike(Eigen::MatrixXd::Identity(m,m)); V.conservativeResizeLike(Eigen::MatrixXd::Identity(n,n)); diff --git a/orocos_kdl/src/jacobian.cpp b/orocos_kdl/src/jacobian.cpp index a49420769..21d3d649f 100644 --- a/orocos_kdl/src/jacobian.cpp +++ b/orocos_kdl/src/jacobian.cpp @@ -68,12 +68,12 @@ namespace KDL unsigned int Jacobian::rows()const { - return data.rows(); + return static_cast(data.rows()); } unsigned int Jacobian::columns()const { - return data.cols(); + return static_cast(data.cols()); } void SetToZero(Jacobian& jac) diff --git a/orocos_kdl/src/jntarray.cpp b/orocos_kdl/src/jntarray.cpp index 6dc26218f..32c875d0b 100644 --- a/orocos_kdl/src/jntarray.cpp +++ b/orocos_kdl/src/jntarray.cpp @@ -69,12 +69,12 @@ namespace KDL unsigned int JntArray::rows()const { - return data.rows(); + return static_cast(data.rows()); } unsigned int JntArray::columns()const { - return data.cols(); + return static_cast(data.cols()); } void Add(const JntArray& src1,const JntArray& src2,JntArray& dest) diff --git a/orocos_kdl/src/jntspaceinertiamatrix.cpp b/orocos_kdl/src/jntspaceinertiamatrix.cpp index 31ea42000..fb8a4fed4 100644 --- a/orocos_kdl/src/jntspaceinertiamatrix.cpp +++ b/orocos_kdl/src/jntspaceinertiamatrix.cpp @@ -67,12 +67,12 @@ namespace KDL unsigned int JntSpaceInertiaMatrix::rows()const { - return data.rows(); + return static_cast(data.rows()); } unsigned int JntSpaceInertiaMatrix::columns()const { - return data.cols(); + return static_cast(data.cols()); } diff --git a/orocos_kdl/src/tree.cpp b/orocos_kdl/src/tree.cpp index 6d8943def..f933e7ea2 100644 --- a/orocos_kdl/src/tree.cpp +++ b/orocos_kdl/src/tree.cpp @@ -156,7 +156,7 @@ bool Tree::getChain(const std::string& chain_root, const std::string& chain_tip, } // add the segments from the common frame to the tip frame - for (int s=parents_chain_tip.size()-1; s>-1; s--){ + for (int s=static_cast(parents_chain_tip.size())-1; s>-1; s--){ chain.addSegment(GetTreeElementSegment(getSegment(parents_chain_tip[s])->second)); } return true; diff --git a/orocos_kdl/src/treeiksolverpos_online.cpp b/orocos_kdl/src/treeiksolverpos_online.cpp index 3e3d1318d..84d3146cb 100644 --- a/orocos_kdl/src/treeiksolverpos_online.cpp +++ b/orocos_kdl/src/treeiksolverpos_online.cpp @@ -26,7 +26,7 @@ namespace KDL { -TreeIkSolverPos_Online::TreeIkSolverPos_Online(const double& nr_of_jnts, +TreeIkSolverPos_Online::TreeIkSolverPos_Online(const unsigned int& nr_of_jnts, const std::vector& endpoints, const JntArray& q_min, const JntArray& q_max, diff --git a/orocos_kdl/src/treeiksolverpos_online.hpp b/orocos_kdl/src/treeiksolverpos_online.hpp index a9172a362..0ceda06fa 100644 --- a/orocos_kdl/src/treeiksolverpos_online.hpp +++ b/orocos_kdl/src/treeiksolverpos_online.hpp @@ -61,7 +61,7 @@ class TreeIkSolverPos_Online: public TreeIkSolverPos { * @return */ - TreeIkSolverPos_Online(const double& nr_of_jnts, + TreeIkSolverPos_Online(const unsigned int& nr_of_jnts, const std::vector& endpoints, const JntArray& q_min, const JntArray& q_max, diff --git a/orocos_kdl/src/utilities/ldl_solver_eigen.cpp b/orocos_kdl/src/utilities/ldl_solver_eigen.cpp index 1729ead9b..3f47afdc2 100644 --- a/orocos_kdl/src/utilities/ldl_solver_eigen.cpp +++ b/orocos_kdl/src/utilities/ldl_solver_eigen.cpp @@ -25,7 +25,7 @@ namespace KDL{ int ldl_solver_eigen(const Eigen::MatrixXd& A, const Eigen::VectorXd& v, Eigen::MatrixXd& L, Eigen::VectorXd& D, Eigen::VectorXd& vtmp, Eigen::VectorXd& q) { - const int n = A.rows(); + const int n = static_cast(A.rows()); int error=SolverI::E_NOERROR; //Check sizes diff --git a/orocos_kdl/src/utilities/svd_eigen_HH.cpp b/orocos_kdl/src/utilities/svd_eigen_HH.cpp index 2fdb9d2b0..7c7bd3794 100644 --- a/orocos_kdl/src/utilities/svd_eigen_HH.cpp +++ b/orocos_kdl/src/utilities/svd_eigen_HH.cpp @@ -26,8 +26,8 @@ namespace KDL{ int svd_eigen_HH(const Eigen::MatrixXd &A, Eigen::MatrixXd &U, Eigen::VectorXd &S, Eigen::MatrixXd &V, Eigen::VectorXd &tmp, int maxiter, double epsilon) { //get the rows/columns of the matrix - const int rows = A.rows(); - const int cols = A.cols(); + const int rows = static_cast(A.rows()); + const int cols = static_cast(A.cols()); U.setZero(); U.topLeftCorner(rows,cols)=A; From ef9b0ee228f1e69649d1b6762940c78293bc2873 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Thu, 31 Mar 2022 18:36:59 -0700 Subject: [PATCH 2/5] Use strncpy_s instead of strncpy on Windows Fixes a MSBuild warning on Windows. Signed-off-by: Jacob Perron --- orocos_kdl/src/utilities/error_stack.cxx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/orocos_kdl/src/utilities/error_stack.cxx b/orocos_kdl/src/utilities/error_stack.cxx index 78c5027a9..c4837e6e1 100644 --- a/orocos_kdl/src/utilities/error_stack.cxx +++ b/orocos_kdl/src/utilities/error_stack.cxx @@ -57,7 +57,11 @@ void IOTracePopStr(char* buffer,int size) { *buffer = 0; return; } +#if defined(_WIN32) + strncpy_s(buffer,size,errorstack.top().c_str(),size); +#else strncpy(buffer,errorstack.top().c_str(),size); +#endif buffer[size - 1] = '\0'; errorstack.pop(); } From d70e705f2f766adc4b22f931a3aaa7ffd470feac Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Fri, 1 Apr 2022 08:56:02 -0700 Subject: [PATCH 3/5] Do not break API Use static cast instead to avoid compiler warnings. Signed-off-by: Jacob Perron --- orocos_kdl/src/treeiksolverpos_online.cpp | 10 +++++----- orocos_kdl/src/treeiksolverpos_online.hpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/orocos_kdl/src/treeiksolverpos_online.cpp b/orocos_kdl/src/treeiksolverpos_online.cpp index 84d3146cb..35b2d5fb0 100644 --- a/orocos_kdl/src/treeiksolverpos_online.cpp +++ b/orocos_kdl/src/treeiksolverpos_online.cpp @@ -26,7 +26,7 @@ namespace KDL { -TreeIkSolverPos_Online::TreeIkSolverPos_Online(const unsigned int& nr_of_jnts, +TreeIkSolverPos_Online::TreeIkSolverPos_Online(const double& nr_of_jnts, const std::vector& endpoints, const JntArray& q_min, const JntArray& q_max, @@ -35,12 +35,12 @@ TreeIkSolverPos_Online::TreeIkSolverPos_Online(const unsigned int& nr_of_jnts, const double x_dot_rot_max, TreeFkSolverPos& fksolver, TreeIkSolverVel& iksolver) : - q_min_(nr_of_jnts), - q_max_(nr_of_jnts), - q_dot_max_(nr_of_jnts), + q_min_(static_cast(nr_of_jnts)), + q_max_(static_cast(nr_of_jnts)), + q_dot_max_(static_cast(nr_of_jnts)), fksolver_(fksolver), iksolver_(iksolver), - q_dot_(nr_of_jnts) + q_dot_(static_cast(nr_of_jnts)) { q_min_ = q_min; q_max_ = q_max; diff --git a/orocos_kdl/src/treeiksolverpos_online.hpp b/orocos_kdl/src/treeiksolverpos_online.hpp index 0ceda06fa..a9172a362 100644 --- a/orocos_kdl/src/treeiksolverpos_online.hpp +++ b/orocos_kdl/src/treeiksolverpos_online.hpp @@ -61,7 +61,7 @@ class TreeIkSolverPos_Online: public TreeIkSolverPos { * @return */ - TreeIkSolverPos_Online(const unsigned int& nr_of_jnts, + TreeIkSolverPos_Online(const double& nr_of_jnts, const std::vector& endpoints, const JntArray& q_min, const JntArray& q_max, From fc0dfd80cbe1810f7e27c10a860c7c1896174f99 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Fri, 1 Apr 2022 09:17:14 -0700 Subject: [PATCH 4/5] Remove members from initializer list They are set inside the constructor anyways. Signed-off-by: Jacob Perron --- orocos_kdl/src/treeiksolverpos_online.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/orocos_kdl/src/treeiksolverpos_online.cpp b/orocos_kdl/src/treeiksolverpos_online.cpp index 35b2d5fb0..594c3a056 100644 --- a/orocos_kdl/src/treeiksolverpos_online.cpp +++ b/orocos_kdl/src/treeiksolverpos_online.cpp @@ -35,9 +35,6 @@ TreeIkSolverPos_Online::TreeIkSolverPos_Online(const double& nr_of_jnts, const double x_dot_rot_max, TreeFkSolverPos& fksolver, TreeIkSolverVel& iksolver) : - q_min_(static_cast(nr_of_jnts)), - q_max_(static_cast(nr_of_jnts)), - q_dot_max_(static_cast(nr_of_jnts)), fksolver_(fksolver), iksolver_(iksolver), q_dot_(static_cast(nr_of_jnts)) From 3324420efff9b58b53d37680beb01a81e440d6f6 Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Fri, 1 Apr 2022 17:45:28 -0700 Subject: [PATCH 5/5] Use reverse iterator instead of decrementing index Signed-off-by: Jacob Perron --- orocos_kdl/src/tree.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/orocos_kdl/src/tree.cpp b/orocos_kdl/src/tree.cpp index f933e7ea2..70151e663 100644 --- a/orocos_kdl/src/tree.cpp +++ b/orocos_kdl/src/tree.cpp @@ -156,8 +156,8 @@ bool Tree::getChain(const std::string& chain_root, const std::string& chain_tip, } // add the segments from the common frame to the tip frame - for (int s=static_cast(parents_chain_tip.size())-1; s>-1; s--){ - chain.addSegment(GetTreeElementSegment(getSegment(parents_chain_tip[s])->second)); + for (auto rit=parents_chain_tip.rbegin(); rit != parents_chain_tip.rend(); ++rit){ + chain.addSegment(GetTreeElementSegment(getSegment(*rit)->second)); } return true; }