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
53 template <typename TOrthogonal, typename TSourceObject>
59
67 inline void onEntry() override
68 {
69 // components resolved in onStateOrthogonalAllocation
70 auto * cpMoveGroup = cpMoveGroup_;
71 auto * graspingComponent = graspingComponent_;
72
73 moveit_msgs::msg::CollisionObject targetCollisionObject;
74 bool found = graspingComponent->getGraspingObject(targetObjectName_, targetCollisionObject);
75
76 if (found)
77 {
78 RCLCPP_INFO_STREAM(getLogger(), "[CbAttachObject] Attaching object: " << targetObjectName_);
79
80 targetCollisionObject.operation = moveit_msgs::msg::CollisionObject::ADD;
81 targetCollisionObject.header.stamp = getNode()->now();
82
83 cpMoveGroup->planningSceneInterface->applyCollisionObject(targetCollisionObject);
84 graspingComponent->currentAttachedObjectName = targetObjectName_;
85
86 cpMoveGroup->moveGroupClientInterface->attachObject(
87 targetObjectName_, graspingComponent->gripperLink_, graspingComponent->fingerTipNames);
88
89 this->postSuccessEvent();
90 }
91 else
92 {
93 RCLCPP_ERROR_STREAM(
94 getLogger(),
95 "[CbAttachObject] Object not found in grasping component: " << targetObjectName_);
96 this->postFailureEvent();
97 }
98 }
99
103 inline void onExit() override {}
104
106 std::string targetObjectName_;
107
108private:
110};
111
112} // 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(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)