aligator  0.16.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Loading...
Searching...
No Matches
contact-map.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace aligator {
6
8template <typename _Scalar> struct ContactMapTpl {
9 using Scalar = _Scalar;
12
13 ContactMapTpl(const std::vector<std::string> &contact_names,
14 const std::vector<bool> &contact_states,
15 const PoseVec &contact_poses)
16 : contact_names_(contact_names)
17 , contact_states_(contact_states)
18 , contact_poses_(contact_poses) {
19 if (contact_states.size() != contact_poses.size()) {
20 ALIGATOR_DOMAIN_ERROR(
21 "Contact_states and contact_poses should have same size, "
22 "currently ({:d} and {:d}).",
23 contact_states.size(), contact_poses.size());
24 }
25 size_ = contact_states_.size();
26 }
27
28 void addContact(std::string_view name, const bool state,
29 const Vector3s &pose) {
30 contact_names_.emplace_back(name);
31 contact_states_.push_back(state);
32 contact_poses_.push_back(pose);
33 size_ += 1;
34 }
35
36 void removeContact(const size_t i) {
37 if (size_ == 0) {
38 ALIGATOR_RUNTIME_ERROR("ContactMap is empty!");
39 } else {
40 contact_names_.erase(contact_names_.begin() + long(i));
41 contact_states_.erase(contact_states_.begin() + long(i));
42 contact_poses_.erase(contact_poses_.begin() + long(i));
43 size_ -= 1;
44 }
45 }
46
47 bool getContactState(std::string_view name) const {
48 auto it = std::find(contact_names_.begin(), contact_names_.end(), name);
49 if (it == contact_names_.end()) {
50 ALIGATOR_RUNTIME_ERROR("Contact name does not exist in this map!");
51 }
52
53 const auto index = size_t(it - contact_names_.begin());
54 return contact_states_[index];
55 }
56
57 const Vector3s &getContactPose(std::string_view name) const {
58 auto it = std::find(contact_names_.begin(), contact_names_.end(), name);
59 if (it == contact_names_.end()) {
60 ALIGATOR_RUNTIME_ERROR("Contact name does not exist in this map!");
61 }
62
63 const auto index = size_t(it - contact_names_.begin());
64 return contact_poses_[index];
65 }
66
67 void setContactPose(std::string_view name, const Vector3s &ref) {
68 auto it = std::find(contact_names_.begin(), contact_names_.end(), name);
69 if (it == contact_names_.end()) {
70 ALIGATOR_RUNTIME_ERROR("Contact name does not exist in this map!");
71 }
72
73 const auto index = size_t(it - contact_names_.begin());
74 contact_poses_[index] = ref;
75 }
76
77 std::vector<std::string> contact_names_;
78 std::vector<bool> contact_states_;
80 std::size_t size_;
81};
82
83#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
84extern template struct ContactMapTpl<context::Scalar>;
85#endif
86} // namespace aligator
#define ALIGATOR_RUNTIME_ERROR(...)
Definition exceptions.hpp:7
Main package namespace.
std::vector< T, Eigen::aligned_allocator< T > > StdVectorEigenAligned
Typedef for vector with Eigen::aligned_allocator allocator type.
Definition fwd.hpp:170
Contact map for centroidal costs and dynamics.
std::vector< bool > contact_states_
void addContact(std::string_view name, const bool state, const Vector3s &pose)
void setContactPose(std::string_view name, const Vector3s &ref)
std::vector< std::string > contact_names_
void removeContact(const size_t i)
bool getContactState(std::string_view name) const
StdVectorEigenAligned< Vector3s > PoseVec
const Vector3s & getContactPose(std::string_view name) const
ContactMapTpl(const std::vector< std::string > &contact_names, const std::vector< bool > &contact_states, const PoseVec &contact_poses)