@@ -160,7 +160,6 @@ bool moveWaypointFromCollisionTrajopt(WaypointPoly& waypoint,
160160 CONSOLE_BRIDGE_logError (" MoveWaypointFromCollision error: %s" , e.what ());
161161 return false ;
162162 }
163- auto num_jnts = static_cast <std::size_t >(start_pos.size ());
164163
165164 // Setup trajopt problem with basic info
166165 ProblemConstructionInfo pci (env);
@@ -183,23 +182,106 @@ bool moveWaypointFromCollisionTrajopt(WaypointPoly& waypoint,
183182 Eigen::VectorXd pos_tolerance = range * profile.jiggle_factor ;
184183 Eigen::VectorXd neg_tolerance = range * -profile.jiggle_factor ;
185184
186- { // Add Constraint
185+ // Use trajopt_joint_constraint_config if enabled
186+ if (profile.trajopt_joint_constraint_config .enabled )
187+ {
187188 auto jp_cnt = std::make_shared<JointPosTermInfo>();
188- jp_cnt->coeffs = std::vector<double >(num_jnts, 1.0 );
189+ jp_cnt->coeffs = std::vector<double >(profile.trajopt_joint_constraint_config .coeff .data (),
190+ profile.trajopt_joint_constraint_config .coeff .data () +
191+ profile.trajopt_joint_constraint_config .coeff .size ());
189192 jp_cnt->targets = std::vector<double >(start_pos.data (), start_pos.data () + start_pos.size ());
190- jp_cnt->upper_tols = std::vector<double >(pos_tolerance.data (), pos_tolerance.data () + pos_tolerance.size ());
191- jp_cnt->lower_tols = std::vector<double >(neg_tolerance.data (), neg_tolerance.data () + neg_tolerance.size ());
193+ if (profile.trajopt_joint_constraint_config .use_tolerance_override )
194+ {
195+ // Handle lower tolerance
196+ if (profile.trajopt_joint_constraint_config .lower_tolerance .size () == 1 )
197+ {
198+ jp_cnt->lower_tols = std::vector<double >(static_cast <std::size_t >(start_pos.size ()),
199+ profile.trajopt_joint_constraint_config .lower_tolerance [0 ]);
200+ }
201+ else if (profile.trajopt_joint_constraint_config .lower_tolerance .size () == start_pos.size ())
202+ {
203+ jp_cnt->lower_tols = std::vector<double >(profile.trajopt_joint_constraint_config .lower_tolerance .data (),
204+ profile.trajopt_joint_constraint_config .lower_tolerance .data () +
205+ profile.trajopt_joint_constraint_config .lower_tolerance .size ());
206+ }
207+ else
208+ {
209+ jp_cnt->lower_tols = std::vector<double >(neg_tolerance.data (), neg_tolerance.data () + neg_tolerance.size ());
210+ }
211+
212+ // Handle upper tolerance
213+ if (profile.trajopt_joint_constraint_config .upper_tolerance .size () == 1 )
214+ {
215+ jp_cnt->upper_tols = std::vector<double >(static_cast <std::size_t >(start_pos.size ()),
216+ profile.trajopt_joint_constraint_config .upper_tolerance [0 ]);
217+ }
218+ else if (profile.trajopt_joint_constraint_config .upper_tolerance .size () == start_pos.size ())
219+ {
220+ jp_cnt->upper_tols = std::vector<double >(profile.trajopt_joint_constraint_config .upper_tolerance .data (),
221+ profile.trajopt_joint_constraint_config .upper_tolerance .data () +
222+ profile.trajopt_joint_constraint_config .upper_tolerance .size ());
223+ }
224+ else
225+ {
226+ jp_cnt->upper_tols = std::vector<double >(pos_tolerance.data (), pos_tolerance.data () + pos_tolerance.size ());
227+ }
228+ }
229+ else
230+ {
231+ jp_cnt->lower_tols = std::vector<double >(neg_tolerance.data (), neg_tolerance.data () + neg_tolerance.size ());
232+ jp_cnt->upper_tols = std::vector<double >(pos_tolerance.data (), pos_tolerance.data () + pos_tolerance.size ());
233+ }
192234 jp_cnt->first_step = 0 ;
193235 jp_cnt->last_step = 0 ;
194236 jp_cnt->name = " joint_pos_cnt" ;
195237 jp_cnt->term_type = TermType::TT_CNT;
196238 pci.cnt_infos .push_back (jp_cnt);
197239 }
198240
199- { // Add Costs
241+ // Use trajopt_joint_cost_config if enabled
242+ if (profile.trajopt_joint_cost_config .enabled )
243+ {
200244 auto jp_cost = std::make_shared<JointPosTermInfo>();
201- jp_cost->coeffs = std::vector<double >(num_jnts, 5.0 );
245+ jp_cost->coeffs = std::vector<double >(profile.trajopt_joint_cost_config .coeff .data (),
246+ profile.trajopt_joint_cost_config .coeff .data () +
247+ profile.trajopt_joint_cost_config .coeff .size ());
202248 jp_cost->targets = std::vector<double >(start_pos.data (), start_pos.data () + start_pos.size ());
249+ if (profile.trajopt_joint_cost_config .use_tolerance_override )
250+ {
251+ // Handle lower tolerance
252+ if (profile.trajopt_joint_cost_config .lower_tolerance .size () == 1 )
253+ {
254+ jp_cost->lower_tols = std::vector<double >(static_cast <std::size_t >(start_pos.size ()),
255+ profile.trajopt_joint_cost_config .lower_tolerance [0 ]);
256+ }
257+ else if (profile.trajopt_joint_cost_config .lower_tolerance .size () == start_pos.size ())
258+ {
259+ jp_cost->lower_tols = std::vector<double >(profile.trajopt_joint_cost_config .lower_tolerance .data (),
260+ profile.trajopt_joint_cost_config .lower_tolerance .data () +
261+ profile.trajopt_joint_cost_config .lower_tolerance .size ());
262+ }
263+ else
264+ {
265+ jp_cost->lower_tols = std::vector<double >(neg_tolerance.data (), neg_tolerance.data () + neg_tolerance.size ());
266+ }
267+
268+ // Handle upper tolerance
269+ if (profile.trajopt_joint_cost_config .upper_tolerance .size () == 1 )
270+ {
271+ jp_cost->upper_tols = std::vector<double >(static_cast <std::size_t >(start_pos.size ()),
272+ profile.trajopt_joint_cost_config .upper_tolerance [0 ]);
273+ }
274+ else if (profile.trajopt_joint_cost_config .upper_tolerance .size () == start_pos.size ())
275+ {
276+ jp_cost->upper_tols = std::vector<double >(profile.trajopt_joint_cost_config .upper_tolerance .data (),
277+ profile.trajopt_joint_cost_config .upper_tolerance .data () +
278+ profile.trajopt_joint_cost_config .upper_tolerance .size ());
279+ }
280+ else
281+ {
282+ jp_cost->upper_tols = std::vector<double >(pos_tolerance.data (), pos_tolerance.data () + pos_tolerance.size ());
283+ }
284+ }
203285 jp_cost->first_step = 0 ;
204286 jp_cost->last_step = 0 ;
205287 jp_cost->name = " joint_pos_cost" ;
0 commit comments