7 template =
"""class {name:s}Constraint : public ompl::base::Constraint
10 {name:s}Constraint() : ompl::base::Constraint({ambientDim:d}, {constraintDim:d})
14 void function(const Eigen::Ref<const Eigen::VectorXd> &x, Eigen::Ref<Eigen::VectorXd> out) const override
18 void jacobian(const Eigen::Ref<const Eigen::VectorXd> &x, Eigen::Ref<Eigen::MatrixXd> out) const override
26 def __init__(self, name, n):
29 self.
variables_ = [sp.Symbol(
"x[{:d}]".format(i), real=
True)
for i
in range(n)]
33 """Return the index^th variable."""
37 """Create a variable vector."""
41 """Create a constraint function vector."""
45 """Add some symbolic function of variables to the list of constraints."""
49 """Compute the Jacobian of the current list of constraints."""
56 ss += sp.printing.cxxcode(sp.simplify(self.
constraints_[i]),
57 assign_to=
"out[{:d}]".format(i))
64 for i
in range(jac.shape[0]):
65 for j
in range(jac.shape[1]):
67 ss += sp.printing.cxxcode(sp.simplify(jac[i, j]),
68 assign_to=
"out({:d}, {:d})".format(i, j))
73 return template.format(name=self.
name_,
79 if __name__ ==
"__main__":
82 s.addConstraint(s.getVars().norm() - 1)
93 torus = (t.getVars() - outer_radius * c / c.norm()).norm() - inner_radius
94 t.addConstraint(torus)