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
00032 #ifndef __SBPL_ARM_PLANNER_NODE_H_
00033 #define __SBPL_ARM_PLANNER_NODE_H_
00034
00035 #include <iostream>
00036 #include <map>
00037 #include <ros/ros.h>
00038 #include <boost/thread/mutex.hpp>
00039 #include <tf/tf.h>
00040 #include <tf/transform_listener.h>
00041 #include <message_filters/subscriber.h>
00042 #include <tf/message_filter.h>
00043 #include <tf/transform_datatypes.h>
00044 #include <kdl/chain.hpp>
00045 #include <kdl/frames.hpp>
00046 #include <kdl/chainjnttojacsolver.hpp>
00047 #include <angles/angles.h>
00048 #include <sbpl_arm_planner_node/visualize_arm.h>
00049
00051 #include <geometry_msgs/Pose.h>
00052 #include <mapping_msgs/CollisionMap.h>
00053 #include <mapping_msgs/AttachedCollisionObject.h>
00054 #include <motion_planning_msgs/GetMotionPlan.h>
00055 #include <trajectory_msgs/JointTrajectoryPoint.h>
00056 #include <kinematics_msgs/GetPositionIK.h>
00057 #include <kinematics_msgs/GetPositionFK.h>
00058
00059 namespace sbpl_arm_planner
00060 {
00061 class SBPLArmPlannerNode
00062 {
00063 public:
00065 SBPLArmPlannerNode();
00066
00067 ~SBPLArmPlannerNode();
00068
00070 bool init();
00071
00073 int run();
00074
00076 bool planKinematicPath(motion_planning_msgs::GetMotionPlan::Request &req, motion_planning_msgs::GetMotionPlan::Response &res);
00077
00078 private:
00079
00080 ros::NodeHandle node_handle_, root_handle_;
00081 ros::ServiceServer planning_service_;
00082 ros::Subscriber object_subscriber_;
00083 message_filters::Subscriber<mapping_msgs::CollisionMap> collision_map_subscriber_;
00084 tf::MessageFilter<mapping_msgs::CollisionMap> *collision_map_filter_;
00085
00086
00087 ros::Subscriber collision_object_subscriber_;
00088 void collisionObjectCallback(const mapping_msgs::CollisionObjectConstPtr &collision_object);
00089 std::vector<std::vector<double> > col_objects_;
00090
00092 KDL::ChainFkSolverPos_recursive *jnt_to_pose_solver_;
00093
00095 std::string fk_service_name_;
00096
00098 std::string ik_service_name_;
00099
00101 std::string side_;
00102
00104 double allocated_time_;
00105
00108 double waypoint_time_;
00109
00110 double env_resolution_;
00111
00112
00113 bool forward_search_;
00114 bool search_mode_;
00115 bool visualize_expanded_states_;
00116 bool visualize_heuristic_;
00117 bool visualize_goal_;
00118 bool planner_initialized_;
00119 bool print_path_;
00120 bool visualize_trajectory_;
00121 bool visualize_collision_model_trajectory_;
00122 bool use_research_heuristic_;
00123 bool use_first_solution_;
00124 bool attached_object_;
00125 int throttle_;
00126 int num_joints_;
00127
00128 std::string collision_map_topic_;
00129 std::string robot_description_;
00130 std::string node_name_;
00131 std::string reference_frame_;
00132 std::string map_frame_;
00133 std::string planning_joint_;
00134 std::string arm_name_;
00135 std::string trajectory_type_;
00136 std::string arm_description_filename_;
00137 std::string mprims_filename_;
00138 std::string attached_object_frame_;
00139 std::vector<std::string> joint_names_;
00140 std::vector<std::vector<double> > dpath_;
00141 std::map<std::string, mapping_msgs::CollisionObject> object_map_;
00142
00143
00144 MDPConfig mdp_cfg_;
00145 EnvironmentROBARM3D sbpl_arm_env_;
00146 SBPLPlanner *planner_;
00147 SBPLCollisionSpace* cspace_;
00148 OccupancyGrid* grid_;
00149 VisualizeArm* aviz_;
00150
00151 boost::mutex colmap_mutex_;
00152 boost::mutex object_mutex_;
00153
00154
00155 tf::TransformListener tf_;
00156 tf::StampedTransform transform_;
00157 KDL::Chain arm_chain_;
00158 KDL::JntArray jnt_pos_;
00159 KDL::Frame kdl_transform_;
00160
00162 bool initializePlannerAndEnvironment();
00163
00165 bool setStart(const sensor_msgs::JointState &start_state);
00166
00168 bool setGoalPosition(const motion_planning_msgs::Constraints &goals);
00169
00171 void updateMapFromCollisionMap(const mapping_msgs::CollisionMapConstPtr &collision_map);
00172
00176 void collisionMapCallback(const mapping_msgs::CollisionMapConstPtr &collision_map);
00177
00178 void attachedObjectCallback(const mapping_msgs::AttachedCollisionObjectConstPtr &attached_object);
00179
00180 void attachObject(const mapping_msgs::CollisionObject &obj);
00181
00183 bool planToPosition(motion_planning_msgs::GetMotionPlan::Request &req, motion_planning_msgs::GetMotionPlan::Response &res);
00184
00186 bool plan(std::vector<trajectory_msgs::JointTrajectoryPoint> &arm_path);
00187
00189 bool isGoalConstraintSatisfied(const std::vector<double> &angles, const motion_planning_msgs::Constraints &goal);
00190
00192 bool computeIK(const geometry_msgs::Pose &pose_stamped_msg, std::vector<double> jnt_pos, std::vector<double> &solution);
00193
00195 bool computeFK(const std::vector<double> &jnt_pos, geometry_msgs::Pose &pose);
00196
00198 void computeFKwithKDL(const std::vector<double> &jnt_pos, geometry_msgs::Pose &pose, int joint_num);
00199
00201 bool initChain(std::string robot_description);
00202
00204 void visualizeGoalPosition(const motion_planning_msgs::Constraints &goal);
00205
00206
00207 void visualizeElbowPoses();
00208
00210 void displayShortestPath();
00211
00213 void printPath(FILE* fOut, const std::vector<std::vector<double> > path);
00214
00220 void printPath(const std::vector<trajectory_msgs::JointTrajectoryPoint> &arm_path);
00221
00223 void setArmToMapTransform(std::string &map_frame);
00224
00226 void displayARAStarStates();
00227
00228
00229 void visualizeAttachedObject(trajectory_msgs::JointTrajectory &traj_msg, int throttle);
00230
00231
00232 void visualizeAttachedObject(const std::vector<double> &angles);
00233
00235 void visualizeCollisionObjects();
00236 };
00237 }
00238
00239 #endif