1#ifndef ROBOTOC_CONTACT_STATUS_HXX_
2#define ROBOTOC_CONTACT_STATUS_HXX_
15 const std::vector<ContactType>& contact_types,
16 const std::vector<std::string>& contact_frame_names,
17 const double default_friction_coefficients)
18 : contact_types_(contact_types),
19 contact_frame_names_(contact_frame_names),
20 is_contact_active_(contact_types.size(), false),
21 contact_placements_(contact_types.size(),
SE3::Identity()),
22 contact_positions_(contact_types.size(), Eigen::Vector3d::
Zero()),
23 contact_rotations_(contact_types.size(), Eigen::Matrix3d::Identity()),
24 friction_coefficients_(contact_types.size(), 0.7),
26 max_contacts_(contact_types.size()),
27 max_num_contacts_(contact_types.size()),
28 has_active_contacts_(false) {
29 if (contact_types.size() != contact_frame_names.size()) {
30 throw std::invalid_argument(
31 "[ContactStatus] invalid argument: contact_frame_names.size() must be the same as contact_types.size()!");
33 if (default_friction_coefficients <= 0.0) {
34 throw std::invalid_argument(
"[ContactStatus] invalid argument: 'default_friction_coefficients' must be positive!");
41 contact_frame_names_(),
43 contact_placements_(),
46 friction_coefficients_(),
50 has_active_contacts_(false) {
56 for (
int i=0; i<max_num_contacts_; ++i) {
69 return !(*
this == other);
74 assert(contact_index >= 0);
75 assert(contact_index < max_num_contacts_);
76 return contact_types_[contact_index];
81 return contact_types_;
86 const int contact_index)
const {
87 assert(contact_index >= 0);
88 assert(contact_index < max_num_contacts_);
89 if (contact_frame_names_.empty()) {
90 throw std::runtime_error(
"[ContactStatus] invalid argument: contact_frame_names_ is empty!");
92 return contact_frame_names_[contact_index];
97 return contact_frame_names_;
102 assert(!is_contact_active_.empty());
103 assert(contact_index >= 0);
104 assert(contact_index < is_contact_active_.size());
105 return is_contact_active_[contact_index];
110 const std::string& contact_frame_name)
const {
116 return is_contact_active_;
121 return has_active_contacts_;
131 return max_num_contacts_;
136 assert(contact_index >= 0);
137 assert(contact_index < max_num_contacts_);
138 if (!is_contact_active_[contact_index]) {
139 is_contact_active_[contact_index] =
true;
140 switch (contact_types_[contact_index]) {
151 setHasActiveContacts();
161 assert(contact_index >= 0);
162 assert(contact_index < max_num_contacts_);
163 if (is_contact_active_[contact_index]) {
164 is_contact_active_[contact_index] =
false;
165 switch (contact_types_[contact_index]) {
176 setHasActiveContacts();
186 const std::vector<int>& contact_indices) {
187 assert(contact_indices.size() <= max_num_contacts_);
188 for (
const int e : contact_indices) {
195 const std::vector<std::string>& contact_frame_names) {
196 assert(contact_frame_names.size() <= max_num_contacts_);
197 for (
const auto& e : contact_frame_names) {
204 const std::vector<int>& contact_indices) {
205 assert(contact_indices.size() <= max_num_contacts_);
206 for (
const int e : contact_indices) {
213 const std::vector<std::string>& contact_frame_names) {
214 assert(contact_frame_names.size() <= max_num_contacts_);
215 for (
const auto& e : contact_frame_names) {
222 const int contact_index,
const Eigen::Vector3d& contact_position) {
224 Eigen::Matrix3d::Identity());
229 const std::string& contact_frame_name,
230 const Eigen::Vector3d& contact_position) {
232 Eigen::Matrix3d::Identity());
237 const int contact_index,
const Eigen::Vector3d& contact_position,
238 const Eigen::Matrix3d& contact_rotation) {
239 assert(contact_index >= 0);
240 assert(contact_index < max_num_contacts_);
241 contact_positions_[contact_index] = contact_position;
242 contact_rotations_[contact_index] = contact_rotation;
243 contact_placements_[contact_index] =
SE3(contact_rotation, contact_position);
248 const std::string& contact_frame_name,
249 const Eigen::Vector3d& contact_position,
250 const Eigen::Matrix3d& contact_rotation) {
257 const SE3& contact_placement) {
258 assert(contact_index >= 0);
259 assert(contact_index < max_num_contacts_);
260 contact_positions_[contact_index] = contact_placement.translation();
261 contact_rotations_[contact_index] = contact_placement.rotation();
262 contact_placements_[contact_index] = contact_placement;
267 const SE3& contact_placement) {
273 const std::vector<Eigen::Vector3d>& contact_positions) {
274 assert(contact_positions.size() == max_num_contacts_);
275 for (
int i=0; i<max_num_contacts_; ++i) {
282 const std::unordered_map<std::string, Eigen::Vector3d>& contact_positions) {
283 assert(contact_positions.size() == max_num_contacts_);
284 for (
int i=0; i<max_num_contacts_; ++i) {
286 Eigen::Matrix3d::Identity());
292 const std::vector<Eigen::Vector3d>& contact_positions,
293 const std::vector<Eigen::Matrix3d>& contact_rotations) {
294 assert(contact_positions.size() == max_num_contacts_);
295 assert(contact_rotations.size() == max_num_contacts_);
296 for (
int i=0; i<max_num_contacts_; ++i) {
303 const std::unordered_map<std::string, Eigen::Vector3d>& contact_positions,
304 const std::unordered_map<std::string, Eigen::Matrix3d>& contact_rotations) {
305 assert(contact_positions.size() == max_num_contacts_);
306 assert(contact_rotations.size() == max_num_contacts_);
307 for (
int i=0; i<max_num_contacts_; ++i) {
316 assert(contact_placements.size() == max_num_contacts_);
317 for (
int i=0; i<max_num_contacts_; ++i) {
325 assert(contact_placements.size() == max_num_contacts_);
326 for (
int i=0; i<max_num_contacts_; ++i) {
333 const int contact_index)
const {
334 assert(contact_index >= 0);
335 assert(contact_index < max_num_contacts_);
336 return contact_placements_[contact_index];
341 const std::string& contact_frame_name)
const {
347 const int contact_index)
const {
348 assert(contact_index >= 0);
349 assert(contact_index < max_num_contacts_);
350 return contact_positions_[contact_index];
355 const std::string& contact_frame_name)
const {
361 const int contact_index)
const {
362 assert(contact_index >= 0);
363 assert(contact_index < max_num_contacts_);
364 return contact_rotations_[contact_index];
369 const std::string& contact_frame_name)
const {
375 return contact_placements_;
379inline const std::vector<Eigen::Vector3d>&
381 return contact_positions_;
385inline const std::vector<Eigen::Matrix3d>&
387 return contact_rotations_;
392 const double friction_coefficient) {
393 if (friction_coefficient <= 0.0) {
394 throw std::invalid_argument(
"[ContactStatus] invalid argument: 'friction_coefficient' must be positive!");
396 assert(contact_index >= 0);
397 assert(contact_index < max_num_contacts_);
398 friction_coefficients_[contact_index] = friction_coefficient;
403 const double friction_coefficient) {
409 const std::vector<double>& friction_coefficients) {
410 assert(friction_coefficients.size() == max_num_contacts_);
411 for (
int i=0; i<max_num_contacts_; ++i) {
418 const std::unordered_map<std::string, double>& friction_coefficients) {
419 assert(friction_coefficients.size() == max_num_contacts_);
420 for (
int i=0; i<max_num_contacts_; ++i) {
427 assert(contact_index >= 0);
428 assert(contact_index < max_num_contacts_);
429 return friction_coefficients_[contact_index];
434 const std::string& contact_frame_name)
const {
440 return friction_coefficients_;
445 const std::string& contact_frame_name)
const {
446 if (contact_frame_names_.empty()) {
447 throw std::runtime_error(
"[ContactStatus] invalid argument: contact_frame_names_ is empty!");
449 for (
int i=0; i<contact_frame_names_.size(); ++i) {
450 if (contact_frame_names_[i] == contact_frame_name) {
454 throw std::runtime_error(
"[ContactStatus] cannot find the input contact_frame_name: '" + contact_frame_name +
"'");
459 std::minstd_rand0 rand(
460 std::chrono::system_clock::now().time_since_epoch().count());
461 for (
int i=0; i<max_num_contacts_; ++i) {
472inline void ContactStatus::setHasActiveContacts() {
473 has_active_contacts_ = (dimf_ > 0);
Definition: constraint_component_base.hpp:17
ContactType
Types of contacts.
Definition: contact_status.hpp:22
std::vector< T, Eigen::aligned_allocator< T > > aligned_vector
std vector with Eigen::aligned_allocator.
Definition: aligned_vector.hpp:14
std::unordered_map< Key, T, std::hash< Key >, std::equal_to< Key >, Eigen::aligned_allocator< std::pair< Key, T > > > aligned_unordered_map
std unordered_map with Eigen::aligned_allocator.
Definition: aligned_unordered_map.hpp:15
pinocchio::SE3 SE3
Using pinocchio::SE3 without its namespace.
Definition: se3.hpp:15