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 #ifndef __ROBOTARM_H__
00031 #define __ROBOTARM_H__
00032
00033
00034 #include <ros/ros.h>
00035
00036 #include <pr2_controllers_msgs/JointTrajectoryAction.h>
00037 #include <pr2_controllers_msgs/JointTrajectoryControllerState.h>
00038 #include <actionlib/client/simple_action_client.h>
00039 #include <actionlib/client/terminal_state.h>
00040 #include <pr2_common_action_msgs/ArmMoveIKAction.h>
00041 #include <tf/transform_listener.h>
00042 #include <pr2_controllers_msgs/Pr2GripperCommandAction.h>
00043 #include <move_base_msgs/MoveBaseAction.h>
00044 #include <geometry_msgs/Twist.h>
00045 #include <pr2_msgs/PressureState.h>
00046 #include <kinematics_msgs/GetPositionIK.h>
00047 #include <kinematics_msgs/GetPositionFK.h>
00048
00049
00050 #include <find_base_pose/FindBasePoseAction.h>
00051
00052
00053 #include <boost/thread/mutex.hpp>
00054
00055
00056
00057
00058
00059
00060 typedef actionlib::SimpleActionClient< pr2_controllers_msgs::JointTrajectoryAction > TrajClient;
00061
00062 class RobotArm
00063 {
00064 private:
00065
00066
00067
00068 int side_;
00069
00070 TrajClient* traj_client_;
00071 static tf::TransformListener *listener_;
00072 actionlib::SimpleActionClient<pr2_common_action_msgs::ArmMoveIKAction> *ac_;
00073 static actionlib::SimpleActionClient<find_base_pose::FindBasePoseAction> *ac_fbp_;
00074 ros::Subscriber jointStateSubscriber_;
00075 ros::NodeHandle n_;
00076 boost::mutex mutex_;
00077
00078 ros::ServiceClient query_client;
00079 ros::ServiceClient fk_client;
00080 ros::ServiceClient ik_client;
00081
00082 volatile bool haveJointState;
00083 double jointState[7];
00084 double jointStateDes[7];
00085 double jointStateErr[7];
00086 std::string joint_names[7];
00087
00088 void jointStateCallback(const pr2_controllers_msgs::JointTrajectoryControllerState::ConstPtr& msg);
00089
00090 static RobotArm *instance[];
00091
00093 RobotArm(int side);
00094
00096 ~RobotArm();
00097
00098 public:
00099
00100 bool tucked;
00101
00102 int retries;
00103
00104 bool raise_elbow;
00105 double preset_angle;
00106
00107 actionlib::SimpleActionClient<pr2_common_action_msgs::ArmMoveIKAction> *getActionClient()
00108 {
00109 return ac_;
00110 }
00111
00112 static RobotArm* getInstance(int side = 0);
00113
00114 bool isTucked()
00115 {
00116 return tucked;
00117 }
00118
00119 void getJointState(double state[]);
00120 void getJointStateDes(double state[]);
00121 void getJointStateErr(double state[]);
00122
00123 static void init();
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 bool run_ik(geometry_msgs::PoseStamped pose, double start_angles[7],double solution[7], std::string link_name);
00140
00141 bool run_ik(tf::Stamped<tf::Pose> pose, double start_angles[7],double solution[7], std::string link_name);
00142
00143 tf::Stamped<tf::Pose> runFK(double jointAngles[], tf::Stamped<tf::Pose> *elbow = 0);
00144
00145
00147 btVector3 cartError();
00148
00150 void startTrajectory(pr2_controllers_msgs::JointTrajectoryGoal goal,bool wait = true);
00151
00152
00153 pr2_controllers_msgs::JointTrajectoryGoal twoPointTrajectory(double *poseA, double *poseB);
00154
00155 pr2_controllers_msgs::JointTrajectoryGoal multiPointTrajectory(const std::vector<std::vector<double> > &poses, const double &duration = 1.0);
00156
00157 pr2_controllers_msgs::JointTrajectoryGoal multiPointTrajectory(const std::vector<std::vector<double> > &poses, const std::vector<double> &duration);
00158
00159 pr2_controllers_msgs::JointTrajectoryGoal multiPointTrajectory(const std::vector<tf::Stamped<tf::Pose> > &poses, const std::vector<double> &duration);
00160
00161 pr2_controllers_msgs::JointTrajectoryGoal goalTraj(double a0, double a1, double a2, double a3, double a4, double a5, double a6, double dur=1.0);
00162
00163 pr2_controllers_msgs::JointTrajectoryGoal goalTraj(double *poseA, double dur=1.0);
00164
00165 pr2_controllers_msgs::JointTrajectoryGoal goalTraj(double *poseA, double *vel);
00166
00168 actionlib::SimpleClientGoalState getState();
00169
00170 static void printPose(const tf::Stamped<tf::Pose> &toolTargetPose);
00171
00172
00173
00174
00175
00176 tf::Stamped<tf::Pose> getToolPose(const char frame[] = "base_link");
00177
00178
00179
00180
00181
00182 void getToolPose(tf::Stamped<tf::Pose> &marker, const char frame[] = "base_link");
00183
00184 void getWristPose(tf::Stamped<tf::Pose> &marker, const char frame[] = "base_link");
00185
00186
00187
00188
00189
00190
00191
00192 bool rotate_toolframe_ik(double r_x, double r_y, double r_z);
00193 tf::Stamped<tf::Pose> rotate_toolframe_ik_p(double r_x, double r_y, double r_z);
00194
00195
00196
00197
00198
00199
00200 bool move_toolframe_ik_pose(tf::Stamped<tf::Pose> toolTargetPose);
00201 bool move_toolframe_ik(double x, double y, double z, double ox, double oy, double oz, double ow);
00202
00203 void stabilize_grip();
00204
00205
00206 bool move_ik(double x, double y, double z, double ox, double oy, double oz, double ow, double time = 1.0);
00207 bool move_ik(tf::Stamped<tf::Pose> targetPose, double time = 0.0);
00208
00209 tf::Stamped<tf::Pose> tool2wrist(tf::Stamped<tf::Pose> toolPose);
00210 tf::Stamped<tf::Pose> wrist2tool(tf::Stamped<tf::Pose> toolPose);
00211
00212
00213
00214 static bool findBaseMovement(tf::Stamped<tf::Pose> &result, std::vector<int> arm, std::vector<tf::Stamped<tf::Pose> > goal, bool drive, bool reach);
00215
00217 btVector3 universal_move_toolframe_ik_pose(tf::Stamped<tf::Pose> toolTargetPose);
00218
00220 btVector3 universal_move_toolframe_ik_pose_tolerance(tf::Stamped<tf::Pose> toolTargetPose, double tolerance, double timeout = 5.0);
00221
00222 btVector3 universal_move_toolframe_ik(double x, double y, double z, double ox, double oy, double oz, double ow, const char target_frame[]="base_link");
00223
00224
00225
00226
00227
00228 void bring_into_reach(tf::Stamped<tf::Pose> toolTargetPose);
00229
00230 bool reachable(tf::Stamped<tf::Pose> target);
00231
00232 void moveElbowOutOfWay(tf::Stamped<tf::Pose> toolTargetPose);
00233
00234 bool executeViaJointControl(const std::vector<tf::Stamped<tf::Pose> > &poses, int start = -1, int end = -1);
00235
00236 bool pose2Joint(const std::vector<tf::Stamped<tf::Pose> > &poses, std::vector<std::vector<double> > &joints);
00237
00238 static void moveBothArms(tf::Stamped<tf::Pose> leftArm, tf::Stamped<tf::Pose> rightArm, double tolerance = 0, bool wait = true);
00239
00240
00241
00242
00243
00244
00245 double time_to_target;
00246
00247 bool evil_switch;
00248
00249 bool excludeBaseProjectionFromWorkspace;
00250
00251 tf::Stamped<tf::Pose> wrist2tool_;
00252 tf::Stamped<tf::Pose> tool2wrist_;
00253
00254 std::string wrist_frame;
00255 std::string tool_frame;
00256 };
00257
00258
00259 #endif