aligator  0.14.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)
17 , contact_states_(contact_states)
18 , contact_poses_(contact_poses) {
19 if (contact_states.size() != contact_poses.size()) {
20 ALIGATOR_DOMAIN_ERROR(
21 fmt::format("contact_states and contact_poses should have same size, "
22 "currently ({} and {}).",
23 contact_states.size(), contact_poses.size()));
24 }
25 size_ = contact_states_.size();
26 }
27
28 void addContact(const std::string &name, const bool state,
29 const Vector3s &pose) {
30 contact_names_.push_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(const std::string &name) const {
48 auto id = std::find(contact_names_.begin(), contact_names_.end(), name);
49 if (id == contact_names_.end()) {
50 ALIGATOR_RUNTIME_ERROR("Contact name does not exist in this map!");
51 }
52
53 return contact_states_[id - contact_names_.begin()];
54 }
55
56 const Vector3s &getContactPose(const std::string &name) const {
57 auto id = std::find(contact_names_.begin(), contact_names_.end(), name);
58 if (id == contact_names_.end()) {
59 ALIGATOR_RUNTIME_ERROR("Contact name does not exist in this map!");
60 }
61
62 return contact_poses_[id - contact_names_.begin()];
63 }
64
65 void setContactPose(const std::string &name, const Vector3s &ref) {
66 auto id = std::find(contact_names_.begin(), contact_names_.end(), name);
67 if (id == contact_names_.end()) {
68 ALIGATOR_RUNTIME_ERROR("Contact name does not exist in this map!");
69 }
70
71 contact_poses_[id - contact_names_.begin()] = ref;
72 }
73
74 std::vector<std::string> contact_names_;
75 std::vector<bool> contact_states_;
77 std::size_t size_;
78};
79
80} // namespace aligator
#define ALIGATOR_RUNTIME_ERROR(...)
Definition exceptions.hpp:7
Forward declarations.
Main package namespace.
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)