SMACC2
Loading...
Searching...
No Matches
cb_undo_last_trajectory.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
25
26namespace cl_moveit2z
27{
29{
30public:
32
33 CbUndoLastTrajectory(int backIndex) : backIndex_(backIndex) {}
34
36
37 virtual void onEntry() override
38 {
39 // components resolved in onStateOrthogonalAllocation (base chain)
40 CpTrajectoryHistory * trajectoryHistory = cpTrajectoryHistory_;
41
42 if (
43 trajectoryHistory != nullptr && trajectoryHistory->getLastTrajectory(backIndex_, trajectory))
44 {
45 RCLCPP_WARN_STREAM(
46 getLogger(), "[" << getName() << "] reversing last trajectory [" << backIndex_ << "]");
47
48 auto initialTime = trajectory.joint_trajectory.points.back().time_from_start;
49
51
52 std::reverse(
53 reversed.joint_trajectory.points.begin(), reversed.joint_trajectory.points.end());
54
55 for (auto & jp : reversed.joint_trajectory.points)
56 {
57 jp.time_from_start = rclcpp::Duration(initialTime) - rclcpp::Duration(jp.time_from_start);
58 }
59
61 }
62 else
63 {
64 RCLCPP_WARN_STREAM(
65 getLogger(), "[" << getName() << "] could not undo last trajectory, trajectory not found.");
66 // previously this path posted nothing and the state machine waited forever
67 this->postMotionFailure();
68 }
69 }
70
71 virtual void generateTrajectory() {}
72
73private:
74 int backIndex_ = -1;
75
76 moveit_msgs::msg::RobotTrajectory trajectory;
77 moveit_msgs::msg::RobotTrajectory reversed;
78};
79
80} // namespace cl_moveit2z
void executeJointSpaceTrajectory(const moveit_msgs::msg::RobotTrajectory &computedJointTrajectory)
moveit_msgs::msg::RobotTrajectory trajectory
moveit_msgs::msg::RobotTrajectory reversed
bool getLastTrajectory(int backIndex, moveit_msgs::msg::RobotTrajectory &trajectory)
virtual rclcpp::Logger getLogger() const