Go to the documentation of this file.00001 #include <time.h>
00002 #include <ros/ros.h>
00003 #include <actionlib/client/simple_action_client.h>
00004 #include <gtest/gtest.h>
00005 #include <sensor_msgs/JointState.h>
00006 #include <iri_wam_common_msgs/SimpleBhandPickUpAction.h>
00007 #include <object_manipulation_msgs/GripperTranslation.h>
00008
00009 #include "geometry_test_helpers.h"
00010 #include "iri_bhand_fake_recorder.cpp"
00011 #include "iri_wam_joint_move_fake_recorder.cpp"
00012 #include "iri_ik_fake_recorder.cpp"
00013 #include "../../include/grasp_actions_alg_node.h"
00014
00015 using namespace geometry_test_helpers;
00016
00017 const size_t DOF = 7;
00018
00019 std::vector<double> get_random_seven_joints_position()
00020 {
00021 std::vector<double> m;
00022
00023 srand(time(NULL));
00024
00025 for (int i=0; i < 7; i++)
00026 m.push_back(rand() % 10 + 1);
00027
00028 return m;
00029 }
00030
00031 std::string ns = "/iri_grasp_actions_test/";
00032
00033 TEST(Bhand, constructor)
00034 {
00035 ASSERT_NO_THROW(
00036 BhandFakeRecorder * p = new BhandFakeRecorder("bhand_cmd");
00037 delete p;
00038 );
00039 }
00040
00041 TEST(Bhand, simple_cmd)
00042 {
00043 ros::NodeHandle n;
00044 BhandFakeRecorder bhand_fake(ns + "bhand_cmd");
00045
00046 iri_wam_common_msgs::bhand_cmd cmd;
00047
00048 cmd.request.bhandcmd = "GTO";
00049
00050 ros::ServiceClient client = n.serviceClient<iri_wam_common_msgs::bhand_cmd>
00051 (ns + "bhand_cmd");
00052 client.call(cmd);
00053 usleep(400);
00054
00055 ASSERT_EQ(cmd.request.bhandcmd, bhand_fake.getLastMsg());
00056 }
00057
00058
00059 TEST(JointsMove, constructor)
00060 {
00061 ASSERT_NO_THROW(
00062 WamJointMoveFakeRecorder<DOF> * p = new WamJointMoveFakeRecorder<DOF>("joints_move");
00063 delete p;
00064 );
00065 }
00066
00067 TEST(JointsMove, simple_cmd)
00068 {
00069 ros::NodeHandle n;
00070 WamJointMoveFakeRecorder<DOF> joints_move_fake(ns + "joints_move");
00071
00072 iri_wam_common_msgs::joints_move cmd;
00073
00074 cmd.request.joints = get_random_seven_joints_position();
00075
00076 ros::ServiceClient client = n.serviceClient<iri_wam_common_msgs::joints_move>
00077 (ns + "joints_move");
00078 client.call(cmd);
00079 usleep(400);
00080
00081 ASSERT_EQ(cmd.request.joints, joints_move_fake.getLastMsg());
00082 }
00083
00084 TEST(JointsMove, bad_joints)
00085 {
00086 ros::NodeHandle n;
00087 WamJointMoveFakeRecorder<DOF> joints_move_fake(ns + "joints_move");
00088
00089 iri_wam_common_msgs::joints_move cmd;
00090
00091 cmd.request.joints = get_random_seven_joints_position();
00092
00093 cmd.request.joints.push_back(0.0);
00094
00095 ros::ServiceClient client = n.serviceClient<iri_wam_common_msgs::joints_move>
00096 (ns + "joints_move");
00097 client.call(cmd);
00098 usleep(400);
00099
00100 ASSERT_FALSE(cmd.response.success);
00101 }
00102
00103 TEST(IK, constructor)
00104 {
00105 ASSERT_NO_THROW(
00106 IKFakeRecorder * p = new IKFakeRecorder("get_wam_ik");
00107 delete p;
00108 );
00109 }
00110
00111 TEST(IK, simple_ik)
00112 {
00113 ros::NodeHandle n;
00114 IKFakeRecorder ik_fake(ns + "get_wam_ik");
00115 geometry_msgs::PoseStamped pose_st;
00116 pose_st.pose = geometry_test_helpers::generator::generate_fixed_pose(1);
00117
00118 iri_wam_common_msgs::wamInverseKinematics cmd;
00119
00120 cmd.request.pose = pose_st;
00121 ros::ServiceClient client = n.serviceClient<iri_wam_common_msgs::wamInverseKinematics>
00122 (ns + "get_wam_ik");
00123 client.call(cmd);
00124 usleep(400);
00125
00126 ASSERT_TRUE(comparison::poses_stamped_are_equal(cmd.request.pose, ik_fake.getLastMsg()));
00127 }
00128
00129 TEST(GraspActions, constructor)
00130 {
00131 ASSERT_NO_THROW(
00132 GraspActionsAlgNode * p = new GraspActionsAlgNode();
00133 delete p;
00134 );
00135 }
00136
00137 TEST(GraspActions, test_movement)
00138 {
00139 ros::NodeHandle n;
00140 GraspActionsAlgNode grasp_node;
00141 BhandFakeRecorder bhand_fake(ns + "bhand_cmd");
00142 WamJointMoveFakeRecorder<DOF> joint_move_fake(ns + "joints_move");
00143 IKFakeRecorder ik_fake(ns + "get_wam_ik");
00144 std::string default_grasp("SGO");
00145 std::string default_pre_grasp("SGC");
00146 geometry_msgs::Pose grasp_pose, pre_grasp_modifier;
00147 object_manipulation_msgs::GripperTranslation lift;
00148
00149 lift.direction.vector.x = 1;
00150 lift.direction.vector.y = 1;
00151 lift.direction.vector.z = -1;
00152 lift.desired_distance = 0.2;
00153
00154 iri_wam_common_msgs::SimpleBhandPickUpGoal goal;
00155
00156 actionlib::SimpleActionClient<iri_wam_common_msgs::SimpleBhandPickUpAction> ac(ns + "pickup", true);
00157 ac.waitForServer();
00158
00159
00160 grasp_pose = generator::generate_fixed_pose(1);
00161 pre_grasp_modifier = generator::generate_fixed_pose(2);
00162 goal.grasp_pose.pose = grasp_pose;
00163 goal.pre_grasp_modifier = pre_grasp_modifier;
00164 goal.lift = lift;
00165 goal.fingers_position_for_grasp.push_back(default_grasp);
00166 goal.fingers_position_for_pre_grasp.push_back(default_pre_grasp);
00167
00168 ac.sendGoal(goal);
00169
00170
00171 bool finished_before_timeout = ac.waitForResult(ros::Duration(10.0));
00172
00173 if (! finished_before_timeout)
00174 FAIL() << "Action did not finish before the time out.";
00175
00176 actionlib::SimpleClientGoalState state = ac.getState();
00177
00178 std::vector<std::vector<double> > movements = joint_move_fake.getHistoryOfMsg();
00179 std::vector<std::string> fingers_positions = bhand_fake.getHistoryOfMsg();
00180 std::vector<geometry_msgs::PoseStamped> poses = ik_fake.getHistoryOfMsg();
00181
00182 ASSERT_EQ(state.toString(), "SUCCEEDED");
00183 ASSERT_EQ(movements.size(), 3);
00184 ASSERT_EQ(poses.size(), 3);
00185
00186 ASSERT_LE(poses[0].pose.position.z, poses[1].pose.position.z);
00187
00188 ASSERT_LE(poses[2].pose.position.z, poses[1].pose.position.z);
00189 ASSERT_EQ(fingers_positions.size(), 2);
00190 ASSERT_EQ(fingers_positions[0], default_pre_grasp);
00191 ASSERT_EQ(fingers_positions[1], default_grasp);
00192 }
00193
00194
00195 int main(int argc, char **argv)
00196 {
00197 ros::init(argc, argv, "iri_grasp_actions_test");
00198
00199
00200 ros::AsyncSpinner spinner(1);
00201 spinner.start();
00202
00203 testing::InitGoogleTest(&argc, argv);
00204 return RUN_ALL_TESTS();
00205 }