momentumopt
DynamicsState.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <array>
12 #include <vector>
13 #include <string>
14 #include <iostream>
15 #include <Eigen/Eigen>
16 
19 
20 namespace momentumopt {
21 
30  {
31  public:
32  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
33 
34  public:
35  DynamicsState();
36  ~DynamicsState(){}
37 
38  // Center of mass, linear and angular momenta
39  double& time() { return dtime_; }
40  Eigen::Vector3d& centerOfMass() { return com_; }
41  Eigen::Vector3d& linearMomentum() { return lmom_; }
42  Eigen::Vector3d& angularMomentum() { return amom_; }
43  Eigen::Vector3d& linearMomentumRate() { return lmomd_; }
44  Eigen::Vector3d& angularMomentumRate() { return amomd_; }
45 
46  const double& time() const { return dtime_; }
47  const Eigen::Vector3d& centerOfMass() const { return com_; }
48  const Eigen::Vector3d& linearMomentum() const { return lmom_; }
49  const Eigen::Vector3d& angularMomentum() const { return amom_; }
50  const Eigen::Vector3d& linearMomentumRate() const { return lmomd_; }
51  const Eigen::Vector3d& angularMomentumRate() const { return amomd_; }
52 
53  void time(const double& dtime) { dtime_ = dtime; }
54  void centerOfMass(const Eigen::Vector3d& com) { com_ = com; }
55  void linearMomentum(const Eigen::Vector3d& lmom) { lmom_ = lmom; }
56  void angularMomentum(const Eigen::Vector3d& amom) { amom_ = amom; }
57  void linearMomentumRate(const Eigen::Vector3d& lmomd) { lmomd_ = lmomd; }
58  void angularMomentumRate(const Eigen::Vector3d& amomd) { amomd_ = amomd; }
59 
60  // Endeffector forces, torques and cops
61  Eigen::Vector3d& endeffectorCoP(int eff_id) { return eff_cops_[eff_id]; }
62  Eigen::Vector3d& endeffectorForce(int eff_id) { return eff_forces_[eff_id]; }
63  Eigen::Vector3d& endeffectorTorque(int eff_id) { return eff_torques_[eff_id]; }
64  Eigen::Vector3d& endeffectorTorqueAtContactPoint(int eff_id) { return eefs_trqs_contact_point_[eff_id]; }
65 
66  const long endeffectorNum() { return eff_cops_.size(); }
67  const Eigen::Vector3d& endeffectorCoP(int eff_id) const { return eff_cops_[eff_id]; }
68  const Eigen::Vector3d& endeffectorForce(int eff_id) const { return eff_forces_[eff_id]; }
69  const Eigen::Vector3d& endeffectorTorque(int eff_id) const { return eff_torques_[eff_id]; }
70  const Eigen::Vector3d& endeffectorTorqueAtContactPoint(int eff_id) const { return eefs_trqs_contact_point_[eff_id]; }
71 
72  const std::vector<Eigen::Vector3d>& pyEndeffectorCops() const { return eff_cops_; }
73  const std::vector<Eigen::Vector3d>& pyEndeffectorForces() const { return eff_forces_; }
74  const std::vector<Eigen::Vector3d>& pyEndeffectorTorques() const { return eff_torques_; }
75 
76  void pyEndeffectorCops(const std::vector<Eigen::Vector3d>& eff_cops) { eff_cops_ = eff_cops; }
77  void pyEndeffectorForces(const std::vector<Eigen::Vector3d>& eff_forces) { eff_forces_ = eff_forces; }
78  void pyEndeffectorTorques(const std::vector<Eigen::Vector3d>& eff_torques) { eff_torques_ = eff_torques; }
79 
80  // Endeffector activations, activation and contact ids
81  int& endeffectorContactId(int eff_id) { return cnt_ids_[eff_id]; }
82  int& endeffectorActivationId(int eff_id) { return eff_ids_[eff_id]; }
83  bool& endeffectorActivation(int eff_id) { return eff_activations_[eff_id]; }
84 
85  const int& endeffectorContactId(int eff_id) const { return cnt_ids_[eff_id]; }
86  const int& endeffectorActivationId(int eff_id) const { return eff_ids_[eff_id]; }
87  bool endeffectorActivation(int eff_id) const { return eff_activations_[eff_id]; }
88 
89  // endeffector poses
90  Eigen::Vector3d& endeffectorPosition(int eff_id) { return eff_positions_[eff_id]; }
91  Eigen::Vector3d& endeffectorVelocity(int eff_id) { return eff_velocities_[eff_id]; }
92  Eigen::Vector3d& endeffectorAcceleration(int eff_id) { return eff_accelerations_[eff_id]; }
93  Eigen::Quaternion<double>& endeffectorOrientation(int eff_id) { return eff_orientations_[eff_id]; }
94 
95  const Eigen::Vector3d& endeffectorPosition(int eff_id) const { return eff_positions_[eff_id]; }
96  const Eigen::Vector3d& endeffectorVelocity(int eff_id) const { return eff_velocities_[eff_id]; }
97  const Eigen::Vector3d& endeffectorAcceleration(int eff_id) const { return eff_accelerations_[eff_id]; }
98  const Eigen::Quaternion<double>& endeffectorOrientation(int eff_id) const { return eff_orientations_[eff_id]; }
99 
100  const std::vector<Eigen::Vector3d>& pyEndeffectorPositions() const { return eff_positions_; }
101  void pyEndeffectorPositions(const std::vector<Eigen::Vector3d>& eff_positions) { eff_positions_ = eff_positions; }
102 
103  // Helper functions
104  std::string toString() const;
105  friend std::ostream& operator<<(std::ostream &os, const DynamicsState& obj) { return os << obj.toString(); }
106  void fillInitialRobotState(const std::string cfg_file, const std::string robot_state = "initial_robot_configuration");
107 
108  private:
109  double dtime_;
110  Eigen::Vector3d com_, amom_, lmom_, amomd_, lmomd_;
111  std::array<bool, Problem::n_endeffs_> eff_activations_;
112  std::array<int, Problem::n_endeffs_> eff_ids_, cnt_ids_;
113 
114  std::vector<Eigen::Quaternion<double>> eff_orientations_;
115  std::vector<Eigen::Vector3d> eff_positions_, eff_velocities_, eff_accelerations_;
116  std::vector<Eigen::Vector3d> eff_forces_, eff_torques_, eff_cops_, eefs_trqs_contact_point_;
117  };
118 
124  {
125  public:
126  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
127 
128  public:
129  DynamicsSequence(){}
130  ~DynamicsSequence(){}
131 
132  void resize(int num_timesteps);
133  void clean() { dynamics_sequence_.clear(); }
134  int size() const { return dynamics_sequence_.size(); }
135 
136  const std::vector<DynamicsState>& dynamicsSequence() const { return dynamics_sequence_; }
137  void dynamicsSequence(const std::vector<DynamicsState>& dynamics_sequence) { dynamics_sequence_ = dynamics_sequence; }
138 
139  DynamicsState& dynamicsState(int time_id) { return dynamics_sequence_[time_id]; }
140  const DynamicsState& dynamicsState(int time_id) const { return dynamics_sequence_[time_id]; }
141 
142  Eigen::Matrix<int, Problem::n_endeffs_, 1>& activeEndeffectorSteps() { return active_endeffector_steps_; }
143  const Eigen::Matrix<int, Problem::n_endeffs_, 1>& activeEndeffectorSteps() const { return active_endeffector_steps_; }
144 
145  std::string toString() const;
146  friend std::ostream& operator<<(std::ostream &os, const DynamicsSequence& obj) { return os << obj.toString(); }
147 
148  private:
149  std::vector<DynamicsState> dynamics_sequence_;
150  Eigen::Matrix<int, Problem::n_endeffs_, 1> active_endeffector_steps_;
151  };
152 
153 }
This class is a container for all variables required to define a dynamic state: center of mass positi...
Definition: DynamicsState.hpp:29
This class is a container for a sequence of dynamic states, for all time steps in the optimization...
Definition: DynamicsState.hpp:123