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