Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
pinocchio
Commits
a0a704c7
Verified
Commit
a0a704c7
authored
Nov 16, 2019
by
Justin Carpentier
Browse files
python/mode: templatization of ModelPythonVisitor
parent
c5a38f9e
Changes
2
Hide whitespace changes
Inline
Side-by-side
bindings/python/multibody/expose-model.cpp
View file @
a0a704c7
//
// Copyright (c) 2015-201
6
CNRS
// Copyright (c) 2015-201
9
CNRS
INRIA
//
#include
"pinocchio/bindings/python/fwd.hpp"
...
...
@@ -12,7 +12,7 @@ namespace pinocchio
void
exposeModel
()
{
ModelPythonVisitor
::
expose
();
ModelPythonVisitor
<
Model
>
::
expose
();
}
}
// namespace python
...
...
bindings/python/multibody/model.hpp
View file @
a0a704c7
...
...
@@ -34,16 +34,32 @@ namespace pinocchio
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
(
existFrame_overload
,
Model
::
existFrame
,
1
,
2
)
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS
(
addJointFrame_overload
,
Model
::
addJointFrame
,
1
,
2
)
template
<
typename
Model
>
struct
ModelPythonVisitor
:
public
bp
::
def_visitor
<
ModelPythonVisitor
>
:
public
bp
::
def_visitor
<
ModelPythonVisitor
<
Model
>
>
{
public:
typedef
Model
::
Index
Index
;
typedef
Model
::
JointIndex
JointIndex
;
typedef
Model
::
FrameIndex
FrameIndex
;
typedef
typename
Model
::
Scalar
Scalar
;
typedef
typename
Model
::
Index
Index
;
typedef
typename
Model
::
JointIndex
JointIndex
;
typedef
typename
Model
::
FrameIndex
FrameIndex
;
typedef
typename
Model
::
IndexVector
IndexVector
;
typedef
typename
Model
::
SE3
SE3
;
typedef
typename
Model
::
Motion
Motion
;
typedef
typename
Model
::
Force
Force
;
typedef
typename
Model
::
Frame
Frame
;
typedef
typename
Model
::
Inertia
Inertia
;
typedef
typename
Model
::
Data
Data
;
typedef
typename
Model
::
VectorXs
VectorXs
;
protected:
struct
addJointVisitor
:
public
boost
::
static_visitor
<
Model
::
Index
>
struct
addJointVisitor
:
public
boost
::
static_visitor
<
Index
>
{
Model
&
m_model
;
const
JointIndex
m_parent_id
;
...
...
@@ -67,25 +83,26 @@ namespace pinocchio
}
};
// struct addJointVisitor
struct
addJointWithLimitsVisitor
:
public
boost
::
static_visitor
<
Model
::
Index
>
struct
addJointWithLimitsVisitor
:
public
boost
::
static_visitor
<
Index
>
{
Model
&
m_model
;
const
JointIndex
m_parent_id
;
const
SE3
&
m_joint_placement
;
const
std
::
string
&
m_joint_name
;
const
Eigen
::
VectorX
d
&
m_max_effort
;
const
Eigen
::
VectorX
d
&
m_max_velocity
;
const
Eigen
::
VectorX
d
&
m_min_config
;
const
Eigen
::
VectorX
d
&
m_max_config
;
const
VectorX
s
&
m_max_effort
;
const
VectorX
s
&
m_max_velocity
;
const
VectorX
s
&
m_min_config
;
const
VectorX
s
&
m_max_config
;
addJointWithLimitsVisitor
(
Model
&
model
,
const
JointIndex
parent_id
,
const
SE3
&
joint_placement
,
const
std
::
string
&
joint_name
,
const
Eigen
::
VectorX
d
&
max_effort
,
const
Eigen
::
VectorX
d
&
max_velocity
,
const
Eigen
::
VectorX
d
&
min_config
,
const
Eigen
::
VectorX
d
&
max_config
)
const
VectorX
s
&
max_effort
,
const
VectorX
s
&
max_velocity
,
const
VectorX
s
&
min_config
,
const
VectorX
s
&
max_config
)
:
m_model
(
model
)
,
m_parent_id
(
parent_id
)
,
m_joint_placement
(
joint_placement
)
...
...
@@ -111,6 +128,7 @@ namespace pinocchio
{
cl
.
def
(
bp
::
init
<>
(
"Default constructor. Constructs an empty model."
))
// Class Members
.
add_property
(
"nq"
,
&
Model
::
nq
)
.
add_property
(
"nv"
,
&
Model
::
nv
)
...
...
@@ -217,10 +235,10 @@ namespace pinocchio
bp
::
object
jmodel
,
const
SE3
&
joint_placement
,
const
std
::
string
&
joint_name
,
const
Eigen
::
VectorX
d
&
max_effort
,
const
Eigen
::
VectorX
d
&
max_velocity
,
const
Eigen
::
VectorX
d
&
min_config
,
const
Eigen
::
VectorX
d
&
max_config
)
const
VectorX
s
&
max_effort
,
const
VectorX
s
&
max_velocity
,
const
VectorX
s
&
min_config
,
const
VectorX
s
&
max_config
)
{
JointModelVariant
jmodel_variant
=
bp
::
extract
<
JointModelVariant
>
(
jmodel
)();
return
boost
::
apply_visitor
(
addJointWithLimitsVisitor
(
model
,
parent_id
,
joint_placement
,
joint_name
,
max_effort
,
max_velocity
,
min_config
,
max_config
),
jmodel_variant
);
...
...
@@ -239,10 +257,10 @@ namespace pinocchio
/// no element is found, return the size of the vector.
///
template
<
typename
T
>
static
Model
::
Index
index
(
std
::
vector
<
T
>
const
&
x
,
static
Index
index
(
std
::
vector
<
T
>
const
&
x
,
typename
std
::
vector
<
T
>::
value_type
const
&
v
)
{
Model
::
Index
i
=
0
;
Index
i
=
0
;
for
(
typename
std
::
vector
<
T
>::
const_iterator
it
=
x
.
begin
();
it
!=
x
.
end
();
++
it
,
++
i
)
{
if
(
*
it
==
v
)
...
...
@@ -257,13 +275,13 @@ namespace pinocchio
static
void
expose
()
{
StdVectorPythonVisitor
<
Index
>::
expose
(
"StdVec_Index"
);
StdVectorPythonVisitor
<
Model
::
IndexVector
>::
expose
(
"StdVec_IndexVector"
);
StdVectorPythonVisitor
<
IndexVector
>::
expose
(
"StdVec_IndexVector"
);
StdVectorPythonVisitor
<
std
::
string
>::
expose
(
"StdVec_StdString"
);
StdVectorPythonVisitor
<
bool
>::
expose
(
"StdVec_Bool"
);
StdVectorPythonVisitor
<
double
>::
expose
(
"StdVec_double"
);
bp
::
class_
<
std
::
map
<
std
::
string
,
Eigen
::
Vector
Xd
>
>
(
"StdMap_String_EigenVectorXd"
)
.
def
(
bp
::
map_indexing_suite
<
std
::
map
<
std
::
string
,
Eigen
::
Vector
Xd
>
,
true
>
())
.
def_pickle
(
PickleMap
<
std
::
map
<
std
::
string
,
Eigen
::
Vector
Xd
>
>
());
StdVectorPythonVisitor
<
Scalar
>::
expose
(
"StdVec_double"
);
bp
::
class_
<
typename
Model
::
Config
Vector
Map
>
(
"StdMap_String_EigenVectorXd"
)
.
def
(
bp
::
map_indexing_suite
<
typename
Model
::
Config
Vector
Map
,
true
>
())
.
def_pickle
(
PickleMap
<
typename
Model
::
Config
Vector
Map
>
());
bp
::
class_
<
Model
>
(
"Model"
,
"Articulated Rigid Body model"
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment