Skip to content

Commit a614187

Browse files
author
Kai Thouard
committed
Merge branch 'main' of https://github.com/Splashed13/panda_moveit into main
2 parents 4e67738 + a152e33 commit a614187

File tree

6 files changed

+162
-148
lines changed

6 files changed

+162
-148
lines changed

CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ link_directories(${GAZEBO_LIBRARY_DIRS})
4646

4747
# catkin_package ensures that the libraries and executables created in the package are linked together
4848
catkin_package(
49+
INCLUDE_DIRS include
4950
LIBRARIES
5051
INCLUDE_DIRS
5152
CATKIN_DEPENDS
@@ -67,6 +68,7 @@ catkin_package(
6768

6869

6970
include_directories(
71+
include
7072
SYSTEM
7173
${catkin_INCLUDE_DIRS}
7274
${Boost_INCLUDE_DIR}
@@ -78,6 +80,6 @@ catkin_install_python(PROGRAMS scripts/pick_and_place.py
7880
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
7981

8082
# Cpp nodes for pick and place
81-
add_executable(pick_and_place scripts/pick_and_place.cpp)
83+
add_executable(pick_and_place src/main.cpp src/pick_and_place.cpp)
8284
target_link_libraries(pick_and_place ${catkin_LIBRARIES} ${Boost_LIBRARIES})
8385

README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ ROS package containing scripts utilizing MoveIt specifically MoveIt Commander in
66
Run by entering the following in a terminal
77

88
```
9-
roslaunch panda_moveit rvizsim.launch
9+
roslaunch panda_moveit run_sim.launch
1010
```
1111

12-
and then the following in another terminal
12+
and then the following in another terminal for the cpp code
1313

1414
```
15-
roslaunch panda_moveit pick_and_place.launch
15+
rosrun panda_moveit pick_and_place
16+
```
17+
18+
or for the python code
19+
20+
```
21+
rosrun panda_moveit pick_and_place.py
1622
```
1723

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
};

scripts/pick_and_place.py

100644100755
File mode changed.

src/main.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "panda_moveit/pick_and_place.hpp"
2+
int main(int argc, char **argv)
3+
{
4+
ros::init(argc, argv, "pick_and_place");
5+
ros::NodeHandle nh;
6+
7+
// ROS spinning must be running for the MoveGroupInterface to get information
8+
// about the robot's state. One way to do this is to start an AsyncSpinner
9+
// beforehand.
10+
ros::AsyncSpinner spinner(5);
11+
spinner.start();
12+
13+
// add a short sleep so the node can finish initializing
14+
ros::Duration(0.5).sleep();
15+
16+
// Instantiate the PickandPlace class
17+
pnp::PickandPlace pnp(nh);
18+
19+
// Run pick and place operations
20+
pnp.run();
21+
22+
// Shutdown the node and join the thread back before exiting
23+
ros::shutdown();
24+
25+
return 0;
26+
};

0 commit comments

Comments
 (0)