Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef REGRESSION_TEST_ARM_HELPERS
00040 #define REGRESSION_TEST_ARM_HELPERS
00041
00042 #include <planning_environment/monitors/kinematic_model_state_monitor.h>
00043 #include <planning_environment/util/kinematic_state_constraint_evaluator.h>
00044 #include <move_arm/MoveArmAction.h>
00045
00046 #include <planning_models/kinematic_state.h>
00047
00048 void setupGoal(const std::vector<std::string> &names, move_arm::MoveArmGoal &goal)
00049 {
00050 goal.goal_constraints.joint_constraint.resize(names.size());
00051 for (unsigned int i = 0 ; i < goal.goal_constraints.joint_constraint.size(); ++i)
00052 {
00053 goal.goal_constraints.joint_constraint[i].header.stamp = ros::Time::now();
00054 goal.goal_constraints.joint_constraint[i].header.frame_id = "/base_link";
00055 goal.goal_constraints.joint_constraint[i].joint_name = names[i];
00056 goal.goal_constraints.joint_constraint[i].value.resize(1);
00057 goal.goal_constraints.joint_constraint[i].tolerance_above.resize(1);
00058 goal.goal_constraints.joint_constraint[i].tolerance_below.resize(1);
00059 goal.goal_constraints.joint_constraint[i].value[0] = 0.0;
00060 goal.goal_constraints.joint_constraint[i].tolerance_below[0] = 0.0;
00061 goal.goal_constraints.joint_constraint[i].tolerance_above[0] = 0.0;
00062 }
00063
00064 goal.contacts.resize(1);
00065 goal.contacts[0].links.push_back("r_gripper_l_finger_link");
00066 goal.contacts[0].links.push_back("r_gripper_r_finger_link");
00067 goal.contacts[0].links.push_back("r_gripper_l_finger_tip_link");
00068 goal.contacts[0].links.push_back("r_gripper_r_finger_tip_link");
00069 goal.contacts[0].links.push_back("r_gripper_palm_link");
00070 goal.contacts[0].links.push_back("r_wrist_roll_link");
00071 goal.contacts[0].depth = 0.04;
00072 goal.contacts[0].bound.type = arm_navigation_msgs::Object::SPHERE;
00073 goal.contacts[0].bound.dimensions.push_back(0.5);
00074
00075 goal.contacts[0].pose.header.stamp = ros::Time::now();
00076 goal.contacts[0].pose.header.frame_id = "/base_link";
00077 goal.contacts[0].pose.pose.position.x = 1;
00078 goal.contacts[0].pose.pose.position.y = 0;
00079 goal.contacts[0].pose.pose.position.z = 0.5;
00080
00081 goal.contacts[0].pose.pose.orientation.x = 0;
00082 goal.contacts[0].pose.pose.orientation.y = 0;
00083 goal.contacts[0].pose.pose.orientation.z = 0;
00084 goal.contacts[0].pose.pose.orientation.w = 1;
00085 }
00086
00087 void goalToState(const move_arm::MoveArmGoal &goal, planning_models::KinematicState &sp)
00088 {
00089 for (unsigned int i = 0 ; i < goal.goal_constraints.joint_constraint.size() ; ++i)
00090 {
00091 sp.setParamsJoint(&goal.goal_constraints.joint_constraint[i].value[0],
00092 goal.goal_constraints.joint_constraint[i].joint_name);
00093 }
00094 }
00095
00096 tf::Transform effPosition(const planning_environment::KinematicModelStateMonitor &km, const move_arm::MoveArmGoal &goal)
00097 {
00098 planning_models::KinematicState sp(*km.getRobotState());
00099 goalToState(goal, sp);
00100 km.getKinematicModel()->computeTransforms(sp.getParams());
00101 return km.getKinematicModel()->getJoint("r_wrist_roll_joint")->after->globalTrans;
00102 }
00103
00104 void diffConfig(const planning_environment::KinematicModelStateMonitor &km, move_arm::MoveArmGoal &goal, double& dist, double& angle)
00105 {
00106
00107 tf::Transform pose1 = effPosition(km, goal);
00108
00109
00110 std::vector<std::string> names(7);
00111 names[0] = "r_shoulder_pan_joint";
00112 names[1] = "r_shoulder_lift_joint";
00113 names[2] = "r_upper_arm_roll_joint";
00114 names[3] = "r_elbow_flex_joint";
00115 names[4] = "r_forearm_roll_joint";
00116 names[5] = "r_wrist_flex_joint";
00117 names[6] = "r_wrist_roll_joint";
00118 move_arm::MoveArmGoal temp;
00119 setupGoal(names,temp);
00120
00121 planning_models::KinematicState sp(*(km.getRobotState()));
00122 sp.enforceBounds();
00123 for (unsigned int i = 0 ; i < names.size() ; ++i)
00124 {
00125 temp.goal_constraints.joint_constraint[i].value[0] =
00126 sp.getParamsJoint(names[i])[0];
00127 }
00128
00129 tf::Transform pose2 = effPosition(km, temp);
00130 dist = pose1.getOrigin().distance(pose2.getOrigin());
00131 angle = pose1.getRotation().angle(pose2.getRotation());
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 bool finalStateMatchesGoal(const planning_environment::KinematicModelStateMonitor &km, move_arm::MoveArmGoal &goal)
00164 {
00165 planning_models::KinematicState sp(*km.getRobotState());
00166
00167 km.getKinematicModel()->computeTransforms(sp.getParams());
00168
00169 planning_environment::KinematicConstraintEvaluatorSet ks;
00170 ks.add(km.getKinematicModel(),goal.goal_constraints.joint_constraint);
00171 ks.add(km.getKinematicModel(),goal.goal_constraints.pose_constraint);
00172
00173 ks.print(std::cout);
00174
00175 return ks.decide(sp.getParams(),true);
00176
00177 }
00178
00179 bool currentStateSatisfiesPathConstraints(const planning_environment::KinematicModelStateMonitor &km, move_arm::MoveArmGoal &goal) {
00180
00181 planning_models::KinematicState sp(*km.getRobotState());
00182
00183 km.getKinematicModel()->computeTransforms(sp.getParams());
00184
00185 planning_environment::KinematicConstraintEvaluatorSet ks;
00186 ks.add(km.getKinematicModel(),goal.path_constraints.joint_constraint);
00187 ks.add(km.getKinematicModel(),goal.path_constraints.pose_constraint);
00188
00189 ks.print(std::cout);
00190
00191 bool ok = ks.decide(sp.getParams(),true);
00192
00193 if(!ok) {
00194
00195 ks.decide(sp.getParams(),true);
00196 }
00197
00198 return ok;
00199 }
00200
00201 #endif