Go to the documentation of this file.00001
00027 #include "sr_robot_lib/sr_motor_hand_lib.hpp"
00028 #include <sr_mechanism_model/simple_transmission.hpp>
00029 #include <gtest/gtest.h>
00030 #include <ros/ros.h>
00031 #include <utility>
00032 #include <string>
00033 #include <vector>
00034
00035 #define error_flag_names palm_0200_edc_error_flag_names
00036 #define STATUS_TYPE ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_STATUS
00037 #define COMMAND_TYPE ETHERCAT_DATA_STRUCTURE_0230_PALM_EDC_COMMAND
00038
00039 class HandLibTestProtected :
00040 public shadow_robot::SrMotorHandLib<STATUS_TYPE, COMMAND_TYPE>
00041 {
00042 public:
00043 HandLibTestProtected(hardware_interface::HardwareInterface *hw, ros::NodeHandle nh)
00044 : shadow_robot::SrMotorHandLib<STATUS_TYPE, COMMAND_TYPE>(hw, nh, nh, "", "rh_")
00045 {
00046 };
00047
00048 public:
00049 using shadow_robot::SrMotorHandLib<STATUS_TYPE, COMMAND_TYPE>::joints_vector;
00050 using shadow_robot::SrMotorHandLib<STATUS_TYPE, COMMAND_TYPE>::humanize_flags;
00051 };
00052
00053 class HandLibTest
00054 {
00055 ros::NodeHandle nh;
00056 public:
00057 ros_ethercat_model::RobotState *hw = NULL;
00058 boost::shared_ptr<HandLibTestProtected> sr_hand_lib;
00059 sr_actuator::SrMotorActuator *actuator;
00060 XmlRpc::XmlRpcValue joint_to_sensor_mapping;
00061
00062 HandLibTest()
00063 {
00064 TiXmlElement *root;
00065 TiXmlElement *root_element;
00066 TiXmlDocument xml;
00067 std::string robot_description;
00068 if (ros::param::get("/robot_description", robot_description))
00069 {
00070 xml.Parse(robot_description.c_str());
00071 }
00072 else
00073 {
00074 ROS_ERROR_STREAM("Could not load the xml from parameter server");
00075 }
00076 root_element = xml.RootElement();
00077 root = xml.FirstChildElement("robot");
00078
00079 nh.getParam("joint_to_sensor_mapping", joint_to_sensor_mapping);
00080 hw = new ros_ethercat_model::RobotState(root);
00081
00082 hardware_interface::HardwareInterface *ehw = static_cast<hardware_interface::HardwareInterface *>(hw);
00083 sr_hand_lib.reset(new HandLibTestProtected(ehw, nh));
00084 }
00085
00086 ~HandLibTest()
00087 {
00088 delete hw;
00089 }
00090
00091 void check_hw_actuator(std::string name, int motor_id, int id_in_enum, double expected_pos)
00092 {
00093 actuator = static_cast<sr_actuator::SrMotorActuator *>(hw->getActuator(name));
00094
00095 EXPECT_EQ(actuator->state_.device_id_, motor_id);
00096
00097 }
00098 };
00099
00103 TEST(SrRobotLib, Initialization)
00104 {
00105 boost::shared_ptr<HandLibTest> lib_test = boost::shared_ptr<HandLibTest>(new HandLibTest());
00106
00107
00108
00109
00110
00111
00112
00113 EXPECT_TRUE(true);
00114 }
00115
00119 TEST(SrRobotLib, UpdateMotor)
00120 {
00121 boost::shared_ptr<HandLibTest> lib_test = boost::shared_ptr<HandLibTest>(new HandLibTest());
00122
00123 STATUS_TYPE *status_data = new STATUS_TYPE();
00124
00125 for (unsigned int i = 1; i < SENSORS_NUM_0220 + 2; ++i)
00126 {
00127
00128 status_data->sensors[i] = i;
00129 }
00130
00131 status_data->motor_data_type = MOTOR_DATA_SGR;
00132
00133
00134 status_data->which_motors = 0;
00135
00136
00137 status_data->which_motor_data_arrived = 0x00055555;
00138 status_data->which_motor_data_had_errors = 0;
00139
00140
00141 for (unsigned int i = 0; i < 10; ++i)
00142 {
00143 status_data->motor_data_packet[i].torque = 4;
00144 status_data->motor_data_packet[i].misc = 2 * i;
00145 }
00146
00147 status_data->idle_time_us = 1;
00148
00149
00150 lib_test->sr_hand_lib->update(status_data);
00151
00152
00153 EXPECT_EQ(lib_test->sr_hand_lib->main_pic_idle_time, 1);
00154 EXPECT_EQ(lib_test->sr_hand_lib->main_pic_idle_time_min, 1);
00155
00156
00157 std::vector<shadow_joints::Joint>::iterator joint_tmp = lib_test->sr_hand_lib->joints_vector.begin();
00158 for (; joint_tmp != lib_test->sr_hand_lib->joints_vector.end(); ++joint_tmp)
00159 {
00160 if (joint_tmp->has_actuator)
00161 {
00162 boost::shared_ptr<shadow_joints::MotorWrapper> motor_wrapper =
00163 boost::static_pointer_cast<shadow_joints::MotorWrapper>(joint_tmp->actuator_wrapper);
00164
00165 if (motor_wrapper->motor_id % 2 == 0)
00166 {
00167 const sr_actuator::SrMotorActuator *sr_actuator =
00168 static_cast<sr_actuator::SrMotorActuator *>(motor_wrapper->actuator);
00169
00170 ROS_ERROR_STREAM("last measured effort: " << sr_actuator->state_.last_measured_effort_ << " actuator: " <<
00171 motor_wrapper->actuator);
00172
00173 EXPECT_FLOAT_EQ(sr_actuator->motor_state_.force_unfiltered_, 4.0);
00174 EXPECT_EQ(sr_actuator->motor_state_.strain_gauge_right_, motor_wrapper->motor_id);
00175 }
00176 }
00177 }
00178 delete status_data;
00179 }
00180
00186 TEST(SrRobotLib, UpdateActuators)
00187 {
00188 boost::shared_ptr<HandLibTest> lib_test = boost::shared_ptr<HandLibTest>(new HandLibTest());
00189
00190 STATUS_TYPE *status_data = new STATUS_TYPE();
00191
00192 for (unsigned int i = 0; i < SENSORS_NUM_0220 + 1; ++i)
00193 {
00194
00195 status_data->sensors[i] = i + 1;
00196 }
00197
00198 status_data->motor_data_type = MOTOR_DATA_VOLTAGE;
00199
00200
00201 status_data->which_motors = 0;
00202
00203
00204 status_data->which_motor_data_arrived = 0x00055555;
00205 status_data->which_motor_data_had_errors = 0;
00206
00207
00208 for (unsigned int i = 0; i < 10; ++i)
00209 {
00210 status_data->motor_data_packet[i].torque = i;
00211 status_data->motor_data_packet[i].misc = 10 * i;
00212 }
00213
00214 status_data->idle_time_us = 1;
00215
00216
00217 lib_test->sr_hand_lib->update(status_data);
00218
00219
00220 lib_test->check_hw_actuator("rh_FFJ4", 2, 3, 4.0);
00221
00222
00223 delete status_data;
00224 }
00225
00232 class TestHandLib
00233 :
00234 public HandLibTestProtected
00235 {
00236 public:
00237 TestHandLib(hardware_interface::HardwareInterface *hw, ros::NodeHandle nh)
00238 : HandLibTestProtected(hw, nh)
00239 {
00240 }
00241
00242 using HandLibTestProtected::calibrate_joint;
00243
00244
00245
00246
00247
00248 using HandLibTestProtected::humanize_flags;
00249 };
00250
00251
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00439 TEST(SrRobotLib, HumanizeFlags)
00440 {
00441 boost::shared_ptr<HandLibTest> lib_test = boost::shared_ptr<HandLibTest>(new HandLibTest());
00442
00443 std::vector<std::pair<std::string, bool> > flags;
00444
00445 flags = lib_test->sr_hand_lib->humanize_flags(0xFFFF);
00446
00447 EXPECT_EQ(flags.size(), 16);
00448
00449 for (unsigned int i = 0; i < 16; ++i)
00450 {
00451 EXPECT_EQ(flags[i].first.compare(error_flag_names[i]), 0);
00452 }
00453
00454
00455 EXPECT_TRUE(flags[13].second);
00456 EXPECT_TRUE(flags[14].second);
00457 EXPECT_TRUE(flags[15].second);
00458 }
00459
00461
00463
00464 int main(int argc, char **argv)
00465 {
00466 ros::init(argc, argv, "calibration_test");
00467 testing::InitGoogleTest(&argc, argv);
00468 return RUN_ALL_TESTS();
00469 }
00470
00471
00472
00473
00474
00475