TestBotaDriverFTOffsets.cpp
Go to the documentation of this file.
1 
7 #include <gtest/gtest.h>
8 
9 #include <geometry_msgs/WrenchStamped.h>
10 #include <geometry_msgs/Wrench.h>
11 #include <ros/ros.h>
12 #include <Eigen/Dense>
13 
14 using namespace Eigen;
15 namespace bota_driver_testing
16 {
17 class BotaDriverTestFTOffsets : public ::testing::Test
18 {
19 protected:
21  ros::NodeHandle nh_{ "~" };
22  std::uint32_t msgCount_;
23  geometry_msgs::Wrench meanWrenchOffset_;
24  std::string topicName_;
26  VectorXd fxSamples_;
27  VectorXd fySamples_;
28  VectorXd fzSamples_;
29  VectorXd txSamples_;
30  VectorXd tySamples_;
31  VectorXd tzSamples_;
32 
33  BotaDriverTestFTOffsets() : msgCount_(0)
34  {
35  }
36 
38  {
39  // You can do clean-up work that doesn't throw exceptions here.
40  }
41 
42  // If the constructor and destructor are not enough for setting up
43  // and cleaning up each test, you can define the following methods:
44 
45  void SetUp() override
46  {
47  // Code here will be called immediately after the constructor (right
48  // before each test).
49  }
50 
51  void TearDown() override
52  {
53  // Code here will be called immediately after each test (right
54  // before the destructor).
55  }
56 
57 public:
58  void meanwrenchCallback(const geometry_msgs::WrenchStamped::ConstPtr& msg)
59  {
60  std::uint32_t lpos = msgCount_;
61  msgCount_++;
62  fxSamples_.conservativeResize(msgCount_);
63  fySamples_.conservativeResize(msgCount_);
64  fzSamples_.conservativeResize(msgCount_);
65  txSamples_.conservativeResize(msgCount_);
66  tySamples_.conservativeResize(msgCount_);
67  tzSamples_.conservativeResize(msgCount_);
68 
69  fxSamples_(lpos) = msg->wrench.force.x;
70  fySamples_(lpos) = msg->wrench.force.y;
71  fzSamples_(lpos) = msg->wrench.force.z;
72  txSamples_(lpos) = msg->wrench.torque.x;
73  tySamples_(lpos) = msg->wrench.torque.y;
74  tzSamples_(lpos) = msg->wrench.torque.z;
75  }
76 };
77 
79 {
80  SCOPED_TRACE("SetFTOffsets");
81  ros::Time time_offset;
82  ASSERT_EQ(nh_.getParam("topic_name", topicName_), true);
83  sub_ = nh_.subscribe(topicName_, 1000, &BotaDriverTestFTOffsets::meanwrenchCallback, (BotaDriverTestFTOffsets*)this);
84  ASSERT_EQ(nh_.getParam("test_duration", testDuration_), true);
85  time_offset = ros::Time::now() + ros::Duration(testDuration_);
86  while (ros::ok() && ros::Time::now() < time_offset)
87  {
88  ros::spinOnce();
89  if (HasFatalFailure())
90  {
91  FAIL() << "Fatal errors occurred.\n";
92  return;
93  }
94  }
95  EXPECT_GT(msgCount_, 0U);
96  meanWrenchOffset_.force.x = fxSamples_.mean();
97  meanWrenchOffset_.force.y = fySamples_.mean();
98  meanWrenchOffset_.force.z = fzSamples_.mean();
99  meanWrenchOffset_.torque.x = txSamples_.mean();
100  meanWrenchOffset_.torque.y = tySamples_.mean();
101  meanWrenchOffset_.torque.z = tzSamples_.mean();
102  ASSERT_NEAR(meanWrenchOffset_.force.x, 10000.0, 1000);
103  ASSERT_NEAR(meanWrenchOffset_.force.y, -10000.0, 1000);
104  ASSERT_NEAR(meanWrenchOffset_.force.z, 20000.0, 1000);
105  ASSERT_NEAR(meanWrenchOffset_.torque.x, -20000.0, 100);
106  ASSERT_NEAR(meanWrenchOffset_.torque.y, 30000.0, 100);
107  ASSERT_NEAR(meanWrenchOffset_.torque.z, -30000.0, 100);
108 }
109 
110 } // namespace bota_driver_testing
bota_driver_testing
Tests Command.
Definition: TestBotaDriverBoot.cpp:15
msg
msg
ros.h
bota_driver_testing::BotaDriverTestFTOffsets
Definition: TestBotaDriverFTOffsets.cpp:17
bota_driver_testing::BotaDriverTestFTOffsets::txSamples_
VectorXd txSamples_
Definition: TestBotaDriverFTOffsets.cpp:29
bota_driver_testing::BotaDriverTestFTOffsets::~BotaDriverTestFTOffsets
~BotaDriverTestFTOffsets() override
Definition: TestBotaDriverFTOffsets.cpp:37
ros::spinOnce
ROSCPP_DECL void spinOnce()
bota_driver_testing::BotaDriverTestFTOffsets::tySamples_
VectorXd tySamples_
Definition: TestBotaDriverFTOffsets.cpp:30
bota_driver_testing::BotaDriverTestFTOffsets::tzSamples_
VectorXd tzSamples_
Definition: TestBotaDriverFTOffsets.cpp:31
ros::ok
ROSCPP_DECL bool ok()
bota_driver_testing::BotaDriverTestFTOffsets::TearDown
void TearDown() override
Definition: TestBotaDriverFTOffsets.cpp:51
bota_driver_testing::BotaDriverTestFTOffsets::fxSamples_
VectorXd fxSamples_
Definition: TestBotaDriverFTOffsets.cpp:26
bota_driver_testing::BotaDriverTestFTOffsets::topicName_
std::string topicName_
Definition: TestBotaDriverFTOffsets.cpp:24
bota_driver_testing::BotaDriverTestFTOffsets::SetUp
void SetUp() override
Definition: TestBotaDriverFTOffsets.cpp:45
bota_driver_testing::TEST_F
TEST_F(BotaDriverTestFTOffsets, SetFTOffsets)
Definition: TestBotaDriverFTOffsets.cpp:78
bota_driver_testing::BotaDriverTestFTOffsets::meanwrenchCallback
void meanwrenchCallback(const geometry_msgs::WrenchStamped::ConstPtr &msg)
Definition: TestBotaDriverFTOffsets.cpp:58
bota_driver_testing::BotaDriverTestFTOffsets::sub_
ros::Subscriber sub_
Definition: TestBotaDriverFTOffsets.cpp:20
bota_driver_testing::BotaDriverTestFTOffsets::fzSamples_
VectorXd fzSamples_
Definition: TestBotaDriverFTOffsets.cpp:28
ros::Time
bota_driver_testing::BotaDriverTestFTOffsets::meanWrenchOffset_
geometry_msgs::Wrench meanWrenchOffset_
Definition: TestBotaDriverFTOffsets.cpp:23
bota_driver_testing::BotaDriverTestFTOffsets::fySamples_
VectorXd fySamples_
Definition: TestBotaDriverFTOffsets.cpp:27
bota_driver_testing::BotaDriverTestFTOffsets::msgCount_
std::uint32_t msgCount_
Definition: TestBotaDriverFTOffsets.cpp:22
bota_driver_testing::BotaDriverTestFTOffsets::testDuration_
float testDuration_
Definition: TestBotaDriverFTOffsets.cpp:25
bota_driver_testing::BotaDriverTestFTOffsets::BotaDriverTestFTOffsets
BotaDriverTestFTOffsets()
Definition: TestBotaDriverFTOffsets.cpp:33
ros::Duration
ros::NodeHandle
ros::Subscriber
ros::Time::now
static Time now()


bota_driver_testing
Author(s):
autogenerated on Sat Apr 15 2023 02:54:01