hand_commander_test.cpp
Go to the documentation of this file.
1 
24 // We are testing this
26 
27 #include <utility>
28 #include <string>
29 #include <vector>
30 
31 // ROS
32 #include "ros/ros.h"
33 
34 // Gtest
35 #include <gtest/gtest.h>
36 
38 
39 TEST(HandCommander, constructor)
40 {
41  HandCommander handcmd = HandCommander();
42  EXPECT_TRUE(true);
43 }
44 
45 TEST(HandCommander, topic_state)
46 {
47  HandCommander handcmd = HandCommander();
48 
49  // get_controller_state_topic returns fully resolved topics
50  ros::NodeHandle nh;
51 
52  std::string topic = handcmd.get_controller_state_topic("rh_FFJ3");
53  EXPECT_EQ(nh.resolveName("sh_rh_ffj3_position_controller/state"), topic);
54 
55  topic = handcmd.get_controller_state_topic("rh_FFJ0");
56  EXPECT_EQ(nh.resolveName("sh_rh_ffj0_position_controller/state"), topic);
57 
58  topic = handcmd.get_controller_state_topic("unknown joint");
59  EXPECT_EQ("", topic);
60 }
61 
63 {
64  HandCommander handcmd = HandCommander();
65 
66  std::pair<double, double> min_max = handcmd.get_min_max("rh_FFJ3");
67  EXPECT_DOUBLE_EQ(min_max.first, 0.0);
68  EXPECT_DOUBLE_EQ(min_max.second, 1.57079632679);
69 
70  // also works for lower case
71  min_max = handcmd.get_min_max("rh_FFJ3");
72  EXPECT_DOUBLE_EQ(min_max.first, 0.0);
73  EXPECT_DOUBLE_EQ(min_max.second, 1.57079632679);
74 
75  // j0 should be 0, 180
76  min_max = handcmd.get_min_max("rh_FFJ0");
77  EXPECT_DOUBLE_EQ(min_max.first, 0.0);
78  EXPECT_DOUBLE_EQ(min_max.second, 3.14159265358);
79 
80  // returns 0, 0 if joint not found
81  min_max = handcmd.get_min_max("unknown joint");
82  EXPECT_DOUBLE_EQ(min_max.first, 0.0);
83  EXPECT_DOUBLE_EQ(min_max.second, 0.0);
84 
85  // Check that we can get the min and max for each joint
86  std::vector<std::string> all_joints = handcmd.get_all_joints();
87  for (size_t i = 0; i < all_joints.size(); ++i)
88  {
89  min_max = handcmd.get_min_max(all_joints[i]);
90  EXPECT_TRUE(min_max.first != min_max.second); // min = max if joint not found
91  }
92 }
93 
94 TEST(HandCommander, all_joints)
95 {
96  HandCommander handcmd = HandCommander();
97 
98  EXPECT_EQ(handcmd.get_all_joints().size(), 20);
99 }
100 
101 int main(int argc, char **argv)
102 {
103  testing::InitGoogleTest(&argc, argv);
104 
105  // sleep until gazebo is ready
106  sleep(300.0);
107 
108  ros::init(argc, argv, "hand_commander_test");
109  ros::NodeHandle nh; // init the node
110 
111 
112  return RUN_ALL_TESTS();
113 }
int main(int argc, char **argv)
std::string resolveName(const std::string &name, bool remap=true) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
std::vector< std::string > get_all_joints()
#define EXPECT_DOUBLE_EQ(expected, actual)
std::pair< double, double > get_min_max(std::string joint_name)
void InitGoogleTest(int *argc, char **argv)
std::string get_controller_state_topic(std::string joint_name)
#define EXPECT_EQ(expected, actual)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
TEST(HandCommander, constructor)
#define EXPECT_TRUE(condition)
This is a library that offers a simple interface to send commands to hand joints. It is compatible wi...


sr_hand
Author(s): Ugo Cupcic
autogenerated on Tue Oct 13 2020 03:55:53