aligator
0.19.0
A versatile and efficient C++ library for real-time constrained trajectory optimization.
Toggle main menu visibility
Loading...
Searching...
No Matches
contact-map.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
aligator/context.hpp
"
4
5
namespace
aligator
{
6
8
template
<
typename
_Scalar>
struct
ContactMapTpl
{
9
using
Scalar
= _Scalar;
10
ALIGATOR_DYNAMIC_TYPEDEFS
(
Scalar
);
11
using
PoseVec
= std::vector<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
"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_
;
79
PoseVec
contact_poses_
;
80
std::size_t
size_
;
81
};
82
83
#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
84
extern
template
struct
ContactMapTpl<context::Scalar>
;
85
#endif
86
}
// namespace aligator
context.hpp
ALIGATOR_RUNTIME_ERROR
#define ALIGATOR_RUNTIME_ERROR(...)
Definition
exceptions.hpp:8
aligator
Main package namespace.
Definition
action-model-wrap.hpp:14
aligator::ContactMapTpl
Contact map for centroidal costs and dynamics.
Definition
contact-map.hpp:8
aligator::ContactMapTpl< Scalar >::contact_states_
std::vector< bool > contact_states_
Definition
contact-map.hpp:78
aligator::ContactMapTpl::addContact
void addContact(std::string_view name, const bool state, const Vector3s &pose)
Definition
contact-map.hpp:28
aligator::ContactMapTpl::setContactPose
void setContactPose(std::string_view name, const Vector3s &ref)
Definition
contact-map.hpp:67
aligator::ContactMapTpl< Scalar >::contact_names_
std::vector< std::string > contact_names_
Definition
contact-map.hpp:77
aligator::ContactMapTpl::removeContact
void removeContact(const size_t i)
Definition
contact-map.hpp:36
aligator::ContactMapTpl::getContactState
bool getContactState(std::string_view name) const
Definition
contact-map.hpp:47
aligator::ContactMapTpl::getContactPose
const Vector3s & getContactPose(std::string_view name) const
Definition
contact-map.hpp:57
aligator::ContactMapTpl< Scalar >::size_
std::size_t size_
Definition
contact-map.hpp:80
aligator::ContactMapTpl::ALIGATOR_DYNAMIC_TYPEDEFS
ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
aligator::ContactMapTpl::ContactMapTpl
ContactMapTpl(const std::vector< std::string > &contact_names, const std::vector< bool > &contact_states, const PoseVec &contact_poses)
Definition
contact-map.hpp:13
aligator::ContactMapTpl< Scalar >::contact_poses_
PoseVec contact_poses_
Definition
contact-map.hpp:79
aligator::ContactMapTpl< Scalar >::PoseVec
std::vector< Vector3s > PoseVec
Definition
contact-map.hpp:11
aligator::ContactMapTpl< Scalar >::Scalar
Scalar Scalar
Definition
contact-map.hpp:9
include
aligator
modelling
contact-map.hpp
Generated by
1.17.0