diff_drive_dyn_reconf_test.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018, PAL Robotics S.L.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of PAL Robotics, Inc. nor the names of its
12 // contributors may be used to endorse or promote products derived from
13 // this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 // POSSIBILITY OF SUCH DAMAGE.
27 
29 
30 #include "test_common.h"
31 #include <tf/transform_listener.h>
32 
33 #include <dynamic_reconfigure/server.h>
34 
35 // TEST CASES
36 TEST_F(DiffDriveControllerTest, testDynReconfServerAlive)
37 {
38  // wait for ROS
39  waitForController();
40 
41  // Expect server is alive
42  EXPECT_TRUE(ros::service::exists("diffbot_controller/set_parameters", true));
43 
44  dynamic_reconfigure::ReconfigureRequest srv_req;
45  dynamic_reconfigure::ReconfigureResponse srv_resp;
46 
47  // Expect server is callable (get-fashion)
48  EXPECT_TRUE(ros::service::call("diffbot_controller/set_parameters", srv_req, srv_resp));
49 
50  EXPECT_EQ(1, srv_resp.config.bools.size());
51 
52  if (!srv_resp.config.bools.empty())
53  {
54  EXPECT_EQ("enable_odom_tf", srv_resp.config.bools[0].name);
55  // expect false since it is set to false in the .test
56  EXPECT_EQ(false, srv_resp.config.bools[0].value);
57  }
58 
59  EXPECT_EQ(4, srv_resp.config.doubles.size());
60 
61  if (srv_resp.config.doubles.size() >= 4)
62  {
63  EXPECT_EQ("left_wheel_radius_multiplier", srv_resp.config.doubles[0].name);
64  EXPECT_EQ(1, srv_resp.config.doubles[0].value);
65 
66  EXPECT_EQ("right_wheel_radius_multiplier", srv_resp.config.doubles[1].name);
67  EXPECT_EQ(1, srv_resp.config.doubles[1].value);
68 
69  EXPECT_EQ("wheel_separation_multiplier", srv_resp.config.doubles[2].name);
70  EXPECT_EQ(1, srv_resp.config.doubles[2].value);
71 
72  EXPECT_EQ("publish_rate", srv_resp.config.doubles[3].name);
73  EXPECT_EQ(50, srv_resp.config.doubles[3].value);
74  }
75 
76  dynamic_reconfigure::DoubleParameter double_param;
77  double_param.name = "left_wheel_radius_multiplier";
78  double_param.value = 0.95;
79 
80  srv_req.config.doubles.push_back(double_param);
81 
82  double_param.name = "right_wheel_radius_multiplier";
83  double_param.value = 0.95;
84 
85  srv_req.config.doubles.push_back(double_param);
86 
87  double_param.name = "wheel_separation_multiplier";
88  double_param.value = 0.95;
89 
90  srv_req.config.doubles.push_back(double_param);
91 
92  double_param.name = "publish_rate";
93  double_param.value = 150;
94 
95  srv_req.config.doubles.push_back(double_param);
96 
97  dynamic_reconfigure::BoolParameter bool_param;
98  bool_param.name = "enable_odom_tf";
99  bool_param.value = false;
100 
101  srv_req.config.bools.push_back(bool_param);
102 
103  // Expect server is callable (set-fashion)
104  EXPECT_TRUE(ros::service::call("diffbot_controller/set_parameters", srv_req, srv_resp));
105 
106  EXPECT_EQ(1, srv_resp.config.bools.size());
107 
108  if (!srv_resp.config.bools.empty())
109  {
110  EXPECT_EQ("enable_odom_tf", srv_resp.config.bools[0].name);
111  EXPECT_EQ(false, srv_resp.config.bools[0].value);
112  }
113 
114  EXPECT_EQ(4, srv_resp.config.doubles.size());
115 
116  if (srv_resp.config.doubles.size() >= 4)
117  {
118  EXPECT_EQ("left_wheel_radius_multiplier", srv_resp.config.doubles[0].name);
119  EXPECT_EQ(0.95, srv_resp.config.doubles[0].value);
120 
121  EXPECT_EQ("right_wheel_radius_multiplier", srv_resp.config.doubles[1].name);
122  EXPECT_EQ(0.95, srv_resp.config.doubles[1].value);
123 
124  EXPECT_EQ("wheel_separation_multiplier", srv_resp.config.doubles[2].name);
125  EXPECT_EQ(0.95, srv_resp.config.doubles[2].value);
126 
127  EXPECT_EQ("publish_rate", srv_resp.config.doubles[3].name);
128  EXPECT_EQ(150, srv_resp.config.doubles[3].value);
129  }
130 }
131 
132 // TEST CASES
133 TEST_F(DiffDriveControllerTest, testDynReconfEnableTf)
134 {
135  // wait for ROS
136  while(!isControllerAlive() && ros::ok())
137  {
138  ros::Duration(0.1).sleep();
139  }
140  if (!ros::ok())
141  FAIL() << "Something went wrong while executing test";
142 
143  // set up tf listener
144  tf::TransformListener listener;
145  ros::Duration(2.0).sleep();
146  // check the odom frame doesn't exist
147  EXPECT_FALSE(listener.frameExists("odom"));
148 
149  dynamic_reconfigure::ReconfigureRequest srv_req;
150  dynamic_reconfigure::ReconfigureResponse srv_resp;
151 
152  dynamic_reconfigure::BoolParameter bool_param;
153  bool_param.name = "enable_odom_tf";
154  bool_param.value = true;
155 
156  srv_req.config.bools.push_back(bool_param);
157 
158  EXPECT_TRUE(ros::service::call("diffbot_controller/set_parameters", srv_req, srv_resp));
159 
160  ros::Duration(2.0).sleep();
161  // check the odom frame doesn't exist
162  EXPECT_TRUE(listener.frameExists("odom"));
163 }
164 
165 int main(int argc, char** argv)
166 {
167  testing::InitGoogleTest(&argc, argv);
168  ros::init(argc, argv, "diff_drive_dyn_reconf_test");
169 
171  spinner.start();
172  int ret = RUN_ALL_TESTS();
173  spinner.stop();
174  ros::shutdown();
175  return ret;
176 }
ros::service::exists
ROSCPP_DECL bool exists(const std::string &service_name, bool print_failure_reason)
ros::service::call
bool call(const std::string &service_name, MReq &req, MRes &res)
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
test_common.h
ros::AsyncSpinner
ros::shutdown
ROSCPP_DECL void shutdown()
main
int main(int argc, char **argv)
Definition: diff_drive_dyn_reconf_test.cpp:165
ros::ok
ROSCPP_DECL bool ok()
spinner
void spinner()
TEST_F
TEST_F(DiffDriveControllerTest, testDynReconfServerAlive)
Definition: diff_drive_dyn_reconf_test.cpp:36
DiffDriveControllerTest
Definition: test_common.h:54
transform_listener.h
tf::Transformer::frameExists
bool frameExists(const std::string &frame_id_str) const
tf::TransformListener
ros::Duration::sleep
bool sleep() const
ros::Duration


diff_drive_controller
Author(s): Bence Magyar
autogenerated on Fri May 24 2024 02:41:04