Skip to content

Commit f7f8ebb

Browse files
[tools] ParameterServer and RobotUtils are simplified and explained
better. Thanks to the feedback of Joseph Mirabel.
1 parent c19c7c5 commit f7f8ebb

File tree

4 files changed

+61
-38
lines changed

4 files changed

+61
-38
lines changed

include/sot/core/parameter-server.hh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ public:
104104
const Type &ParameterValue)
105105
{
106106
if (!m_initSucceeded) {
107-
DYNAMIC_GRAPH_ENTITY_WARNING(*this) << "Cannot set parameter " << ParameterName
108-
<< " to " << ParameterValue << " before initialization!\n";
107+
DYNAMIC_GRAPH_ENTITY_WARNING(*this) << "Cannot set parameter " <<
108+
ParameterName << " to " << ParameterValue
109+
<< " before initialization!\n";
109110
return;
110111
}
111112

@@ -117,8 +118,8 @@ public:
117118
{
118119

119120
if (!m_initSucceeded) {
120-
SEND_WARNING_STREAM_MSG("Cannot get parameter " + ParameterName +
121-
" before initialization!");
121+
DYNAMIC_GRAPH_ENTITY_WARNING(*this) << "Cannot get parameter " <<
122+
ParameterName << " before initialization!\n";
122123
Type ParameterValue;
123124
return ParameterValue;
124125
}

include/sot/core/robot-utils.hh

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,22 @@
1111
/* --------------------------------------------------------------------- */
1212
/* --- INCLUDE --------------------------------------------------------- */
1313
/* --------------------------------------------------------------------- */
14+
15+
/** pinocchio is forcing the BOOST_MPL_LIMIT_VECTOR_SIZE to a specific value.
16+
This happen to be not working when including the boost property_tree library.
17+
For this reason if defined, the current value of BOOST_MPL_LIMIT_VECTOR_SIZE
18+
is saved in the preprocessor stack and unset.
19+
Once the property_tree included the pinocchio value of this variable is
20+
restored.
21+
*/
22+
1423
#ifdef BOOST_MPL_LIMIT_VECTOR_SIZE
1524
#pragma push_macro("BOOST_MPL_LIMIT_VECTOR_SIZE")
1625
#undef BOOST_MPL_LIMIT_VECTOR_SIZE
17-
#define BOOST_MPL_LIMIT_VECTOR_SIZE_PUSH
18-
#endif
19-
20-
#ifdef BOOST_MPL_LIMIT_LIST_SIZE
21-
#pragma push_macro("BOOST_MPL_LIMIT_LIST_SIZE")
22-
#undef BOOST_MPL_LIMIT_LIST_SIZE
23-
#define BOOST_MPL_LIMIT_LIST_SIZE_PUSH
24-
#endif
25-
2626
#include <boost/property_tree/ptree.hpp>
27-
28-
#ifdef BOOST_MPL_LIMIT_VECTOR_SIZE_PUSH
2927
#pragma pop_macro("BOOST_MPL_LIMIT_VECTOR_SIZE")
30-
#endif
31-
32-
#ifdef BOOST_MPL_LIMIT_LIST_SIZE_PUSH
33-
#pragma pop_macro("BOOST_MPL_LIMIT_LIST_SIZE")
28+
#else
29+
#include <boost/property_tree/ptree.hpp>
3430
#endif
3531

3632
#include "boost/assign.hpp"
@@ -271,10 +267,13 @@ public:
271267
}
272268
catch(const boost::property_tree::ptree_error &e)
273269
{
274-
DYNAMIC_GRAPH_ENTITY_ERROR(*this) << "Robot utils: parameter path is invalid " << '\n'
270+
std::ostringstream oss;
271+
oss << "Robot utils: parameter path is invalid " << '\n'
275272
<< " for set_parameter("
276273
<< parameter_name << ")\n"
277-
<< e.what() << '\n';
274+
<< e.what() << std::endl;
275+
sendMsg(oss.str(),
276+
MSG_TYPE_ERROR);
278277
return;
279278

280279
}
@@ -298,10 +297,13 @@ public:
298297
}
299298
catch(const boost::property_tree::ptree_error &e)
300299
{
301-
DYNAMIC_GRAPH_ENTITY_ERROR(*this) << "Robot utils: parameter path is invalid " << '\n'
300+
std::ostringstream oss;
301+
oss << "Robot utils: parameter path is invalid " << '\n'
302302
<< " for get_parameter("
303303
<< parameter_name << ")\n"
304-
<< e.what() << '\n';
304+
<< e.what() << std::endl;
305+
sendMsg(oss.str(),
306+
MSG_TYPE_ERROR);
305307
}
306308
}
307309
/** @} */

src/tools/parameter-server.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,21 @@
1414
* with sot-torque-control. If not, see <http://www.gnu.org/licenses/>.
1515
*/
1616

17+
/** pinocchio is forcing the BOOST_MPL_LIMIT_VECTOR_SIZE to a specific value.
18+
This happen to be not working when including the boost property_tree library.
19+
For this reason if defined, the current value of BOOST_MPL_LIMIT_VECTOR_SIZE
20+
is saved in the preprocessor stack and unset.
21+
Once the property_tree included the pinocchio value of this variable is
22+
restored.
23+
*/
24+
1725
#ifdef BOOST_MPL_LIMIT_VECTOR_SIZE
1826
#pragma push_macro("BOOST_MPL_LIMIT_VECTOR_SIZE")
1927
#undef BOOST_MPL_LIMIT_VECTOR_SIZE
20-
#define BOOST_MPL_LIMIT_VECTOR_SIZE_PUSH
21-
#endif
22-
23-
#ifdef BOOST_MPL_LIMIT_LIST_SIZE
24-
#pragma push_macro("BOOST_MPL_LIMIT_LIST_SIZE")
25-
#undef BOOST_MPL_LIMIT_LIST_SIZE
26-
#define BOOST_MPL_LIMIT_LIST_SIZE_PUSH
27-
#endif
28-
2928
#include <boost/property_tree/ptree.hpp>
30-
31-
#ifdef BOOST_MPL_LIMIT_VECTOR_SIZE_PUSH
3229
#pragma pop_macro("BOOST_MPL_LIMIT_VECTOR_SIZE")
33-
#endif
34-
35-
#ifdef BOOST_MPL_LIMIT_LIST_SIZE_PUSH
36-
#pragma pop_macro("BOOST_MPL_LIMIT_LIST_SIZE")
30+
#else
31+
#include <boost/property_tree/ptree.hpp>
3732
#endif
3833

3934
#include <dynamic-graph/all-commands.h>

src/tools/robot-utils.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
*
66
*/
77

8+
/** pinocchio is forcing the BOOST_MPL_LIMIT_VECTOR_SIZE to a specific value.
9+
This happen to be not working when including the boost property_tree library.
10+
For this reason if defined, the current value of BOOST_MPL_LIMIT_VECTOR_SIZE
11+
is saved in the preprocessor stack and unset.
12+
Once the property_tree included the pinocchio value of this variable is
13+
restored.
14+
*/
815
#ifdef BOOST_MPL_LIMIT_VECTOR_SIZE
916
#pragma push_macro("BOOST_MPL_LIMIT_VECTOR_SIZE")
1017
#undef BOOST_MPL_LIMIT_VECTOR_SIZE
@@ -40,7 +47,9 @@ RobotUtilShrPtr RefVoidRobotUtil() {
4047
ExtractJointMimics::ExtractJointMimics(std::string & robot_model) {
4148
// Parsing the model from a string.
4249
std::istringstream iss(robot_model);
50+
/// Read the XML file in the property tree.
4351
boost::property_tree::read_xml(iss,tree_);
52+
/// Start the recursive parsing.
4453
go_through_full();
4554
}
4655

@@ -50,40 +59,56 @@ ExtractJointMimics::get_mimic_joints() {
5059
}
5160

5261
void ExtractJointMimics::go_through_full() {
62+
/// Root of the recursive parsing.
5363
current_joint_name_="";
5464
go_through(tree_,0,0);
5565
}
5666

5767
void ExtractJointMimics::go_through(pt::ptree &pt, int level, int stage)
5868
{
69+
/// If pt is empty (i.e. this is a leaf)
5970
if (pt.empty()) {
71+
/// and this is a name of a joint (stage == 3) update the
72+
/// curret_joint_name_ variable.
6073
if (stage==3)
6174
current_joint_name_=pt.data();
6275
}
6376
else {
6477

78+
/// This is not a leaf
6579
for (auto pos : pt) {
6680
int new_stage = stage;
6781

82+
/// But this is joint
6883
if (pos.first=="joint")
84+
/// the continue the exploration.
6985
new_stage=1;
7086
else if (pos.first=="<xmlattr>")
7187
{
88+
/// we are exploring the xml attributes of a joint
89+
/// -> continue the exploration
7290
if (stage==1)
7391
new_stage=2;
7492
}
93+
/// The xml attribute of the joint is the name
94+
/// next leaf is the name we are possibly looking for
7595
else if (pos.first=="name")
7696
{
7797
if (stage==2)
7898
new_stage=3;
7999
}
100+
/// The exploration of the tree tracback on the joint
101+
/// and find that this is a mimic joint.
80102
else if (pos.first=="mimic")
81103
{
82104
if (stage==1)
105+
/// Save the current name of the joint
106+
/// in mimic_joints.
83107
mimic_joints_.push_back(current_joint_name_);
84108
}
85109
else new_stage=0;
86110

111+
/// Explore the subtree of the XML robot description.
87112
go_through(pos.second, level + 1,new_stage);
88113

89114
}

0 commit comments

Comments
 (0)