-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
unit_quaternion_constraint.h
58 lines (48 loc) · 1.77 KB
/
unit_quaternion_constraint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once
#include <memory>
#include "drake/multibody/plant/multibody_plant.h"
#include "drake/solvers/constraint.h"
#include "drake/solvers/mathematical_program.h"
namespace drake {
namespace multibody {
/**
* Constrains the quaternion to have a unit length.
*
* @ingroup solver_evaluators
*/
class UnitQuaternionConstraint : public solvers::Constraint {
public:
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(UnitQuaternionConstraint)
UnitQuaternionConstraint();
~UnitQuaternionConstraint() override {}
private:
template <typename T, typename S>
void DoEvalGeneric(const Eigen::Ref<const VectorX<T>>& x,
VectorX<S>* y) const {
y->resize(1);
(*y)(0) = x(0) * x(0) + x(1) * x(1) + x(2) * x(2) + x(3) * x(3);
}
void DoEval(const Eigen::Ref<const Eigen::VectorXd>& x,
Eigen::VectorXd* y) const override;
void DoEval(const Eigen::Ref<const AutoDiffVecXd>& x,
AutoDiffVecXd* y) const override;
void DoEval(const Eigen::Ref<const VectorX<symbolic::Variable>>&,
VectorX<symbolic::Expression>*) const override;
};
/**
* Add unit length constraints to all the variables representing quaternion in
* `q_vars`. Namely the quaternions for floating base joints in `plant` will be
* enforced to have a unit length.
* @param plant The plant on which we impose the unit quaternion constraints.
* @param q_vars The decision variables for the generalized position of the
* plant.
* @param prog The unit quaternion constraints are added to this prog.
* @tparam_default_scalar
*/
template <typename T>
void AddUnitQuaternionConstraintOnPlant(
const MultibodyPlant<T>& plant,
const Eigen::Ref<const VectorX<symbolic::Variable>>& q_vars,
solvers::MathematicalProgram* prog);
} // namespace multibody
} // namespace drake