diff_drive_nan_test.cpp
Go to the documentation of this file.
1 // Copyright (C) 2014, 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 
32 // NaN
33 #include <limits>
34 
35 // TEST CASES
37  // wait for ROS
38  while (!isControllerAlive()) {
39  ros::Duration(0.1).sleep();
40  }
41  // zero everything before test
42  geometry_msgs::Twist cmd_vel;
43  cmd_vel.linear.x = 0.0;
44  cmd_vel.angular.z = 0.0;
45  publish(cmd_vel);
46  ros::Duration(2.0).sleep();
47 
48  // send a command
49  cmd_vel.linear.x = 0.1;
50  ros::Duration(2.0).sleep();
51 
52  // stop robot (will generate NaN)
53  stop();
54  ros::Duration(2.0).sleep();
55 
56  nav_msgs::Odometry odom = getLastOdom();
57 
58  EXPECT_FALSE(std::isnan(odom.twist.twist.linear.x));
59  EXPECT_FALSE(std::isnan(odom.twist.twist.angular.z));
60  EXPECT_FALSE(std::isnan(odom.pose.pose.position.x));
61  EXPECT_FALSE(std::isnan(odom.pose.pose.position.y));
62  EXPECT_FALSE(std::isnan(odom.pose.pose.orientation.z));
63  EXPECT_FALSE(std::isnan(odom.pose.pose.orientation.w));
64 
65  // start robot
66  start();
67  ros::Duration(2.0).sleep();
68 
69  odom = getLastOdom();
70 
71  EXPECT_FALSE(std::isnan(odom.twist.twist.linear.x));
72  EXPECT_FALSE(std::isnan(odom.twist.twist.angular.z));
73  EXPECT_FALSE(std::isnan(odom.pose.pose.position.x));
74  EXPECT_FALSE(std::isnan(odom.pose.pose.position.y));
75  EXPECT_FALSE(std::isnan(odom.pose.pose.orientation.z));
76  EXPECT_FALSE(std::isnan(odom.pose.pose.orientation.w));
77 }
78 
80  // wait for ROS
81  while (!isControllerAlive()) {
82  ros::Duration(0.1).sleep();
83  }
84  // zero everything before test
85  geometry_msgs::Twist cmd_vel;
86  cmd_vel.linear.x = 0.0;
87  cmd_vel.angular.z = 0.0;
88  publish(cmd_vel);
89  ros::Duration(0.1).sleep();
90 
91  // send NaN
92  for (int i = 0; i < 10; ++i) {
93  geometry_msgs::Twist cmd_vel;
94  cmd_vel.linear.x = NAN;
95  cmd_vel.angular.z = NAN;
96  publish(cmd_vel);
97  geometry_msgs::TwistStamped odom_msg = getLastCmdVelOut();
98  EXPECT_FALSE(std::isnan(odom_msg.twist.linear.x));
99  EXPECT_FALSE(std::isnan(odom_msg.twist.angular.z));
100  ros::Duration(0.1).sleep();
101  }
102 
103  nav_msgs::Odometry odom = getLastOdom();
104  EXPECT_DOUBLE_EQ(odom.twist.twist.linear.x, 0.0);
105  EXPECT_DOUBLE_EQ(odom.pose.pose.position.x, 0.0);
106  EXPECT_DOUBLE_EQ(odom.pose.pose.position.y, 0.0);
107 
108  geometry_msgs::TwistStamped odom_msg = getLastCmdVelOut();
109  EXPECT_DOUBLE_EQ(odom_msg.twist.linear.x, 0.0);
110 }
111 
112 int main(int argc, char **argv) {
113  testing::InitGoogleTest(&argc, argv);
114  ros::init(argc, argv, "diff_drive_nan_test");
115 
117  spinner.start();
118  int ret = RUN_ALL_TESTS();
119  spinner.stop();
120  ros::shutdown();
121  return ret;
122 }
TEST_F(DiffDriveControllerTest, testNaN)
ROSCPP_DECL void start()
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void spinner()
int main(int argc, char **argv)
ROSCPP_DECL void shutdown()
bool sleep() const


diff_drive_controller
Author(s): Bence Magyar
autogenerated on Fri Feb 3 2023 03:19:01