SMACC2
Loading...
Searching...
No Matches
cb_undo_last_trajectory.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
26namespace cl_moveit2z
27{
29{
30public:
32
33 CbUndoLastTrajectory(int backIndex) : backIndex_(backIndex) {}
34
36
37 virtual void onEntry() override
38 {
39 CpTrajectoryHistory * trajectoryHistory;
40 this->requiresComponent(trajectoryHistory);
42
43 if (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 }
67 }
68
69 virtual void generateTrajectory() {}
70
71private:
72 int backIndex_ = -1;
73
74 moveit_msgs::msg::RobotTrajectory trajectory;
75 moveit_msgs::msg::RobotTrajectory reversed;
76};
77
78} // 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
void requiresClient(SmaccClientType *&storage)
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)