SMACC2
Loading...
Searching...
No Matches
cb_move_to_pose.hpp
Go to the documentation of this file.
1// Copyright 2026 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: Brett Aldrich
18 *
19 *****************************************************************************************************************/
20
21#pragma once
22
23#include <optional>
24#include <string>
25
27#include <geometry_msgs/msg/pose_stamped.hpp>
28
29namespace cl_moveit2z
30{
31
33{
34 geometry_msgs::msg::PoseStamped pose; // of the tip link, in the frame of its header
35 std::string tipLink; // empty: the end effector link of the client's group
36 double velocityScaling = 1.0; // fraction of the joint velocity limits
37 double accelerationScaling = 1.0; // fraction of the joint acceleration limits
38 double planningTime = 1.0; // s
39};
40
41// Moves the tip link of its client's planning group to a pose: one plan, then its execution.
42// Without parameters it does nothing and posts no event, so one can stand idle on an orthogonal.
44{
45public:
46 CbMoveToPose() = default;
47
48 explicit CbMoveToPose(const MoveToPoseParams & params) : params_(params) {}
49
50 void setParams(const MoveToPoseParams & params) { params_ = params; }
51
52 void onEntry() override
53 {
54 if (!params_)
55 {
56 RCLCPP_INFO(getLogger(), "[CbMoveToPose] no pose given: idle");
57 return;
58 }
59 if (cpMotionPlanner_ == nullptr)
60 {
61 RCLCPP_ERROR(getLogger(), "[CbMoveToPose] the client has no CpMotionPlanner");
62 this->postMotionFailure();
63 return;
64 }
65
66 PlanningOptions options;
67 options.planningTime = params_->planningTime;
68 options.maxVelocityScaling = params_->velocityScaling;
69 options.maxAccelerationScaling = params_->accelerationScaling;
70 const std::optional<std::string> tipLink =
71 params_->tipLink.empty() ? std::nullopt : std::optional<std::string>(params_->tipLink);
72
73 const auto planned = cpMotionPlanner_->planToPose(params_->pose, tipLink, options);
74 if (!planned.success)
75 {
76 RCLCPP_WARN(getLogger(), "[CbMoveToPose] no plan: %s", planned.errorMessage.c_str());
77 this->postMotionFailure();
78 return;
79 }
80
81 bool executed = false;
82 if (cpTrajectoryExecutor_ != nullptr)
83 {
84 ExecutionOptions executionOptions;
85 executionOptions.trajectoryName = this->getName();
86 executed = cpTrajectoryExecutor_->executePlan(planned.plan, executionOptions).success;
87 }
88 else
89 {
90 executed = cpMoveGroup_->moveGroupClientInterface->execute(planned.plan) ==
91 moveit::core::MoveItErrorCode::SUCCESS;
92 }
93
94 if (executed)
95 {
96 this->postMotionSuccess();
97 }
98 else
99 {
100 RCLCPP_WARN(getLogger(), "[CbMoveToPose] the execution failed");
101 this->postMotionFailure();
102 }
103 }
104
105private:
106 std::optional<MoveToPoseParams> params_;
107};
108
109} // namespace cl_moveit2z
CbMoveToPose(const MoveToPoseParams &params)
void setParams(const MoveToPoseParams &params)
std::optional< MoveToPoseParams > params_
PlanningResult planToPose(const geometry_msgs::msg::PoseStamped &target, const std::optional< std::string > &tipLink=std::nullopt, const PlanningOptions &options={})
Plan to a Cartesian pose.
std::shared_ptr< moveit::planning_interface::MoveGroupInterface > moveGroupClientInterface
ExecutionResult executePlan(const moveit::planning_interface::MoveGroupInterface::Plan &plan, const ExecutionOptions &options={})
Execute a motion plan synchronously.
virtual rclcpp::Logger getLogger() const
Configuration options for trajectory execution.
std::optional< std::string > trajectoryName
geometry_msgs::msg::PoseStamped pose
Configuration options for motion planning.
std::optional< double > maxVelocityScaling
std::optional< double > maxAccelerationScaling
std::optional< double > planningTime