Skip to content

Commit dab3b9c

Browse files
committed
Throw an exception when number of coeffs or tolerances is incorrect
1 parent bb35eb8 commit dab3b9c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tesseract_motion_planners/trajopt/src/trajopt_utils.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ std::shared_ptr<trajopt::TermInfo> createCartesianWaypointTermInfo(int index,
9797
pose_info->pos_coeffs = coeffs.head<3>();
9898
pose_info->rot_coeffs = coeffs.tail<3>();
9999
}
100+
else
101+
{
102+
throw std::runtime_error("Invalid coeffs size for Cartesian waypoint term info. Expected 1 or 6, got " +
103+
std::to_string(coeffs.size()));
104+
}
100105

101106
if (lower_tolerance.size() == 1)
102107
{
@@ -106,6 +111,11 @@ std::shared_ptr<trajopt::TermInfo> createCartesianWaypointTermInfo(int index,
106111
{
107112
pose_info->lower_tolerance = lower_tolerance;
108113
}
114+
else
115+
{
116+
throw std::runtime_error("Invalid lower tolerance size for Cartesian waypoint term info. Expected 1 or 6, got " +
117+
std::to_string(lower_tolerance.size()));
118+
}
109119

110120
if (upper_tolerance.size() == 1)
111121
{
@@ -115,6 +125,11 @@ std::shared_ptr<trajopt::TermInfo> createCartesianWaypointTermInfo(int index,
115125
{
116126
pose_info->upper_tolerance = upper_tolerance;
117127
}
128+
else
129+
{
130+
throw std::runtime_error("Invalid upper tolerance size for Cartesian waypoint term info. Expected 1 or 6, got " +
131+
std::to_string(upper_tolerance.size()));
132+
}
118133

119134
return pose_info;
120135
}
@@ -150,6 +165,11 @@ std::shared_ptr<trajopt::TermInfo> createDynamicCartesianWaypointTermInfo(int in
150165
pose->pos_coeffs = coeffs.head<3>();
151166
pose->rot_coeffs = coeffs.tail<3>();
152167
}
168+
else
169+
{
170+
throw std::runtime_error("Invalid coeffs size for Cartesian waypoint term info. Expected 1 or 6, got " +
171+
std::to_string(coeffs.size()));
172+
}
153173

154174
pose->lower_tolerance = lower_tolerance;
155175
pose->upper_tolerance = upper_tolerance;
@@ -187,9 +207,18 @@ std::shared_ptr<trajopt::TermInfo> createJointWaypointTermInfo(const Eigen::Vect
187207
{
188208
auto joint_info = std::make_shared<trajopt::JointPosTermInfo>();
189209
if (coeffs.size() == 1)
210+
{
190211
joint_info->coeffs = std::vector<double>(static_cast<std::size_t>(j_wp.size()), coeffs(0));
212+
}
191213
else if (coeffs.size() == j_wp.size())
214+
{
192215
joint_info->coeffs = std::vector<double>(coeffs.data(), coeffs.data() + coeffs.rows() * coeffs.cols());
216+
}
217+
else
218+
{
219+
throw std::runtime_error("Invalid coeffs size for joint waypoint term info. Expected 1 or " +
220+
std::to_string(j_wp.size()) + ", got " + std::to_string(coeffs.size()));
221+
}
193222

194223
joint_info->targets = std::vector<double>(j_wp.data(), j_wp.data() + j_wp.rows() * j_wp.cols());
195224
joint_info->first_step = index;
@@ -209,9 +238,18 @@ std::shared_ptr<trajopt::TermInfo> createTolerancedJointWaypointTermInfo(const E
209238
{
210239
auto joint_info = std::make_shared<trajopt::JointPosTermInfo>();
211240
if (coeffs.size() == 1)
241+
{
212242
joint_info->coeffs = std::vector<double>(static_cast<std::size_t>(j_wp.size()), coeffs(0));
243+
}
213244
else if (coeffs.size() == j_wp.size())
245+
{
214246
joint_info->coeffs = std::vector<double>(coeffs.data(), coeffs.data() + coeffs.rows() * coeffs.cols());
247+
}
248+
else
249+
{
250+
throw std::runtime_error("Invalid coeffs size for joint waypoint term info. Expected 1 or " +
251+
std::to_string(j_wp.size()) + ", got " + std::to_string(coeffs.size()));
252+
}
215253

216254
joint_info->targets = std::vector<double>(j_wp.data(), j_wp.data() + j_wp.rows() * j_wp.cols());
217255
joint_info->lower_tols =

0 commit comments

Comments
 (0)