SMACC2
Loading...
Searching...
No Matches
cb_attach_object.hpp
Go to the documentation of this file.
1// Copyright 2025 Robosoft 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
26#include <moveit_msgs/msg/collision_object.hpp>
27#include <smacc2/smacc.hpp>
28
29namespace cl_moveit2z
30{
40{
41public:
46 inline CbAttachObject(std::string targetObjectName) : targetObjectName_(targetObjectName) {}
47
51 inline CbAttachObject() {}
52
60 inline void onEntry() override
61 {
63 this->requiresComponent(cpMoveGroup);
64
65 cl_moveit2z::CpGraspingComponent * graspingComponent;
66 this->requiresComponent(graspingComponent);
67
68 moveit_msgs::msg::CollisionObject targetCollisionObject;
69 bool found = graspingComponent->getGraspingObject(targetObjectName_, targetCollisionObject);
70
71 if (found)
72 {
73 RCLCPP_INFO_STREAM(getLogger(), "[CbAttachObject] Attaching object: " << targetObjectName_);
74
75 targetCollisionObject.operation = moveit_msgs::msg::CollisionObject::ADD;
76 targetCollisionObject.header.stamp = getNode()->now();
77
78 cpMoveGroup->planningSceneInterface->applyCollisionObject(targetCollisionObject);
80
81 cpMoveGroup->moveGroupClientInterface->attachObject(
82 targetObjectName_, graspingComponent->gripperLink_, graspingComponent->fingerTipNames);
83
84 this->postSuccessEvent();
85 }
86 else
87 {
88 RCLCPP_ERROR_STREAM(
89 getLogger(),
90 "[CbAttachObject] Object not found in grasping component: " << targetObjectName_);
91 this->postFailureEvent();
92 }
93 }
94
98 inline void onExit() override {}
99
101 std::string targetObjectName_;
102};
103
104} // 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::vector< std::string > fingerTipNames
std::optional< std::string > currentAttachedObjectName
bool getGraspingObject(std::string name, moveit_msgs::msg::CollisionObject &object)
std::shared_ptr< moveit::planning_interface::MoveGroupInterface > moveGroupClientInterface
std::shared_ptr< moveit::planning_interface::PlanningSceneInterface > planningSceneInterface
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)