@@ -36,6 +36,7 @@ TRAJOPT_IGNORE_WARNINGS_POP
3636namespace trajopt_ifopt
3737{
3838class JointPosition ;
39+ class Var ;
3940
4041/* * @brief Contains Cartesian pose constraint information */
4142struct CartPosInfo
@@ -202,5 +203,124 @@ class CartPosConstraint : public ifopt::ConstraintSet
202203
203204 static thread_local tesseract_common::TransformMap transforms_cache; // NOLINT
204205};
206+
207+ class CartPosConstraint2 : public ifopt ::ConstraintSet
208+ {
209+ public:
210+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW
211+
212+ using Ptr = std::shared_ptr<CartPosConstraint>;
213+ using ConstPtr = std::shared_ptr<const CartPosConstraint>;
214+ using ErrorFunctionType = std::function<Eigen::VectorXd(const Eigen::Isometry3d&, const Eigen::Isometry3d&)>;
215+ using ErrorDiffFunctionType = std::function<Eigen::VectorXd(const Eigen::VectorXd&,
216+ const Eigen::Isometry3d&,
217+ const Eigen::Isometry3d&,
218+ tesseract_common::TransformMap&)>;
219+
220+ CartPosConstraint2 (const CartPosInfo& info,
221+ std::shared_ptr<const Var> position_var,
222+ const std::string& name = " CartPos" );
223+
224+ CartPosConstraint2 (CartPosInfo info,
225+ std::shared_ptr<const Var> position_var,
226+ const Eigen::VectorXd& coeffs,
227+ const std::string& name = " CartPos" );
228+
229+ /* *
230+ * @brief CalcValues Calculates the values associated with the constraint
231+ * @param joint_vals Input joint values for which FK is solved
232+ * @return Error of FK solution from target, size 6. The first 3 terms are associated with position and the last 3 are
233+ * associated with orientation.
234+ */
235+ Eigen::VectorXd CalcValues (const Eigen::Ref<const Eigen::VectorXd>& joint_vals) const ;
236+ /* *
237+ * @brief Returns the values associated with the constraint. In this case that is the concatenated joint values
238+ * associated with each of the joint positions should be n_dof_ * n_vars_ long
239+ * @return
240+ */
241+ Eigen::VectorXd GetValues () const override ;
242+
243+ /* *
244+ * @brief Returns the "bounds" of this constraint. How these are enforced is up to the solver
245+ * @return Returns the "bounds" of this constraint
246+ */
247+ std::vector<ifopt::Bounds> GetBounds () const override ;
248+
249+ void SetBounds (const std::vector<ifopt::Bounds>& bounds);
250+
251+ /* *
252+ * @brief Fills the jacobian block associated with the constraint
253+ * @param jac_block Block of the overall jacobian associated with these constraints
254+ */
255+ void CalcJacobianBlock (const Eigen::Ref<const Eigen::VectorXd>& joint_vals, Jacobian& jac_block) const ;
256+ /* *
257+ * @brief Fills the jacobian block associated with the given var_set.
258+ * @param var_set Name of the var_set to which the jac_block is associated
259+ * @param jac_block Block of the overall jacobian associated with these constraints and the var_set variable
260+ */
261+ void FillJacobianBlock (std::string var_set, Jacobian& jac_block) const override ;
262+
263+ /* *
264+ * @brief Gets the Cartesian Pose info used to create this constraint
265+ * @return The Cartesian Pose info used to create this constraint
266+ */
267+ const CartPosInfo& GetInfo () const ;
268+ CartPosInfo& GetInfo ();
269+
270+ /* *
271+ * @brief Set the target pose
272+ * @param pose
273+ */
274+ void SetTargetPose (const Eigen::Isometry3d& target_frame_offset);
275+
276+ /* *
277+ * @brief Returns the target pose for the constraint
278+ * @return The target pose for the constraint
279+ */
280+ Eigen::Isometry3d GetTargetPose () const ;
281+
282+ /* *
283+ * @brief Returns the current TCP pose in world frame given the input kinematic info and the current variable values
284+ * @return The current TCP pose given the input kinematic info and the current variable values
285+ */
286+ Eigen::Isometry3d GetCurrentPose () const ;
287+
288+ /* * @brief If true, numeric differentiation will be used. Default: true
289+ *
290+ * Note: While the logic for using the jacobian from KDL will be used if set to false, this has been buggy. Set this
291+ * to false at your own risk.
292+ */
293+ bool use_numeric_differentiation{ true };
294+
295+ private:
296+ /* * @brief The var_set associated with this constraint */
297+ std::string var_set_;
298+
299+ /* * @brief The number of joints in a single JointPosition */
300+ long n_dof_;
301+
302+ /* * @brief The constraint coefficients */
303+ Eigen::VectorXd coeffs_;
304+
305+ /* * @brief Bounds on the positions of each joint */
306+ std::vector<ifopt::Bounds> bounds_;
307+
308+ /* *
309+ * @brief Pointers to the vars used by this constraint.
310+ * Do not access them directly. Instead use this->GetVariables()->GetComponent(position_var->GetName())->GetValues()
311+ */
312+ std::shared_ptr<const Var> position_var_;
313+
314+ /* * @brief The kinematic information used when calculating error */
315+ CartPosInfo info_;
316+
317+ /* * @brief Error function for calculating the error in the position given the source and target positions */
318+ ErrorFunctionType error_function_{ nullptr };
319+
320+ /* * @brief The error function to calculate the error difference used for jacobian calculations */
321+ ErrorDiffFunctionType error_diff_function_{ nullptr };
322+
323+ static thread_local tesseract_common::TransformMap transforms_cache; // NOLINT
324+ };
205325} // namespace trajopt_ifopt
206326#endif
0 commit comments