TestBotaDriverSignalQuality.cpp
Go to the documentation of this file.
1 
7 #include <gtest/gtest.h>
8 #include <geometry_msgs/WrenchStamped.h>
9 #include <geometry_msgs/Wrench.h>
10 #include <Eigen/Dense>
11 #include <ros/ros.h>
12 
13 #define ASSERT_DOUBLE_NOT_NEAR(val1, val2, abs_error) \
14  ASSERT_PRED_FORMAT3(!::testing::internal::DoubleNearPredFormat, val1, val2, abs_error)
15 
16 using namespace Eigen;
17 
18 namespace bota_driver_testing
19 {
20 class BotaDriverSignalQuality : public ::testing::Test
21 {
22 protected:
24  ros::NodeHandle nh_{ "~" };
25  std::uint32_t msgCount_;
26  std::uint32_t maxCount_;
27  std::string topicName_;
28  VectorXd fxSamples_;
29  VectorXd fySamples_;
30  VectorXd fzSamples_;
31  VectorXd txSamples_;
32  VectorXd tySamples_;
33  VectorXd tzSamples_;
35 
36  BotaDriverSignalQuality() : msgCount_(0), maxCount_(1000)
37  {
38  }
39 
41  {
42  // You can do clean-up work that doesn't throw exceptions here.
43  }
44 
45  // If the constructor and destructor are not enough for setting up
46  // and cleaning up each test, you can define the following methods:
47 
48  void SetUp() override
49  {
50  // Code here will be called immediately after the constructor (right
51  // before each test).
52  }
53 
54  void TearDown() override
55  {
56  // Code here will be called immediately after each test (right
57  // before the destructor).
58  }
59 
60 public:
61  void wrenchCallback(const geometry_msgs::WrenchStamped::ConstPtr& msg)
62  {
63  std::uint32_t lpos = msgCount_;
64  msgCount_++;
65  fxSamples_.conservativeResize(msgCount_);
66  fySamples_.conservativeResize(msgCount_);
67  fzSamples_.conservativeResize(msgCount_);
68  txSamples_.conservativeResize(msgCount_);
69  tySamples_.conservativeResize(msgCount_);
70  tzSamples_.conservativeResize(msgCount_);
71 
72  fxSamples_(lpos) = msg->wrench.force.x;
73  fySamples_(lpos) = msg->wrench.force.y;
74  fzSamples_(lpos) = msg->wrench.force.z;
75  txSamples_(lpos) = msg->wrench.torque.x;
76  tySamples_(lpos) = msg->wrench.torque.y;
77  tzSamples_(lpos) = msg->wrench.torque.z;
78  }
79 };
80 
82 {
83  SCOPED_TRACE("SignalQualityFT");
84  ros::Time time_offset;
85  ASSERT_EQ(nh_.getParam("topic_name", topicName_), true);
86  sub_ = nh_.subscribe(topicName_, 1, &BotaDriverSignalQuality::wrenchCallback, (BotaDriverSignalQuality*)this,
87  ros::TransportHints().tcpNoDelay());
88  ASSERT_EQ(nh_.getParam("test_duration", testDuration_), true);
89  time_offset = ros::Time::now() + ros::Duration(testDuration_);
90  while (ros::ok() && ros::Time::now() < time_offset && msgCount_ < maxCount_)
91  {
92  ros::spinOnce();
93  if (HasFatalFailure())
94  {
95  FAIL() << "Fatal errors occurred.\n";
96  return;
97  }
98  }
99 
100  EXPECT_GT(msgCount_, 0U);
101  fxSamples_ = fxSamples_.array() - fxSamples_.mean();
102  double sigma_fx = std::sqrt(fxSamples_.squaredNorm() / msgCount_);
103  fySamples_ = fySamples_.array() - fySamples_.mean();
104  double sigma_fy = std::sqrt(fySamples_.squaredNorm() / msgCount_);
105  fzSamples_ = fzSamples_.array() - fzSamples_.mean();
106  double sigma_fz = std::sqrt(fzSamples_.squaredNorm() / msgCount_);
107  txSamples_ = txSamples_.array() - txSamples_.mean();
108  double sigma_tx = std::sqrt(txSamples_.squaredNorm() / msgCount_);
109  tySamples_ = tySamples_.array() - tySamples_.mean();
110  double sigma_ty = std::sqrt(tySamples_.squaredNorm() / msgCount_);
111  tzSamples_ = tzSamples_.array() - tzSamples_.mean();
112  double sigma_tz = std::sqrt(tzSamples_.squaredNorm() / msgCount_);
113 
114  double max_sigma_fxy, max_sigma_fz, max_sigma_txy, max_sigma_tz;
115  ASSERT_EQ(nh_.getParam("max_sigma_fxy", max_sigma_fxy), true);
116  ASSERT_EQ(nh_.getParam("max_sigma_fz", max_sigma_fz), true);
117  ASSERT_EQ(nh_.getParam("max_sigma_txy", max_sigma_txy), true);
118  ASSERT_EQ(nh_.getParam("max_sigma_tz", max_sigma_tz), true);
119  // Compute standard deviation of the signal.
120  ASSERT_GT(sigma_fx, 1e-7);
121  ASSERT_GT(sigma_fy, 1e-7);
122  ASSERT_GT(sigma_fz, 1e-7);
123  ASSERT_GT(sigma_tx, 1e-7);
124  ASSERT_GT(sigma_ty, 1e-7);
125  ASSERT_GT(sigma_tz, 1e-7);
126  ASSERT_LT(sigma_fx, max_sigma_fxy);
127  ASSERT_LT(sigma_fy, max_sigma_fxy);
128  ASSERT_LT(sigma_fz, max_sigma_fz);
129  ASSERT_LT(sigma_tx, max_sigma_txy);
130  ASSERT_LT(sigma_ty, max_sigma_txy);
131  ASSERT_LT(sigma_tz, max_sigma_tz);
132 }
133 
134 } // namespace bota_driver_testing
Tests Command.
TEST_F(BotaDriverSignalQuality, SignalQuality)
ROSCPP_DECL bool ok()
static Time now()
void wrenchCallback(const geometry_msgs::WrenchStamped::ConstPtr &msg)
ROSCPP_DECL void spinOnce()


bota_driver_testing
Author(s):
autogenerated on Sat Apr 15 2023 02:51:37