test_sr_hand_autodetect.cpp
Go to the documentation of this file.
1 /*
2 * Copyright 2020 Shadow Robot Company Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 
17 #include <gtest/gtest.h>
18 #include <ros/ros.h>
19 #include <ros/package.h>
20 #include <utility>
21 #include <string>
24 #include "yaml-cpp/exceptions.h"
25 
26 
27 TEST(SrHandAutodetect, test_run_unimanual)
28 {
29  std::string expected_command_suffix = " eth_port:=eth0 hand_serial:=1130 side:=right"
30  " hand_type:=hand_e_plus hand_version:=E3M5 fingers:=th,ff,mf,rf,lf"
31  " tip_sensors:=ff=bt_sp,lf=bt_sp,mf=bt_sp,rf=bt_sp,th=bt_sp mid_sensors:=none"
32  " prox_sensors:=none palm_sensor:=none";
33  std::string hand_config_path = ros::package::getPath("sr_hand_detector") + "/test/config";
34  std::string detected_hands_file = ros::package::getPath("sr_hand_detector") + "/test/config/test_unimanual.yaml";
35 
36  sr_hand_detector::SrHandAutodetect sr_hand_autodetect(detected_hands_file, hand_config_path);
37  sr_hand_autodetect.run();
38  ASSERT_EQ(sr_hand_autodetect.get_command_suffix(), expected_command_suffix);
39 }
40 
41 TEST(SrHandAutodetect, test_run_unimanual_additional_params)
42 {
43  std::string expected_command_suffix = " eth_port:=eth0 hand_serial:=634 side:=right"
44  " hand_type:=hand_e hand_version:=E3M5 fingers:=th,ff,mf,rf,lf"
45  " tip_sensors:=ff=pst,lf=pst,mf=pst,rf=pst,th=pst mid_sensors:=none"
46  " prox_sensors:=none palm_sensor:=none";
47  std::string expected_mapping_path = ros::package::getPath("sr_hand_detector") + "/rh_mapping.yaml";
48  expected_command_suffix += " mapping_path:=" + expected_mapping_path;
49 
50  std::string hand_config_path = ros::package::getPath("sr_hand_detector") + "/test/config";
51  std::string detected_hands_file = ros::package::getPath("sr_hand_detector") +
52  "/test/config/test_unimanual_additional_params.yaml";
53 
54  sr_hand_detector::SrHandAutodetect sr_hand_autodetect(detected_hands_file, hand_config_path);
55  sr_hand_autodetect.run();
56  ASSERT_EQ(sr_hand_autodetect.get_command_suffix(), expected_command_suffix);
57 }
58 
59 TEST(SrHandAutodetect, test_run_bimanual)
60 {
61  std::string expected_rh_mapping_path = ros::package::getPath("sr_hand_detector") + "/rh_mapping.yaml";
62  std::string expected_lh_mapping_path = ros::package::getPath("sr_hand_detector") + "/lh_mapping.yaml";
63  std::string expected_command_suffix = " eth_port:=eth0_eth1 rh_serial:=634 lh_serial:=2346 right_hand_type:=hand_e"
64  " right_hand_version:=E3M5 right_fingers:=th,ff,mf,rf,lf"
65  " right_tip_sensors:=ff=pst,lf=pst,mf=pst,rf=pst,th=pst"
66  " right_mid_sensors:=none right_prox_sensors:=none right_palm_sensor:=none"
67  " rh_mapping_path:=" + expected_rh_mapping_path +
68  " left_hand_type:=hand_e left_hand_version:=E3M5 left_fingers:=th,ff,mf,rf,lf"
69  " left_tip_sensors:=ff=bt_sp,lf=bt_sp,mf=bt_sp,rf=bt_sp,th=bt_sp"
70  " left_mid_sensors:=none left_prox_sensors:=none left_palm_sensor:=none"
71  " lh_mapping_path:=" + expected_lh_mapping_path;
72 
73  std::string hand_config_path = ros::package::getPath("sr_hand_detector") + "/test/config";
74  std::string detected_hands_file = ros::package::getPath("sr_hand_detector") + "/test/config/test_bimanual.yaml";
75 
76  sr_hand_detector::SrHandAutodetect sr_hand_autodetect(detected_hands_file, hand_config_path);
77  sr_hand_autodetect.run();
78  ASSERT_EQ(sr_hand_autodetect.get_command_suffix(), expected_command_suffix);
79 }
80 
81 TEST(SrHandAutodetect, test_run_bimanual_forced_side)
82 {
83  std::string expected_command_suffix = " eth_port:=eth0 hand_serial:=634 side:=right"
84  " hand_type:=hand_e hand_version:=E3M5 fingers:=th,ff,mf,rf,lf"
85  " tip_sensors:=ff=pst,lf=pst,mf=pst,rf=pst,th=pst mid_sensors:=none"
86  " prox_sensors:=none palm_sensor:=none";
87  std::string expected_mapping_path = ros::package::getPath("sr_hand_detector") + "/rh_mapping.yaml";
88  expected_command_suffix += " mapping_path:=" + expected_mapping_path;
89 
90  std::string hand_config_path = ros::package::getPath("sr_hand_detector") + "/test/config";
91  std::string detected_hands_file = ros::package::getPath("sr_hand_detector") + "/test/config/test_bimanual.yaml";
92 
93  sr_hand_detector::SrHandAutodetect sr_hand_autodetect(detected_hands_file, hand_config_path,
95  sr_hand_autodetect.run();
96  ASSERT_EQ(sr_hand_autodetect.get_command_suffix(), expected_command_suffix);
97 }
98 
99 TEST(SrHandAutodetect, test_run_no_hands)
100 {
101  std::string expected_command_suffix = "";
102  std::string hand_config_path = ros::package::getPath("sr_hand_detector") + "/test/config";
103  std::string detected_hands_file = ros::package::getPath("sr_hand_detector") + "/test/config/test_no_hands.yaml";
104 
105  sr_hand_detector::SrHandAutodetect sr_hand_autodetect(detected_hands_file, hand_config_path);
106  sr_hand_autodetect.run();
107  ASSERT_EQ(sr_hand_autodetect.get_command_suffix(), expected_command_suffix);
108 }
109 
110 TEST(SrHandAutodetect, test_run_non_existing_hand)
111 {
112  std::string hand_config_path = ros::package::getPath("sr_hand_detector") + "/test/config";
113  std::string detected_hands_file = ros::package::getPath("sr_hand_detector") +
114  "/test/config/test_non_existing_hand.yaml";
115  sr_hand_detector::SrHandAutodetect sr_hand_autodetect(detected_hands_file, hand_config_path);
116  ASSERT_THROW(sr_hand_autodetect.run(), YAML::BadFile);
117 }
118 
119 int main(int argc, char **argv)
120 {
121  ros::init(argc, argv, "test_sr_hand_autodetect");
122  ros::NodeHandle nh;
123  testing::InitGoogleTest(&argc, argv);
124  return RUN_ALL_TESTS();
125 }
sr_hand_detector::SrHandAutodetect::run
void run()
Definition: sr_hand_autodetect.cpp:59
sr_hand_detector::SrHandAutodetect::get_command_suffix
std::string get_command_suffix()
Definition: sr_hand_autodetect.cpp:66
ros::package::getPath
ROSLIB_DECL std::string getPath(const std::string &package_name)
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
main
int main(int argc, char **argv)
Definition: test_sr_hand_autodetect.cpp:119
sr_hand_detector::SrHandAutodetect
Definition: sr_hand_autodetect.h:32
TEST
TEST(SrHandAutodetect, test_run_unimanual)
Definition: test_sr_hand_autodetect.cpp:27
sr_hand_detector.h
package.h
sr_hand_detector::ForcedHandSide::right
@ right
sr_hand_autodetect.h
ros::NodeHandle


sr_hand_detector
Author(s):
autogenerated on Sat Sep 24 2022 02:26:10