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)
47 : targetObjectName_(std::move(targetObjectName))
48 {
49 }
50
54 inline CbAttachObject() {}
55
56 template <typename TOrthogonal, typename TSourceObject>
62
70 inline void onEntry() override
71 {
72 // components resolved in onStateOrthogonalAllocation
73 auto * cpMoveGroup = cpMoveGroup_;
74 auto * graspingComponent = graspingComponent_;
75
76 moveit_msgs::msg::CollisionObject targetCollisionObject;
77 bool found = graspingComponent->getGraspingObject(targetObjectName_, targetCollisionObject);
78
79 if (found)
80 {
81 RCLCPP_INFO_STREAM(getLogger(), "[CbAttachObject] Attaching object: " << targetObjectName_);
82
83 targetCollisionObject.operation = moveit_msgs::msg::CollisionObject::ADD;
84 targetCollisionObject.header.stamp = getNode()->now();
85
86 cpMoveGroup->planningSceneInterface->applyCollisionObject(targetCollisionObject);
87 graspingComponent->currentAttachedObjectName = targetObjectName_;
88
89 cpMoveGroup->moveGroupClientInterface->attachObject(
90 targetObjectName_, graspingComponent->gripperLink_, graspingComponent->fingerTipNames);
91
92 this->postSuccessEvent();
93 }
94 else
95 {
96 RCLCPP_ERROR_STREAM(
97 getLogger(),
98 "[CbAttachObject] Object not found in grasping component: " << targetObjectName_);
99 this->postFailureEvent();
100 }
101 }
102
106 inline void onExit() override {}
107
109 std::string targetObjectName_;
110
111private:
113};
114
115} // namespace cl_moveit2z
Client behavior that attaches a collision object to the robot gripper.
void onEntry() override
Called when the behavior is entered.
cl_moveit2z::CpGraspingComponent * graspingComponent_
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.
bool getGraspingObject(const std::string &name, moveit_msgs::msg::CollisionObject &object)
virtual rclcpp::Logger getLogger() const
virtual rclcpp::Node::SharedPtr getNode() const
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)