SMACC2
Loading...
Searching...
No Matches
cb_attach_object.hpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 *****************************************************************************************************************/
20
21#pragma once
22
25#include <moveit_msgs/msg/collision_object.hpp>
26#include <smacc2/smacc.hpp>
27
28namespace cl_moveit2z
29{
39{
40public:
45 inline CbAttachObject(std::string targetObjectName) : targetObjectName_(targetObjectName) {}
46
50 inline CbAttachObject() {}
51
59 inline void onEntry() override
60 {
61 cl_moveit2z::ClMoveit2z * moveGroup;
62 this->requiresClient(moveGroup);
63
64 cl_moveit2z::CpGraspingComponent * graspingComponent;
65 this->requiresComponent(graspingComponent);
66
67 moveit_msgs::msg::CollisionObject targetCollisionObject;
68 bool found = graspingComponent->getGraspingObject(targetObjectName_, targetCollisionObject);
69
70 if (found)
71 {
72 RCLCPP_INFO_STREAM(getLogger(), "[CbAttachObject] Attaching object: " << targetObjectName_);
73
74 targetCollisionObject.operation = moveit_msgs::msg::CollisionObject::ADD;
75 targetCollisionObject.header.stamp = getNode()->now();
76
77 moveGroup->planningSceneInterface->applyCollisionObject(targetCollisionObject);
79
80 moveGroup->moveGroupClientInterface->attachObject(
81 targetObjectName_, graspingComponent->gripperLink_, graspingComponent->fingerTipNames);
82
83 this->postSuccessEvent();
84 }
85 else
86 {
87 RCLCPP_ERROR_STREAM(
88 getLogger(),
89 "[CbAttachObject] Object not found in grasping component: " << targetObjectName_);
90 this->postFailureEvent();
91 }
92 }
93
97 inline void onExit() override {}
98
100 std::string targetObjectName_;
101};
102
103} // namespace cl_moveit2z
Client behavior that attaches a collision object to the robot gripper.
void onEntry() override
Called when the behavior is entered.
std::string targetObjectName_
Name of the target object to attach.
void onExit() override
Called when the behavior is exited.
CbAttachObject()
Default constructor.
CbAttachObject(std::string targetObjectName)
Constructor with object name.
std::shared_ptr< moveit::planning_interface::MoveGroupInterface > moveGroupClientInterface
std::shared_ptr< moveit::planning_interface::PlanningSceneInterface > planningSceneInterface
std::vector< std::string > fingerTipNames
std::optional< std::string > currentAttachedObjectName
bool getGraspingObject(std::string name, moveit_msgs::msg::CollisionObject &object)
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const
void requiresClient(SmaccClientType *&storage)
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)