00001
00002
00003 #include <string>
00004 #include <fstream>
00005 #include <stdlib.h>
00006 #include <ros/ros.h>
00007 #include <math.h>
00008 #include <actionlib/client/simple_action_client.h>
00009 #include <geometry_msgs/PoseStamped.h>
00010 #include <geometry_msgs/Vector3.h>
00011
00012 #include <tf/tf.h>
00013 #include <move_arm_msgs/MoveArmAction.h>
00014 #include <move_arm_msgs/utils.h>
00015 #include <pr2_controllers_msgs/JointTrajectoryAction.h>
00016 #include <actionlib/client/simple_action_client.h>
00017 #include <visualization_msgs/MarkerArray.h>
00018 #include <visualization_msgs/Marker.h>
00019 #include <boost/lexical_cast.hpp>
00020 #include <motion_planning_msgs/DisplayTrajectory.h>
00021 #include <planning_environment/monitors/joint_state_monitor.h>
00022 #include <kinematics_msgs/GetPositionIK.h>
00023 #include <kinematics_msgs/GetPositionFK.h>
00024 #include <kdl_parser/kdl_parser.hpp>
00025 #include <kdl/jntarray.hpp>
00026 #include <kdl/chainfksolverpos_recursive.hpp>
00027 #include <kdl/chain.hpp>
00028 #include <kdl/frames.hpp>
00029 #include <kdl/treefksolverpos_recursive.hpp>
00030
00031 #include <sbpl_arm_planner/robarm3d/environment_robarm3d.h>
00032
00033 typedef actionlib::SimpleActionClient< pr2_controllers_msgs::JointTrajectoryAction > TrajClient;
00034
00035 namespace sbpl_arm_planner{
00036
00037 class VisualizeArm
00038 {
00039 public:
00040
00041 VisualizeArm(std::string arm_name);
00042
00043 ~VisualizeArm();
00044
00045
00046 void setReferenceFrame(std::string &frame);
00047
00048
00049 void sendArmToConfiguration(const std::vector<double> &angles);
00050
00051
00052
00053
00054 void displayArmConfiguration(std::vector<double> angles);
00055
00056
00057 bool initKDLChain();
00058
00059
00060 bool computeFKforVisualizationWithKDL(const std::vector<double> &jnt_pos, std::vector<geometry_msgs::PoseStamped> &poses);
00061
00062
00063 bool computeFKwithKDL(const std::vector<double> angles, int frame_num, geometry_msgs::Pose &pose);
00064
00065
00066 bool computeFKforVisualization(const std::vector<double> &jnt_pos, std::vector<geometry_msgs::PoseStamped> &poses);
00067
00068
00069 void visualizeArmConfiguration(double color_num, const std::vector<double> &jnt_pos);
00070
00071
00072 void visualizeArmMeshes(double color_num, std::vector<geometry_msgs::PoseStamped> &poses);
00073
00074
00075 void visualizePose(const std::vector<double> &pose, std::string text);
00076
00077 void visualizePose(const geometry_msgs::Pose &pose, std::string text);
00078
00079
00080 void visualizePoses(const std::vector<std::vector<double> > &poses);
00081
00082
00083 void visualizeTrajectoryFile(std::string filename, int throttle);
00084
00085
00086 void visualizeEnvironment(std::string filename);
00087
00088
00089 void visualizeObstacles(const std::vector<std::vector<double> > &obstacles);
00090
00091 void visualize3DPath(std::vector<std::vector<double> > &dpath);
00092
00093
00094 bool parseCSVFile(std::string filename, int num_cols, std::vector<std::vector<double> > &data);
00095
00096
00097
00098 bool parsePoseFile(std::string filename, std::vector<std::vector<double> > &poses);
00099
00100
00101 bool parseEnvironmentFile(std::string filename);
00102
00103
00104
00105 void visualizeArmConfigurations(const std::vector<std::vector<double> > &traj, int throttle);
00106
00107
00108 void visualizeJointTrajectoryMsg(trajectory_msgs::JointTrajectory traj_msg, int throttle);
00109
00110
00111 void printEnvironmentInfo(FILE *fid);
00112
00113
00114 void visualizeCollisionModel(const std::vector<std::vector<double> > &path, sbpl_arm_planner::SBPLCollisionSpace &cspace, int throttle);
00115
00116
00117 void visualizeCollisionModelFromJointTrajectoryMsg(trajectory_msgs::JointTrajectory &traj_msg, sbpl_arm_planner::SBPLCollisionSpace &cspace, int throttle);
00118
00119
00120 void visualizeGripperConfiguration(double color_num, const std::vector<double> &jnt_pos);
00121
00122
00123 void visualizeGripperMeshes(double color_num, std::vector<geometry_msgs::PoseStamped> &poses);
00124
00125
00126 void visualizeBasicStates(const std::vector<std::vector<double> > &states, const std::vector<double> &color, std::string name, double size);
00127
00128
00129 void visualizeDetailedStates(const std::vector<std::vector<double> > &states, const std::vector<std::vector<double> >&color, std::string name, double size);
00130
00131
00132 void visualizeSphere(std::vector<double> pose, int color, std::string text, double radius);
00133
00134
00135 void visualizeSpheres(const std::vector<std::vector<double> > &pose, int color, std::string text, double radius);
00136
00137
00138 void visualizeAttachedObject(const std::vector<double> angles);
00139
00140
00141
00142
00143 private:
00144
00145 ros::NodeHandle nh_;
00146 ros::NodeHandle ph_;
00147 ros::Publisher marker_array_publisher_;
00148 ros::Publisher marker_publisher_;
00149 ros::Publisher display_trajectory_publisher_;
00150
00151 std::string reference_frame_;
00152
00153 planning_environment::JointStateMonitor joint_state_monitor_;
00154
00155 TrajClient* traj_client_;
00156
00157 int num_joints_;
00158
00159 visualization_msgs::MarkerArray marker_array_;
00160 visualization_msgs::Marker marker_;
00161
00162 std::vector<std::string> joint_names_;
00163 std::vector<std::string> link_names_;
00164 std::vector<std::string> pr2_arm_meshes_;
00165 std::vector<std::string> pr2_gripper_meshes_;
00166 std::vector<geometry_msgs::Vector3> pr2_arm_meshes_scale_;
00167
00168 KDL::JntArray jnt_pos_in_;
00169 KDL::JntArray jnt_pos_out_;
00170 KDL::Frame p_out_;
00171 KDL::Chain chain_;
00172 KDL::Chain gripper_l_chain_;
00173 KDL::Chain gripper_r_chain_;
00174 KDL::ChainFkSolverPos_recursive *fk_solver_;
00175 KDL::ChainFkSolverPos_recursive *gripper_l_fk_solver_;
00176 KDL::Tree kdl_tree_;
00177
00178 std::string arm_name_;
00179 std::string arm_config_file_;
00180 std::string side_;
00181 std::string side_full_;
00182 std::string fk_service_name_;
00183 std::string ik_service_name_;
00184 std::string chain_root_name_;
00185 std::string chain_tip_name_;
00186
00187 std::vector<double> start_config_;
00188 std::vector<double> goal_pose_;
00189 std::vector<std::vector<double> > cubes_;
00190 double position_tolerance_;
00191 double orientation_tolerance_;
00192 bool goal_is_6dof_;
00193 };
00194
00195 }