Skip to content

Commit 6e5f494

Browse files
author
Kai Thouard
committed
Before attempt to encapsulate launch here
1 parent 64870f6 commit 6e5f494

File tree

4 files changed

+43
-33
lines changed

4 files changed

+43
-33
lines changed

include/panda_moveit/pick_and_place.hpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,15 @@ namespace pnp
3939
const std::string PLANNING_GROUP_ARM = "panda_arm";
4040
const std::string PLANNING_GROUP_GRIPPER = "panda_hand";
4141

42-
moveit::planning_interface::MoveGroupInterface move_group_interface_arm;
43-
moveit::planning_interface::MoveGroupInterface move_group_interface_gripper;
42+
std::unique_ptr<moveit::planning_interface::MoveGroupInterface> move_group_interface_arm;
43+
std::unique_ptr<moveit::planning_interface::MoveGroupInterface> move_group_interface_gripper;
4444

4545
// Create a moveit::planning_interface::MoveGroupInterface::Plan object to store the movements
4646
moveit::planning_interface::MoveGroupInterface::Plan plan;
4747

4848
// planning_scene_interface allows us to add and remove collision objects in the world
4949
moveit::planning_interface::PlanningSceneInterface planning_scene_interface;
5050

51-
const robot_state::JointModelGroup *joint_model_group_arm;
52-
const robot_state::JointModelGroup *joint_model_group_gripper;
5351

5452
std::vector<double> floor_dimensions = {2.5, 2.5, 0.01};
5553
std::vector<double> floor_position = {0.0, 0.0, -0.01};
@@ -154,6 +152,15 @@ namespace pnp
154152
*/
155153
void go_to_home_position(void);
156154

155+
/**
156+
* @brief Opens the gripper.
157+
*
158+
* This function uses MoveIt! to plan and execute a trajectory that moves the gripper from its current position to its open position.
159+
* A message is printed to the ROS console indicating whether the trajectory planning was successful or not.
160+
* If the plan is successful, the gripper is then moved to the open position.
161+
*
162+
* @note This function does not take any parameters and does not return a value.
163+
*/
157164
void open_gripper(void);
158165

159166
/**

launch/run_sim.launch

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@
5252
</group>
5353

5454
<!-- Run the main MoveIt executable without trajectory execution (we do not have controllers configured by default) -->
55-
<include file="$(find franka_gazebo)/launch/move_group.launch" pass_all_args="true">
55+
<include file="$(find panda_moveit_config)/launch/move_group.launch" pass_all_args="true">
5656
<arg name="allow_trajectory_execution" value="true" />
5757
<arg name="info" value="true" />
5858
</include>
5959

6060
<!-- Run Rviz and load the default config to see the state of the move_group node -->
61-
<include file="$(find franka_gazebo)/launch/moveit_rviz.launch" if="$(arg use_rviz)">
61+
<include file="$(find panda_moveit_config)/launch/moveit_rviz.launch" if="$(arg use_rviz)">
6262
<arg name="rviz_tutorial" value="$(arg rviz_tutorial)"/>
63-
<arg name="rviz_config" value="$(find franka_gazebo)/launch/moveit.rviz"/>
63+
<arg name="rviz_config" value="$(find panda_moveit_config)/launch/moveit.rviz"/>
6464
<arg name="debug" value="$(arg debug)"/>
6565
</include>
6666

6767
<!-- If database loading was enabled, start mongodb as well -->
68-
<include file="$(find franka_gazebo)/launch/default_warehouse_db.launch" if="$(arg db)">
68+
<include file="$(find panda_moveit_config)/launch/default_warehouse_db.launch" if="$(arg db)">
6969
<arg name="moveit_warehouse_database_path" value="$(arg db_path)"/>
7070
</include>
7171

package.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<depend>pluginlib</depend>
1818
<depend>eigen</depend>
1919
<depend>moveit_core</depend>
20+
2021
<depend>moveit_ros_planning</depend>
2122
<depend>moveit_ros_planning_interface</depend>
2223
<depend>moveit_ros_perception</depend>
@@ -43,10 +44,12 @@
4344
<depend>rviz</depend>
4445
<depend>xacro</depend>
4546
<depend>nodelet</depend>
46-
<depend>message_generation</depend>
47-
<depend>message_runtime</depend>
4847
<depend>geometry_msgs</depend>
4948

49+
50+
<build_depend>message_generation</build_depend>
51+
<exec_depend>message_runtime</exec_depend>
52+
5053
<export>
5154
<!-- Other tools can request additional information be placed here -->
5255
</export>

src/pick_and_place.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,48 @@
44
// Define the namespace to group related code together
55
namespace pnp
66
{
7-
PickandPlace::PickandPlace(ros::NodeHandle &nh) : move_group_interface_arm(PLANNING_GROUP_ARM), move_group_interface_gripper(PLANNING_GROUP_GRIPPER)
8-
{
7+
PickandPlace::PickandPlace(ros::NodeHandle &nh)
8+
{
99
// Set up a publisher for the pose point visualization marker
1010
pose_point_pub = nh.advertise<visualization_msgs::Marker>("pose_point", 10);
1111

12+
move_group_interface_arm = std::make_unique<moveit::planning_interface::MoveGroupInterface>(PLANNING_GROUP_ARM);
13+
move_group_interface_gripper = std::make_unique<moveit::planning_interface::MoveGroupInterface>(PLANNING_GROUP_GRIPPER);
14+
1215
// Set the planning time for the arm movement
1316
const double PLANNING_TIME = 15.0;
14-
move_group_interface_arm.setPlanningTime(PLANNING_TIME);
17+
move_group_interface_arm->setPlanningTime(PLANNING_TIME);
1518

16-
// Use raw pointers for performance. These point to the joint model groups for the arm and gripper
17-
joint_model_group_arm = move_group_interface_arm.getCurrentState()->getJointModelGroup(PLANNING_GROUP_ARM);
18-
joint_model_group_gripper = move_group_interface_gripper.getCurrentState()->getJointModelGroup(PLANNING_GROUP_GRIPPER);
1919
}
2020

2121
void PickandPlace::writeRobotDetails()
2222
{
2323
// Print out the planning frame for the arm
24-
ROS_INFO_NAMED("pnp", "Planning frame: %s", move_group_interface_arm.getPlanningFrame().c_str());
24+
ROS_INFO_NAMED("pnp", "Planning frame: %s", move_group_interface_arm->getPlanningFrame().c_str());
2525

2626
// Get the link names for the arm and concatenate them into a single string, then print
27-
std::vector<std::string> linkNames = move_group_interface_arm.getLinkNames();
27+
std::vector<std::string> linkNames = move_group_interface_arm->getLinkNames();
2828
std::string linkNamesArm = boost::algorithm::join(linkNames, ", ");
2929
ROS_INFO_NAMED("pnp", "Arm links: %s", linkNamesArm.c_str());
3030

3131
// Get the joint names for the arm and concatenate them into a single string, then print
32-
std::vector<std::string> jointNamesArm = move_group_interface_arm.getJoints();
32+
std::vector<std::string> jointNamesArm = move_group_interface_arm->getJoints();
3333
std::string jointNamesArmString = boost::algorithm::join(jointNamesArm, ", ");
3434
ROS_INFO_NAMED("pnp", "Arm joint names: %s", jointNamesArmString.c_str());
3535

3636
// Get the joint names for the gripper and concatenate them into a single string, then print
37-
std::vector<std::string> jointNamesGripper = move_group_interface_gripper.getJoints();
37+
std::vector<std::string> jointNamesGripper = move_group_interface_gripper->getJoints();
3838
std::string jointNamesGripperString = boost::algorithm::join(jointNamesGripper, ", ");
3939
ROS_INFO_NAMED("pnp", "Gripper joints names: %s", jointNamesGripperString.c_str());
4040

4141
// Get the list of all available planning groups, concatenate them into a single string, then print
42-
std::vector<std::string> planningGroups = move_group_interface_arm.getJointModelGroupNames();
42+
std::vector<std::string> planningGroups = move_group_interface_arm->getJointModelGroupNames();
4343
std::string planningGroupsString = boost::algorithm::join(planningGroups, ", ");
4444
ROS_INFO_NAMED("pnp", "Available Planning Groups: %s", planningGroupsString.c_str());
4545

4646

4747
// Get the home joint values and print them out
48-
home_joint_values = move_group_interface_arm.getCurrentJointValues();
48+
home_joint_values = move_group_interface_arm->getCurrentJointValues();
4949
std::string jointValuesString;
5050
for (const auto &joint : home_joint_values)
5151
{
@@ -184,10 +184,10 @@ namespace pnp
184184
add_pose_arrow(pose_target.position, rotation_rads[2]);
185185

186186
// set the pose target
187-
move_group_interface_arm.setPoseTarget(pose_target);
187+
move_group_interface_arm->setPoseTarget(pose_target);
188188

189189
// move to arm to the target pose
190-
bool success = (move_group_interface_arm.plan(plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
190+
bool success = (move_group_interface_arm->plan(plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
191191

192192
// print if the arm was able to move to the target pose
193193
ROS_INFO_NAMED("pnp", "Moving to pose target %s", success ? "" : "FAILED");
@@ -254,25 +254,25 @@ namespace pnp
254254
void PickandPlace::go_to_home_position()
255255
{
256256
// uses the home_joint_value variable to go to the home position of the robot
257-
move_group_interface_arm.setJointValueTarget(home_joint_values);
257+
move_group_interface_arm->setJointValueTarget(home_joint_values);
258258

259259
// move to arm to the target pose
260-
bool success = (move_group_interface_arm.plan(plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
260+
bool success = (move_group_interface_arm->plan(plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
261261

262262
// print if the arm was able to move to the target pose
263263
ROS_INFO_NAMED("pnp", "Moving to home position %s", success ? "" : "FAILED");
264264

265265
// move the arm to the target pose
266-
move_group_interface_arm.move();
266+
move_group_interface_arm->move();
267267

268268
}
269269

270270
void PickandPlace::open_gripper(){
271271
// Set the joint value target for the gripper
272-
move_group_interface_gripper.setJointValueTarget(OPEN_GRIPPER);
273-
bool success = (move_group_interface_gripper.plan(plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
272+
move_group_interface_gripper->setJointValueTarget(OPEN_GRIPPER);
273+
bool success = (move_group_interface_gripper->plan(plan) == moveit::planning_interface::MoveItErrorCode::SUCCESS);
274274
ROS_INFO_NAMED("pnp", "Opening gripper %s", success ? "" : "FAILED");
275-
move_group_interface_gripper.move();
275+
move_group_interface_gripper->move();
276276

277277
}
278278

@@ -298,17 +298,17 @@ namespace pnp
298298
set_pose_target(rod_position, {45, 90, 45});
299299

300300
// execute the plan
301-
move_group_interface_arm.move();
301+
move_group_interface_arm->move();
302302

303-
std::cout << "Press enter to continue...";
303+
ROS_INFO_NAMED("pnp", "Target Reached - Press any button to continue");
304304
std::cin.ignore();
305305

306306
// reset
307307
go_to_home_position();
308308
clean_scene();
309309
remove_pose_arrow();
310310

311-
std::cout << "Press enter to exit...";
311+
ROS_INFO_NAMED("pnp", "Simulation Complete - Press any button to exit");
312312
std::cin.ignore();
313313

314314
}

0 commit comments

Comments
 (0)