momentumopt
ContactState.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <array>
12 #include <vector>
13 #include <memory>
14 #include <iostream>
15 #include <Eigen/Eigen>
16 
18 
19 namespace momentumopt {
20 
26  enum class ContactType { FreeContact = 0, FlatContact = 1, FullContact = 2 };
27  ContactType idToContactType(int cnt_type_id);
28 
38  {
39  public:
40  ContactState();
41  ~ContactState(){}
42 
43  int& terrainId() { return terrain_id_; }
44  int& optimizationId() { return optimization_id_; }
45  ContactType& contactType() { return contact_type_; }
46  double& contactActivationTime() { return time_ini_; }
47  double& contactDeactivationTime() { return time_end_; }
48  bool& selectedAsActive() { return selected_as_active_; }
49  Eigen::Vector3d& contactPosition() { return position_; }
50  Eigen::Quaternion<double>& contactOrientation() { return orientation_; }
51 
52  void contactActivationTime(const double& time_ini) { time_ini_ = time_ini; }
53  void contactDeactivationTime(const double& time_end) { time_end_ = time_end; }
54  void contactPosition(const Eigen::Vector3d& position) { position_ = position; }
55  void contactOrientation(const Eigen::Quaternion<double>& orientation) { orientation_ = orientation; }
56  void contactType(const ContactType& contact_type) { contact_type_ = contact_type; }
57  void contactPlacement(const Eigen::Matrix<double, 4, 4>& placement);
58  void selectedAsActive(const bool& active){selected_as_active_ = active;}
59 
60  const int& terrainId() const { return terrain_id_; }
61  const int& optimizationId() const { return optimization_id_; }
62  const ContactType& contactType() const { return contact_type_; }
63  const double& contactActivationTime() const { return time_ini_; }
64  const double& contactDeactivationTime() const { return time_end_; }
65  const bool& selectedAsActive() const { return selected_as_active_; }
66  const Eigen::Vector3d& contactPosition() const { return position_; }
67  const Eigen::Quaternion<double>& contactOrientation() const { return orientation_; }
68  const Eigen::Matrix<double, 4, 4> contactPlacement() const;
69 
70 
71  std::string toString() const;
72  friend std::ostream& operator<<(std::ostream &os, const ContactState& obj) { return os << obj.toString(); }
73 
74  private:
75  friend class ContactSequence;
76  ContactState(const Eigen::VectorXd& parameters, const int optimization_id);
77 
78  private:
79  bool selected_as_active_;
80  Eigen::Vector3d position_;
81  ContactType contact_type_;
82  double time_ini_, time_end_;
83  int optimization_id_, terrain_id_;
84  Eigen::Quaternion<double> orientation_;
85  };
86 
92  {
93  public:
94  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
95 
96  public:
97  ContactSequence(){}
98  ~ContactSequence(){}
99 
100  const int numOptimizationContacts() { return num_optimization_contacts_; }
101  const int numEndeffectorContacts(int eff_id) const { return endeffector_contacts_[eff_id].size(); }
102  void loadFromFile(const std::string cfg_file, const std::string contact_plan_name = "contact_plan");
103  std::vector<ContactState>& endeffectorContacts(int eff_id) { return endeffector_contacts_[eff_id]; }
104  const std::vector<ContactState>& endeffectorContacts(int eff_id) const { return endeffector_contacts_[eff_id]; }
105  void endeffectorContacts(int eff_id, const std::vector<ContactState>& endeffector_contacts) { endeffector_contacts_[eff_id] = endeffector_contacts; }
106  const long endeffectorNum() { return endeffector_contacts_.size(); }
107 
108  std::string toString() const;
109  friend std::ostream& operator<<(std::ostream &os, const ContactSequence& obj) { return os << obj.toString(); }
110 
111  private:
112  int num_optimization_contacts_;
113  std::array<std::vector<ContactState>, Problem::n_endeffs_> endeffector_contacts_;
114  };
115 
120  {
121  public:
122  ViapointState();
123  ~ViapointState(){}
124 
125  int& viapointId() { return viapoint_id_; }
126  Eigen::Vector3d& viapointPosition() { return position_; }
127  Eigen::Quaternion<double>& viapointOrientation() { return orientation_; }
128 
129  const int& viapointId() const { return viapoint_id_; }
130  const int& optimizationId() { return optimization_id_; }
131  const Eigen::Vector3d& viapointPosition() const { return position_; }
132  const Eigen::Quaternion<double>& viapointOrientation() const { return orientation_; }
133 
134  std::string toString() const;
135  friend std::ostream& operator<<(std::ostream &os, const ViapointState& obj) { return os << obj.toString(); }
136 
137  private:
138  friend class ViapointSequence;
139  ViapointState(const Eigen::VectorXd& parameters, const int optimization_id);
140 
141  private:
142  Eigen::Vector3d position_;
143  int optimization_id_, viapoint_id_;
144  Eigen::Quaternion<double> orientation_;
145  };
146 
151  {
152  public:
153  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
154 
155  public:
156  ViapointSequence(){}
157  ~ViapointSequence(){}
158 
159  const int& numOptimizationViapoints() const { return num_optimization_viapoints_; }
160  const int numEndeffectorViapoints(int eff_id) const { return endeffector_viapoints_[eff_id].size(); }
161  void loadFromFile(const std::string cfg_file, const std::string contact_plan_name = "contact_plan");
162  std::vector<ViapointState>& endeffectorViapoints(int eff_id) { return endeffector_viapoints_[eff_id]; }
163  const std::vector<ViapointState>& endeffectorViapoints(int eff_id) const { return endeffector_viapoints_[eff_id]; }
164 
165  std::string toString() const;
166  friend std::ostream& operator<<(std::ostream &os, const ViapointSequence& obj) { return os << obj.toString(); }
167 
168  private:
169  int num_optimization_viapoints_;
170  std::array<std::vector<ViapointState>, Problem::n_endeffs_> endeffector_viapoints_;
171  };
172 
173 
174 }
ContactType
Definition of contact type: FlatContact: forces subject to friction cone constrains of flat surface F...
Definition: ContactState.hpp:26
This class is a container for a sequence of viapoint states for all end-effectors.
Definition: ContactState.hpp:150
This class defines a viapoint state including position and orientation.
Definition: ContactState.hpp:119
static constexpr int n_endeffs_
Definition: Definitions.hpp:21
This class is a container for all variables required to define a contact state: position and orientat...
Definition: ContactState.hpp:37
This class is a container for a sequence of contact states, for all end-effectors.
Definition: ContactState.hpp:91