SMACC2
Loading...
Searching...
No Matches
cb_move_end_effector_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
23#include <tf2/transform_datatypes.h>
25#include <moveit_msgs/srv/get_position_ik.hpp>
27#include <visualization_msgs/msg/marker_array.hpp>
28
29namespace cl_moveit2z
30{
31template <typename AsyncCB, typename Orthogonal>
32struct EvJointDiscontinuity : sc::event<EvJointDiscontinuity<AsyncCB, Orthogonal>>
33{
34 moveit_msgs::msg::RobotTrajectory trajectory;
35};
36
37template <typename AsyncCB, typename Orthogonal>
38struct EvIncorrectInitialPosition : sc::event<EvIncorrectInitialPosition<AsyncCB, Orthogonal>>
39{
40 moveit_msgs::msg::RobotTrajectory trajectory;
41};
42
49
50// this is a base behavior to define any kind of parametrized family of trajectories or motions
53{
54public:
55 // std::string tip_link_;
56 std::optional<std::string> group_;
57
58 std::optional<std::string> tipLink_;
59
61
62 CbMoveEndEffectorTrajectory(std::optional<std::string> tipLink = std::nullopt);
63
65 const std::vector<geometry_msgs::msg::PoseStamped> & endEffectorTrajectory,
66 std::optional<std::string> tipLink = std::nullopt);
67
68 template <typename TOrthogonal, typename TSourceObject>
70 {
71 this->initializeROS();
72
73 smacc2::SmaccAsyncClientBehavior::onOrthogonalAllocation<TOrthogonal, TSourceObject>();
74
75 postJointDiscontinuityEvent = [this](auto traj)
76 {
78 ev->trajectory = traj;
79 this->postEvent(ev);
80 };
81
82 postIncorrectInitialStateEvent = [this](auto traj)
83 {
85 ev->trajectory = traj;
86 this->postEvent(ev);
87 };
88
90 {
91 RCLCPP_INFO_STREAM(getLogger(), "[" << this->getName() << "] motion execution failed");
93 this->postEvent<EvMoveGroupMotionExecutionFailed<TSourceObject, TOrthogonal>>();
94 };
95 }
96
97 virtual void onEntry() override;
98
99 virtual void onExit() override;
100
101 virtual void update() override;
102
103protected:
105 moveit_msgs::msg::RobotTrajectory & computedJointTrajectory);
106
108 const moveit_msgs::msg::RobotTrajectory & computedJointTrajectory);
109
110 virtual void generateTrajectory() = 0;
111
112 virtual void createMarkers();
113
114 std::vector<geometry_msgs::msg::PoseStamped> endEffectorTrajectory_;
115
117
118 visualization_msgs::msg::MarkerArray beahiorMarkers_;
119
121 std::string globalFrame, tf2::Stamped<tf2::Transform> & currentEndEffectorTransform);
122
123private:
124 void initializeROS();
125
126 rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr markersPub_;
127
128 std::atomic<bool> markersInitialized_;
129
130 rclcpp::Client<moveit_msgs::srv::GetPositionIK>::SharedPtr iksrv_;
131
132 std::mutex m_mutex_;
133
134 std::function<void(moveit_msgs::msg::RobotTrajectory &)> postJointDiscontinuityEvent;
135 std::function<void(moveit_msgs::msg::RobotTrajectory &)> postIncorrectInitialStateEvent;
136
137 std::function<void()> postMotionExecutionFailureEvents;
138
139 bool autocleanmarkers = false;
140};
141} // namespace cl_moveit2z
std::function< void(moveit_msgs::msg::RobotTrajectory &)> postJointDiscontinuityEvent
std::function< void(moveit_msgs::msg::RobotTrajectory &)> postIncorrectInitialStateEvent
std::vector< geometry_msgs::msg::PoseStamped > endEffectorTrajectory_
ComputeJointTrajectoryErrorCode computeJointSpaceTrajectory(moveit_msgs::msg::RobotTrajectory &computedJointTrajectory)
void executeJointSpaceTrajectory(const moveit_msgs::msg::RobotTrajectory &computedJointTrajectory)
rclcpp::Publisher< visualization_msgs::msg::MarkerArray >::SharedPtr markersPub_
void getCurrentEndEffectorPose(std::string globalFrame, tf2::Stamped< tf2::Transform > &currentEndEffectorTransform)
rclcpp::Client< moveit_msgs::srv::GetPositionIK >::SharedPtr iksrv_
virtual rclcpp::Logger getLogger() const