SMACC
Loading...
Searching...
No Matches
cb_move_joints.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#include <future>
9
11{
12 CbMoveJoints::CbMoveJoints(const std::map<std::string, double> &jointValueTarget) : jointValueTarget_(jointValueTarget)
13 {
14 }
15
17 {
18 }
19
21 {
23
24 if (this->group_)
25 {
26 moveit::planning_interface::MoveGroupInterface move_group(*(this->group_));
27 this->moveJoints(move_group);
28 }
29 else
30 {
32 }
33 }
34
35 std::string currentJointStatesToString(moveit::planning_interface::MoveGroupInterface &moveGroupInterface, std::map<std::string, double>& targetJoints)
36 {
37 auto state = moveGroupInterface.getCurrentState();
38 auto vnames = state->getVariableNames();
39
40 std::stringstream ss;
41
42 for(auto& tgj: targetJoints)
43 {
44 auto it = std::find(vnames.begin(),vnames.end(), tgj.first);
45 auto index = std::distance(vnames.begin(), it);
46
47 ss << tgj.first << ":" << state->getVariablePosition(index) << std::endl;
48 }
49
50 return ss.str();
51 }
52
53 void CbMoveJoints::moveJoints(moveit::planning_interface::MoveGroupInterface &moveGroupInterface)
54 {
56 moveGroupInterface.setMaxVelocityScalingFactor(*scalingFactor_);
57
58 bool success;
59 moveit::planning_interface::MoveGroupInterface::Plan computedMotionPlan;
60
61 if (jointValueTarget_.size() == 0)
62 {
63 ROS_WARN("[CbMoveJoints] No joint was value specified. Skipping planning call.");
64 success = false;
65 }
66 else
67 {
68 moveGroupInterface.setJointValueTarget(jointValueTarget_);
69 //moveGroupInterface.setGoalJointTolerance(0.01);
70 success = (moveGroupInterface.plan(computedMotionPlan) == moveit::core::MoveItErrorCode::SUCCESS);
71 ROS_INFO_NAMED("CbMoveJoints", "Success Visualizing plan 1 (pose goal) %s", success ? "" : "FAILED");
72 }
73
74 if (success)
75 {
76 auto executionResult = moveGroupInterface.execute(computedMotionPlan);
77
78 auto statestr = currentJointStatesToString(moveGroupInterface, jointValueTarget_);
79
80 if (executionResult == moveit_msgs::MoveItErrorCodes::SUCCESS)
81 {
82 ROS_INFO_STREAM("[" << this->getName() << "] motion execution succeeded. Throwing success event. " << std::endl
83 << statestr);
85 this->postSuccessEvent();
86 }
87 else
88 {
89 ROS_WARN_STREAM("[" << this->getName() << "] motion execution failed. Throwing fail event." << std::endl
90 << statestr);
92 this->postFailureEvent();
93 }
94 }
95 else
96 {
97 auto statestr = currentJointStatesToString(moveGroupInterface, jointValueTarget_);
98 ROS_WARN_STREAM("[" << this->getName() << "] motion execution failed. Throwing fail event." << std::endl << statestr);
100 this->postFailureEvent();
101 }
102 }
103
105 {
106 }
107} // namespace cl_move_group_interface
boost::optional< double > scalingFactor_
std::map< std::string, double > jointValueTarget_
void moveJoints(moveit::planning_interface::MoveGroupInterface &moveGroupInterface)
boost::optional< std::string > group_
moveit::planning_interface::MoveGroupInterface moveGroupClientInterface
Definition: cl_movegroup.h:74
void requiresClient(SmaccClientType *&storage)
std::string currentJointStatesToString(moveit::planning_interface::MoveGroupInterface &moveGroupInterface, std::map< std::string, double > &targetJoints)