SMACC
Loading...
Searching...
No Matches
cb_move_cartesian_relative.cpp
Go to the documentation of this file.
1/*****************************************************************************************************************
2 * ReelRobotix Inc. - Software License Agreement Copyright (c) 2018-2020
3 * Authors: Pablo Inigo Blasco, Brett Aldrich
4 *
5 ******************************************************************************************************************/
6
8
10{
12{
13}
14
15CbMoveCartesianRelative::CbMoveCartesianRelative(geometry_msgs::Vector3 offset) : offset_(offset)
16{
17}
18
20{
22
23 if (this->group_)
24 {
25 moveit::planning_interface::MoveGroupInterface move_group(*(this->group_));
26 this->moveRelativeCartesian(&move_group, offset_);
27 }
28 else
29 {
31 }
32}
33
35{
36
37}
38
39// keeps the end efector orientation fixed
40void CbMoveCartesianRelative::moveRelativeCartesian(moveit::planning_interface::MoveGroupInterface *movegroupClient,
41 geometry_msgs::Vector3 &offset)
42{
43 std::vector<geometry_msgs::Pose> waypoints;
44
45 // this one was working fine but the issue is that for relative motions it grows up on ABORT-State-Loop pattern.
46 // But, we need current pose because maybe setCurrentPose was not set by previous behaviors. The only solution would be
47 // distinguishing between the execution error and the planning error with no state change
48 //auto referenceStartPose = movegroupClient->getPoseTarget();
49 auto referenceStartPose = movegroupClient->getCurrentPose();
50 movegroupClient->setPoseReferenceFrame(referenceStartPose.header.frame_id);
51
52 ROS_INFO_STREAM("[CbMoveCartesianRelative] RELATIVE MOTION, SOURCE POSE: " << referenceStartPose);
53 ROS_INFO_STREAM("[CbMoveCartesianRelative] Offset: " << offset);
54
55 waypoints.push_back(referenceStartPose.pose); // up and out
56
57 auto endPose = referenceStartPose.pose;
58
59 endPose.position.x += offset.x;
60 endPose.position.y += offset.y;
61 endPose.position.z += offset.z;
62
63 ROS_INFO_STREAM("[CbMoveCartesianRelative] DESTINY POSE: " << endPose);
64
65 // target_pose2.position.x -= 0.15;
66 waypoints.push_back(endPose); // left
67
68 movegroupClient->setPoseTarget(endPose);
69
70 float scalinf = 0.5;
72 scalinf = *scalingFactor_;
73
74 ROS_INFO_STREAM("[CbMoveCartesianRelative] Using scaling factor: " << scalinf);
75 movegroupClient->setMaxVelocityScalingFactor(scalinf);
76
77 moveit_msgs::RobotTrajectory trajectory;
78 double fraction = movegroupClient->computeCartesianPath(waypoints,
79 0.01, // eef_step
80 0.00, // jump_threshold
81 trajectory);
82
83 moveit::core::MoveItErrorCode behaviorResult;
84 if (fraction != 1.0 || fraction == -1)
85 {
86 ROS_WARN_STREAM("[CbMoveCartesianRelative] Cartesian plan joint-continuity percentaje. Execution skipped because not 100% of cartesian motion: " << fraction*100<<"%");
87 behaviorResult = moveit::core::MoveItErrorCode::PLANNING_FAILED;
88 }
89 else
90 {
91 ROS_INFO_STREAM("[CbMoveCartesianRelative] Cartesian plan joint-continuity percentaje: " << fraction);
92
93 moveit::planning_interface::MoveGroupInterface::Plan grasp_pose_plan;
94
95 // grasp_pose_plan.start_state_ = *(moveGroupInterface.getCurrentState());
96 grasp_pose_plan.trajectory_ = trajectory;
97 behaviorResult = movegroupClient->execute(grasp_pose_plan);
98 }
99
100 if (behaviorResult == moveit_msgs::MoveItErrorCodes::SUCCESS)
101 {
102 ROS_INFO("[CbMoveCartesianRelative] relative motion execution succeeded: fraction %lf.", fraction);
104 this->postSuccessEvent();
105 }
106 else
107 {
108 movegroupClient->setPoseTarget(referenceStartPose); // undo changes since we did not executed the motion
109 ROS_INFO("[CbMoveCartesianRelative] relative motion execution failed: fraction %lf.", fraction);
111 this->postFailureEvent();
112 }
113}
114} // namespace cl_move_group_interface
void moveRelativeCartesian(moveit::planning_interface::MoveGroupInterface *movegroupClient, geometry_msgs::Vector3 &offset)
moveit::planning_interface::MoveGroupInterface moveGroupClientInterface
Definition: cl_movegroup.h:74
void requiresClient(SmaccClientType *&storage)