Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pinocchio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stack Of Tasks
pinocchio
Commits
a9f71a13
Commit
a9f71a13
authored
8 years ago
by
Valenza Florian
Browse files
Options
Downloads
Patches
Plain Diff
[C++][Python] Added a method to get neutral config from an srdf file + binded it
parent
e98ba1ca
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/multibody/model.hxx
+15
-1
15 additions, 1 deletion
src/multibody/model.hxx
src/multibody/parser/srdf.hpp
+83
-0
83 additions, 0 deletions
src/multibody/parser/srdf.hpp
src/python/parsers.hpp
+17
-0
17 additions, 0 deletions
src/python/parsers.hpp
with
115 additions
and
1 deletion
src/multibody/model.hxx
+
15
−
1
View file @
a9f71a13
...
...
@@ -126,12 +126,26 @@ namespace se3
nq
+=
j
.
nq
();
nv
+=
j
.
nv
();
neutralConfigurations
.
conservativeResize
(
nq
);
neutralConfigurations
.
bottomRows
<
D
::
NQ
>
()
=
j
.
neutralConfiguration
();
effortLimit
.
conservativeResize
(
nv
);
effortLimit
.
bottomRows
<
D
::
NV
>
()
=
effort
;
velocityLimit
.
conservativeResize
(
nv
);
velocityLimit
.
bottomRows
<
D
::
NV
>
()
=
velocity
;
lowerPositionLimit
.
conservativeResize
(
nq
);
lowerPositionLimit
.
bottomRows
<
D
::
NQ
>
()
=
lowPos
;
upperPositionLimit
.
conservativeResize
(
nq
);
upperPositionLimit
.
bottomRows
<
D
::
NQ
>
()
=
upPos
;
// Ensure that limits are not inf
Eigen
::
VectorXd
neutralConf
((
lowerPositionLimit
.
bottomRows
<
D
::
NQ
>
()
+
upperPositionLimit
.
bottomRows
<
D
::
NQ
>
())
/
2
);
neutralConfigurations
.
conservativeResize
(
nq
);
if
(
std
::
isfinite
(
neutralConf
.
norm
())
)
{
neutralConfigurations
.
bottomRows
<
D
::
NQ
>
()
=
neutralConf
;
}
else
{
assert
(
false
&&
"One of the position limit is inf or NaN"
);
neutralConfigurations
.
bottomRows
<
D
::
NQ
>
()
=
j
.
neutralConfiguration
();
}
addFrame
((
jointName
!=
""
)
?
jointName
:
random
(
8
),
idx
,
SE3
::
Identity
(),
JOINT
);
return
idx
;
...
...
This diff is collapsed.
Click to expand it.
src/multibody/parser/srdf.hpp
+
83
−
0
View file @
a9f71a13
...
...
@@ -109,6 +109,89 @@ namespace se3
#endif // ifdef WITH_HPP_FCL
///
/// \brief Get the neutral configuration of a given model associated to a SRDF file.
/// It throws if the SRDF file is incorrect.
///
/// \param[in] model The Model for which we want the neutral config
/// \param[in] filename The complete path to the SRDF file.
/// \param[in] verbose Verbosity mode.
///
/// \return The neutral configuration as an eigen vector
inline
Eigen
::
VectorXd
getNeutralConfigurationFromSrdf
(
Model
&
model
,
const
std
::
string
&
filename
,
const
bool
verbose
)
throw
(
std
::
invalid_argument
)
{
const
Eigen
::
VectorXd
neutralConfig
(
model
.
nq
);
// Check extension
const
std
::
string
extension
=
filename
.
substr
(
filename
.
find_last_of
(
'.'
)
+
1
);
if
(
extension
!=
"srdf"
)
{
const
std
::
string
exception_message
(
filename
+
" does not have the right extension."
);
throw
std
::
invalid_argument
(
exception_message
);
}
// Open file
std
::
ifstream
srdf_stream
(
filename
.
c_str
());
if
(
!
srdf_stream
.
is_open
())
{
const
std
::
string
exception_message
(
filename
+
" does not seem to be a valid file."
);
throw
std
::
invalid_argument
(
exception_message
);
}
// Read xml stream
using
boost
::
property_tree
::
ptree
;
ptree
pt
;
read_xml
(
srdf_stream
,
pt
);
// Iterate over all tags directly children of robot
BOOST_FOREACH
(
const
ptree
::
value_type
&
v
,
pt
.
get_child
(
"robot"
))
{
// if we encounter a tag group_state
if
(
v
.
first
==
"group_state"
)
{
const
std
::
string
name
=
v
.
second
.
get
<
std
::
string
>
(
"<xmlattr>.name"
);
std
::
cout
<<
name
<<
std
::
endl
;
// Ensure that it is the half_sitting tag
if
(
name
==
"half_sitting"
)
{
// Iterate over all the joint tags
BOOST_FOREACH
(
const
ptree
::
value_type
&
joint
,
v
.
second
)
{
if
(
joint
.
first
==
"joint"
)
{
std
::
string
joint_name
=
joint
.
second
.
get
<
std
::
string
>
(
"<xmlattr>.name"
);
double
joint_config
=
joint
.
second
.
get
<
double
>
(
"<xmlattr>.value"
);
if
(
verbose
)
{
std
::
cout
<<
"("
<<
joint_name
<<
" , "
<<
joint_config
<<
")"
<<
std
::
endl
;
}
// Search in model the joint and its config id
Model
::
JointIndex
joint_id
=
model
.
getJointId
(
joint_name
);
const
JointModel
&
joint
=
model
.
joints
[
joint_id
];
if
(
joint_id
!=
model
.
joints
.
size
())
// != model.njoints
{
model
.
neutralConfigurations
(
joint
.
idx_q
())
=
joint_config
;
// joint with 1 dof
// model.neutralConfigurations.segment(joint.idx_q(),joint.nq()) = joint_config; // joint with more than 1 dof
}
else
{
if
(
verbose
)
std
::
cout
<<
"The Joint "
<<
joint_name
<<
" was not found in model"
<<
std
::
endl
;
}
}
}
return
neutralConfig
;
}
}
}
// BOOST_FOREACH
assert
(
false
&&
"no half_sitting configuration found in the srdf file"
);
// Should we throw something here ?
return
neutralConfig
;
// warning : uninitialized vector is returned
}
}
}
// namespace se3
...
...
This diff is collapsed.
Click to expand it.
src/python/parsers.hpp
+
17
−
0
View file @
a9f71a13
...
...
@@ -37,6 +37,8 @@
#include
"pinocchio/multibody/parser/lua.hpp"
#endif // #ifdef WITH_LUA
#include
"pinocchio/multibody/parser/srdf.hpp"
namespace
se3
{
namespace
python
...
...
@@ -122,6 +124,14 @@ namespace se3
}
#endif // #ifdef WITH_LUA
static
Eigen
::
VectorXd
getNeutralConfigurationFromSrdf
(
ModelHandler
&
model
,
const
std
::
string
&
filename
,
bool
verbose
)
{
return
se3
::
srdf
::
getNeutralConfigurationFromSrdf
(
*
model
,
filename
,
verbose
);
}
/* --- Expose --------------------------------------------------------- */
static
void
expose
();
};
// struct ParsersPythonVisitor
...
...
@@ -173,6 +183,13 @@ namespace se3
"Parse the urdf file given in input and return a proper pinocchio model "
"(remember to create the corresponding data structure)."
);
#endif // #ifdef WITH_LUA
bp
::
def
(
"getNeutralConfigurationFromSrdf"
,
getNeutralConfigurationFromSrdf
,
// static_cast <ModelHandler (*) ( const std::string &, bool)> (&ParsersPythonVisitor::getNeutralConfigurationFromSrdf),
bp
::
args
(
"Model for which we want the neutral config"
,
"srdf filename (string)"
,
"verbosity"
),
"Get the neutral configuration of a given model associated to a SRDF file"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment