|
| 1 | +// ROS |
| 2 | +#include <ros/ros.h> |
| 3 | +#include <cmath> |
| 4 | +#include <moveit/move_group_interface/move_group_interface.h> |
| 5 | +#include <moveit/planning_scene_interface/planning_scene_interface.h> |
| 6 | +#include <tf2_geometry_msgs/tf2_geometry_msgs.h> |
| 7 | +#include <tf2/LinearMath/Quaternion.h> |
| 8 | +#include <visualization_msgs/Marker.h> |
| 9 | +#include <Eigen/Geometry> |
| 10 | +#include <geometry_msgs/Quaternion.h> |
| 11 | +#include <geometry_msgs/Point.h> |
| 12 | +#include <tf2_eigen/tf2_eigen.h> |
| 13 | +#include <sensor_msgs/JointState.h> |
| 14 | +#include <geometry_msgs/Pose.h> |
| 15 | + |
| 16 | +namespace pnp |
| 17 | +{ |
| 18 | + // This class contains all the functions needed to perform the pick and place operation |
| 19 | + class PickandPlace |
| 20 | + { |
| 21 | + private: |
| 22 | + ros::Publisher pose_point_pub; |
| 23 | + // Set global parameters of panda arm |
| 24 | + const std::vector<double> OPEN_GRIPPER = {0.035, 0.035}; |
| 25 | + const std::vector<double> CLOSE_GRIPPER = {0.011, 0.011}; |
| 26 | + const double end_effector_palm_length = 0.058 * 1.8; // 1.4 is padding |
| 27 | + |
| 28 | + // Map is the python equivalent of a dictionary |
| 29 | + const std::map<std::string, double> box1 = { |
| 30 | + {"x_pos", 0.6}, {"y_pos", 0.2}, {"z_height", 0.2}}; |
| 31 | + const std::map<std::string, double> box2 = { |
| 32 | + {"x_pos", 0}, {"y_pos", 0.6}, {"z_height", 0.1}}; |
| 33 | + const double rod_height = 0.2; |
| 34 | + |
| 35 | + // MoveIt operates on sets of joints called "planning groups" and stores them in an object called |
| 36 | + // the `JointModelGroup`. Throughout MoveIt the terms "planning group" and "joint model group" |
| 37 | + // are used interchangeably. |
| 38 | + const std::string PLANNING_GROUP_ARM = "panda_arm"; |
| 39 | + const std::string PLANNING_GROUP_GRIPPER = "panda_hand"; |
| 40 | + |
| 41 | + moveit::planning_interface::MoveGroupInterface move_group_interface_arm; |
| 42 | + moveit::planning_interface::MoveGroupInterface move_group_interface_gripper; |
| 43 | + |
| 44 | + // Create a moveit::planning_interface::MoveGroupInterface::Plan object to store the movements |
| 45 | + moveit::planning_interface::MoveGroupInterface::Plan plan; |
| 46 | + |
| 47 | + // planning_scene_interface allows us to add and remove collision objects in the world |
| 48 | + moveit::planning_interface::PlanningSceneInterface planning_scene_interface; |
| 49 | + |
| 50 | + const robot_state::JointModelGroup *joint_model_group_arm; |
| 51 | + const robot_state::JointModelGroup *joint_model_group_gripper; |
| 52 | + |
| 53 | + std::vector<double> floor_dimensions = {2.5, 2.5, 0.01}; |
| 54 | + std::vector<double> floor_position = {0.0, 0.0, -0.01}; |
| 55 | + |
| 56 | + std::vector<double> box1_dimensions = {0.2, 0.4, box1.at("z_height")}; |
| 57 | + std::vector<double> box1_position = {box1.at("x_pos"), box1.at("y_pos"), box1.at("z_height") / 2.0}; |
| 58 | + |
| 59 | + // empty vector to be filled with the joint values of the robot |
| 60 | + std::vector<double> home_joint_values; |
| 61 | + |
| 62 | + public: |
| 63 | + PickandPlace(ros::NodeHandle &nh); |
| 64 | + void writeRobotDetails(void); |
| 65 | + void createCollisionObject(std::string id, std::vector<double> dimensions, std::vector<double> position, double rotation_z); |
| 66 | + void createCollisionScene(void); |
| 67 | + void clean_scene(void); |
| 68 | + void set_pose_target(std::vector<double> translation, std::vector<double> rotation); |
| 69 | + void add_pose_arrow(geometry_msgs::Point desired_position, float z_rotation); |
| 70 | + std::vector<double> get_rod_position(void); |
| 71 | + void pick(void); |
| 72 | + void run(void); |
| 73 | + }; |
| 74 | +}; |
0 commit comments