27: jointValueTarget_(jointValueTarget)
31CbMoveJoints::CbMoveJoints() {}
33void CbMoveJoints::onEntry()
35 this->requiresClient(movegroupClient_);
39 moveit::planning_interface::MoveGroupInterface move_group(
40 getNode(), moveit::planning_interface::MoveGroupInterface::Options(*(this->group_)));
41 this->moveJoints(move_group);
45 this->moveJoints(*movegroupClient_->moveGroupClientInterface);
50 moveit::planning_interface::MoveGroupInterface & moveGroupInterface,
51 std::map<std::string, double> & targetJoints)
53 auto state = moveGroupInterface.getCurrentState();
55 if (state ==
nullptr)
return std::string();
57 auto vnames = state->getVariableNames();
61 for (
auto & tgj : targetJoints)
63 auto it = std::find(vnames.begin(), vnames.end(), tgj.first);
64 auto index = std::distance(vnames.begin(), it);
66 ss << tgj.first <<
":" << state->getVariablePosition(index) << std::endl;
72void CbMoveJoints::moveJoints(moveit::planning_interface::MoveGroupInterface & moveGroupInterface)
74 if (scalingFactor_) moveGroupInterface.setMaxVelocityScalingFactor(*scalingFactor_);
77 moveit::planning_interface::MoveGroupInterface::Plan computedMotionPlan;
79 if (jointValueTarget_.size() == 0)
82 getLogger(),
"[CbMoveJoints] No joint was value specified. Skipping planning call.");
87 moveGroupInterface.setJointValueTarget(jointValueTarget_);
90 auto result = moveGroupInterface.plan(computedMotionPlan);
92 success = (result == moveit::core::MoveItErrorCode::SUCCESS);
95 getLogger(),
"[CbMoveJoints] Execution plan result %s (%d)", success ?
"SUCCESS" :
"FAILED",
101 auto executionResult = moveGroupInterface.execute(computedMotionPlan);
105 if (executionResult == moveit_msgs::msg::MoveItErrorCodes::SUCCESS)
108 getLogger(),
"[" << this->getName()
109 <<
"] motion execution succeeded. Throwing success event. " << std::endl
112 movegroupClient_->postEventMotionExecutionSucceded();
113 this->postSuccessEvent();
119 "[" << this->getName() <<
"] motion execution failed. Throwing fail event." << std::endl
122 movegroupClient_->postEventMotionExecutionFailed();
123 this->postFailureEvent();
131 "[" << this->getName() <<
"] motion execution failed. Throwing fail event." << std::endl
134 movegroupClient_->postEventMotionExecutionFailed();
135 this->postFailureEvent();
139void CbMoveJoints::onExit() {}
std::string currentJointStatesToString(moveit::planning_interface::MoveGroupInterface &moveGroupInterface, std::map< std::string, double > &targetJoints)