aligator  0.9.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
contact-map.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "aligator/fwd.hpp"
4
5namespace aligator {
6
8template <typename _Scalar> struct ContactMapTpl {
9 using Scalar = _Scalar;
11 using PoseVec = StdVectorEigenAligned<Vector3s>;
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), contact_states_(contact_states),
17 contact_poses_(contact_poses) {
18 if (contact_states.size() != contact_poses.size()) {
20 fmt::format("contact_states and contact_poses should have same size, "
21 "currently ({} and {}).",
22 contact_states.size(), contact_poses.size()));
23 }
24 size_ = contact_states_.size();
25 }
26
27 void addContact(const std::string &name, const bool state,
28 const Vector3s &pose) {
29 contact_names_.push_back(name);
30 contact_states_.push_back(state);
31 contact_poses_.push_back(pose);
32 size_ += 1;
33 }
34
35 void removeContact(const size_t i) {
36 if (size_ == 0) {
37 ALIGATOR_RUNTIME_ERROR("ContactMap is empty!");
38 } else {
39 contact_names_.erase(contact_names_.begin() + long(i));
40 contact_states_.erase(contact_states_.begin() + long(i));
41 contact_poses_.erase(contact_poses_.begin() + long(i));
42 size_ -= 1;
43 }
44 }
45
46 bool getContactState(const std::string &name) const {
47 auto id = std::find(contact_names_.begin(), contact_names_.end(), name);
48 if (id == contact_names_.end()) {
49 ALIGATOR_RUNTIME_ERROR("Contact name does not exist in this map!");
50 }
51
52 return contact_states_[id - contact_names_.begin()];
53 }
54
55 const Vector3s &getContactPose(const std::string &name) const {
56 auto id = std::find(contact_names_.begin(), contact_names_.end(), name);
57 if (id == contact_names_.end()) {
58 ALIGATOR_RUNTIME_ERROR("Contact name does not exist in this map!");
59 }
60
61 return contact_poses_[id - contact_names_.begin()];
62 }
63
64 void setContactPose(const std::string &name, const Vector3s &ref) {
65 auto id = std::find(contact_names_.begin(), contact_names_.end(), name);
66 if (id == contact_names_.end()) {
67 ALIGATOR_RUNTIME_ERROR("Contact name does not exist in this map!");
68 }
69
70 contact_poses_[id - contact_names_.begin()] = ref;
71 }
72
73 std::vector<std::string> contact_names_;
74 std::vector<bool> contact_states_;
76 std::size_t size_;
77};
78
79} // namespace aligator
#define ALIGATOR_RUNTIME_ERROR(...)
Definition exceptions.hpp:7
#define ALIGATOR_DOMAIN_ERROR(msg)
Forward declarations.
Main package namespace.
Contact map for centroidal costs and dynamics.
std::vector< bool > contact_states_
void addContact(const std::string &name, const bool state, const Vector3s &pose)
std::vector< std::string > contact_names_
const Vector3s & getContactPose(const std::string &name) const
void removeContact(const size_t i)
StdVectorEigenAligned< Vector3s > PoseVec
void setContactPose(const std::string &name, const Vector3s &ref)
bool getContactState(const std::string &name) const
ContactMapTpl(const std::vector< std::string > &contact_names, const std::vector< bool > &contact_states, const PoseVec &contact_poses)