SMACC2
Loading...
Searching...
No Matches
cb_detach_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 <smacc2/smacc.hpp>
27
28namespace cl_moveit2z
29{
39{
40public:
47 inline void onEntry() override
48 {
49 cl_moveit2z::CpGraspingComponent * graspingComponent;
50 this->requiresComponent(graspingComponent);
51
53 this->requiresComponent(cpMoveGroup);
54
55 if (graspingComponent->currentAttachedObjectName)
56 {
57 RCLCPP_INFO_STREAM(
58 getLogger(),
59 "[CbDetachObject] Detaching object: " << *(graspingComponent->currentAttachedObjectName));
60
61 auto & planningSceneInterface = cpMoveGroup->planningSceneInterface;
62 auto res = cpMoveGroup->moveGroupClientInterface->detachObject(
63 *(graspingComponent->currentAttachedObjectName));
64
65 planningSceneInterface->removeCollisionObjects(
66 {*(graspingComponent->currentAttachedObjectName)});
67
68 if (res)
69 {
70 RCLCPP_INFO(getLogger(), "[CbDetachObject] Detach succeeded");
71 this->postSuccessEvent();
72 }
73 else
74 {
75 RCLCPP_ERROR(getLogger(), "[CbDetachObject] Detach failed");
76 this->postFailureEvent();
77 }
78 }
79 else
80 {
81 RCLCPP_ERROR(getLogger(), "[CbDetachObject] No object currently attached");
82 this->postFailureEvent();
83 }
84 }
85
89 inline void onExit() override {}
90};
91
92} // namespace cl_moveit2z
Client behavior that detaches the currently attached collision object.
void onExit() override
Called when the behavior is exited.
void onEntry() override
Called when the behavior is entered.
std::optional< std::string > currentAttachedObjectName
std::shared_ptr< moveit::planning_interface::MoveGroupInterface > moveGroupClientInterface
std::shared_ptr< moveit::planning_interface::PlanningSceneInterface > planningSceneInterface
virtual rclcpp::Logger getLogger() const
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)