calibration_offset_parser_tests.cpp
Go to the documentation of this file.
1 #include <boost/algorithm/string.hpp>
2 #include <urdf/model.h>
4 #include <robot_calibration/models/chain.h> // for rotation functions
5 #include <gtest/gtest.h>
6 
7 std::string robot_description =
8 "<?xml version='1.0' ?>"
9 "<robot name='test'>"
10 " <link name='link_0'/>"
11 " <joint name='first_joint' type='fixed'>"
12 " <origin rpy='0 0 0' xyz='1 1 1'/>"
13 " <parent link='link_0'/>"
14 " <child link='link_1'/>"
15 " </joint>"
16 " <link name='link_1'/>"
17 " <joint name='second_joint' type='revolute'>"
18 " <origin rpy='0 0 0' xyz='0 0 0'/>"
19 " <axis xyz='0 0 1'/>"
20 " <limit effort='30' lower='-1.57' upper='1.57' velocity='0.524'/>"
21 " <parent link='link_1'/>"
22 " <child link='link_2'/>"
23 " </joint>"
24 " <link name='link_2'/>"
25 " <joint name='third_joint' type='fixed'>"
26 " <origin rpy='0 -1.5 0' xyz='0 0 0.0526'/>"
27 " <parent link='link_2'/>"
28 " <child link='link_3'/>"
29 " </joint>"
30 " <link name='link_3'/>"
31 "</robot>";
32 
34 "<?xml version=\"1.0\" ?>\n"
35 "<robot name=\"test\">\n"
36 " <link name=\"link_0\" />\n"
37 " <joint name=\"first_joint\" type=\"fixed\">\n"
38 " <origin rpy=\"0 0 0\" xyz=\"1 1 1\" />\n"
39 " <parent link=\"link_0\" />\n"
40 " <child link=\"link_1\" />\n"
41 " </joint>\n"
42 " <link name=\"link_1\" />\n"
43 " <joint name=\"second_joint\" type=\"revolute\">\n"
44 " <origin rpy=\"0 0 0\" xyz=\"0 0 0\" />\n"
45 " <axis xyz=\"0 0 1\" />\n"
46 " <limit effort=\"30\" lower=\"-1.57\" upper=\"1.57\" velocity=\"0.524\" />\n"
47 " <parent link=\"link_1\" />\n"
48 " <child link=\"link_2\" />\n"
49 " <calibration rising=\"0.245\" />\n"
50 " </joint>\n"
51 " <link name=\"link_2\" />\n"
52 " <joint name=\"third_joint\" type=\"fixed\">\n"
53 " <origin rpy=\"1.57000000 -1.50000000 0.00000000\" xyz=\"0.00000000 0.00000000 0.05260000\" />\n"
54 " <parent link=\"link_2\" />\n"
55 " <child link=\"link_3\" />\n"
56 " </joint>\n"
57 " <link name=\"link_3\" />\n"
58 "</robot>";
59 
60 TEST(CalibrationOffsetParserTests, test_urdf_update)
61 {
63 
64  p.add("second_joint");
65  p.addFrame("third_joint", true, true, true, true, true, true);
66 
67  double params[7] = {0.245, 0, 0, 0, 0, 0, 0};
68 
69  // set angles
70  KDL::Rotation r = KDL::Rotation::RPY(1.57, 0, 0);
71  robot_calibration::axis_magnitude_from_rotation(r, params[4], params[5], params[6]);
72 
73  p.update(params);
74 
75  std::string s = p.updateURDF(robot_description);
76 
77  // google test fails if we give it all of robot_description_updated, so break this up
78  std::vector<std::string> s_pieces;
79  std::vector<std::string> robot_pieces;
80 
81  boost::split(s_pieces, s, boost::is_any_of("\n"));
82  boost::split(robot_pieces, robot_description_updated, boost::is_any_of("\n"));
83 
84  for (size_t i = 0; i < robot_pieces.size(); ++i)
85  {
86  ASSERT_STREQ(robot_pieces[i].c_str(), s_pieces[i].c_str());
87  }
88 }
89 
90 TEST(CalibrationOffsetParserTests, test_multi_step)
91 {
93 
94  p.add("first_step_joint1");
95  p.add("first_step_joint2");
96 
97  double params[2] = {0.245, 0.44};
98  p.update(params);
99 
100  EXPECT_EQ(0.245, p.get("first_step_joint1"));
101  EXPECT_EQ(0.44, p.get("first_step_joint2"));
102  EXPECT_EQ((size_t) 2, p.size());
103 
104  // Reset num of free params
105  p.reset();
106  EXPECT_EQ((size_t) 0, p.size());
107 
108  // Add a new one for second step
109  p.add("second_step_joint1");
110  EXPECT_EQ((size_t) 1, p.size());
111 
112  params[0] *= 2.0;
113  p.update(params);
114 
115  EXPECT_EQ(0.245, p.get("first_step_joint1"));
116  EXPECT_EQ(0.44, p.get("first_step_joint2"));
117  EXPECT_EQ(0.49, p.get("second_step_joint1"));
118 
119  // Reset num of free params
120  p.reset();
121  EXPECT_EQ((size_t) 0, p.size());
122 
123  // Reuse a param for a third step
124  p.add("first_step_joint1");
125  EXPECT_EQ((size_t) 1, p.size());
126 
127  params[0] *= 2.0;
128  p.update(params);
129 
130  EXPECT_EQ(0.98, p.get("first_step_joint1"));
131  EXPECT_EQ(0.44, p.get("first_step_joint2"));
132  EXPECT_EQ(0.49, p.get("second_step_joint1"));
133 }
134 
135 int main(int argc, char** argv)
136 {
137  testing::InitGoogleTest(&argc, argv);
138  return RUN_ALL_TESTS();
139 }
std::string robot_description_updated
std::string robot_description
XmlRpcServer s
Combined parser and configuration for calibration offsets. Holds the configuration of what is to be c...
bool add(const std::string name)
Tell the parser we wish to calibrate an active joint or other single parameter.
static Rotation RPY(double roll, double pitch, double yaw)
double get(const std::string name) const
Get the offset.
void axis_magnitude_from_rotation(const KDL::Rotation &r, double &x, double &y, double &z)
Converts from KDL::Rotation to angle-axis-with-integrated-magnitude.
Definition: models.cpp:261
bool addFrame(const std::string name, bool calibrate_x, bool calibrate_y, bool calibrate_z, bool calibrate_roll, bool calibrate_pitch, bool calibrate_yaw)
Tell the parser we wish to calibrate a fixed joint.
std::string updateURDF(const std::string &urdf)
Update the urdf with the new offsets.
bool reset()
Clear free parameters, but retain values for multi-step calirations.
TEST(CalibrationOffsetParserTests, test_urdf_update)
int main(int argc, char **argv)
bool update(const double *const free_params)
Update the offsets based on free_params from ceres-solver.


robot_calibration
Author(s): Michael Ferguson
autogenerated on Tue Nov 3 2020 17:30:30