test_hand_finder.cpp
Go to the documentation of this file.
00001 /*
00002  * File:  test_hand_finder.cpp
00003  * Author: Vahid Aminzadeh <vahid@shadowrobot.com>
00004  * Copyright:
00005  *
00006  * @brief see README.md
00007  */
00008 #include <gtest/gtest.h>
00009 #include <vector>
00010 #include "ros/ros.h"
00011 #include <ros/package.h>
00012 #include <iostream>
00013 #include <map>
00014 #include <string>
00015 #include "sr_utilities/sr_hand_finder.hpp"
00016 using std::vector;
00017 using std::map;
00018 using std::string;
00019 
00020 TEST(SrHandFinder, hand_absent_test)
00021 {
00022   shadow_robot::SrHandFinder hand_finder;
00023   map<string, vector<string> > hand_joints(hand_finder.get_joints());
00024   ASSERT_EQ(hand_joints.size(), 0);
00025   map<string, string> calibration_path(hand_finder.get_calibration_path());
00026   ASSERT_EQ(calibration_path.size(), 0);
00027   shadow_robot::HandControllerTuning controller_tuning(hand_finder.get_hand_controller_tuning());
00028   ASSERT_EQ(controller_tuning.friction_compensation_.size(), 0);
00029   ASSERT_EQ(controller_tuning.host_control_.size(), 0);
00030   ASSERT_EQ(controller_tuning.motor_control_.size(), 0);
00031 }
00032 TEST(SrHandFinder, hand_present_test)
00033 {
00034   ros::NodeHandle nh;
00035   nh.setParam("hand/mapping/1", "rh");
00036   nh.setParam("hand/joint_prefix/1", "rh_");
00037   const string joint_names[] = {"FFJ1", "FFJ2", "FFJ3", "FFJ4", "MFJ1", "MFJ2", "MFJ3", "MFJ4",
00038                                 "RFJ1", "RFJ2", "RFJ3", "RFJ4", "LFJ1", "LFJ2", "LFJ3", "LFJ4", "LFJ5",
00039                                 "THJ1", "THJ2", "THJ3", "THJ4", "THJ5", "WRJ1", "WRJ2"};
00040   shadow_robot::SrHandFinder hand_finder;
00041   map<string, vector<string> > hand_joints(hand_finder.get_joints());
00042   for (map<string, vector<string> >::const_iterator iter = hand_joints.begin(); iter != hand_joints.end(); ++iter)
00043   {
00044     for (size_t i = 0; i != iter->second.size(); ++i)
00045     {
00046       ROS_DEBUG_STREAM(iter->second[i]);
00047       ASSERT_STREQ(iter->second[i].c_str(), ("rh_" +  joint_names[i]).c_str());
00048     }
00049   }
00050   string ethercat_path = ros::package::getPath("sr_ethercat_hand_config");
00051   map<string, string> calibration_path(hand_finder.get_calibration_path());
00052   for (map<string, string>::const_iterator iter = calibration_path.begin(); iter != calibration_path.end(); ++iter)
00053   {
00054     ROS_INFO_STREAM(iter->second);
00055     ASSERT_STREQ(iter->second.c_str(), (ethercat_path + "/calibrations/rh/" + "calibration.yaml").c_str());
00056   }
00057   shadow_robot::HandControllerTuning controller_tuning(hand_finder.get_hand_controller_tuning());
00058   for (map<string, string>::const_iterator iter = controller_tuning.friction_compensation_.begin();
00059       iter != controller_tuning.friction_compensation_.end(); ++iter)
00060   {
00061     ASSERT_STREQ(iter->second.c_str(), (ethercat_path  + "/controls/friction_compensation.yaml").c_str());
00062     ROS_DEBUG_STREAM(iter->second);
00063   }
00064   for (map<string, string>::const_iterator iter = controller_tuning.motor_control_.begin();
00065         iter != controller_tuning.motor_control_.end(); ++iter)
00066   {
00067     ASSERT_STREQ(iter->second.c_str(),
00068                  (ethercat_path  + "/controls/motors/rh/motor_board_effort_controllers.yaml").c_str());
00069     ROS_DEBUG_STREAM(iter->second);
00070   }
00071   for (map<string, vector<string> >::const_iterator iter = controller_tuning.host_control_.begin();
00072           iter != controller_tuning.host_control_.end(); ++iter)
00073   {
00074     string host_array[] = {"sr_edc_calibration_controllers.yaml",
00075                          "sr_edc_joint_velocity_controllers_PWM.yaml",
00076                          "sr_edc_effort_controllers_PWM.yaml",
00077                          "sr_edc_joint_velocity_controllers.yaml",
00078                          "sr_edc_effort_controllers.yaml",
00079                          "sr_edc_mixed_position_velocity_joint_controllers_PWM.yaml",
00080                          "sr_edc_joint_position_controllers_PWM.yaml",
00081                          "sr_edc_mixed_position_velocity_joint_controllers.yaml",
00082                          "sr_edc_joint_position_controllers.yaml"};
00083     vector<string> host_controller_files(host_array, host_array + 9);
00084     ASSERT_EQ(host_controller_files.size(), iter->second.size());
00085     for (size_t i = 0; i != iter->second.size(); ++i)
00086     {
00087       ASSERT_STREQ(iter->second[i].c_str(), (ethercat_path + "/controls/host/rh/" + host_controller_files[i]).c_str());
00088       ROS_DEBUG_STREAM(iter->second[i]);
00089     }
00090   }
00091   nh.deleteParam("hand/mapping/1");
00092   nh.deleteParam("hand/joint_prefix/1");
00093   ASSERT_TRUE(true);
00094 }
00095 
00096 
00097 int main(int argc, char **argv)
00098 {
00099   ros::init(argc, argv, "test_hand_finder");
00100   ros::NodeHandle nh;
00101   testing::InitGoogleTest(&argc, argv);
00102   return RUN_ALL_TESTS();
00103 }
00104 


sr_utilities
Author(s): Ugo Cupcic
autogenerated on Fri Aug 21 2015 12:24:47