pass_through_controllers.h
Go to the documentation of this file.
1 // -- BEGIN LICENSE BLOCK ----------------------------------------------
2 // Copyright 2020 FZI Forschungszentrum Informatik
3 // Created on behalf of Universal Robots A/S
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // -- END LICENSE BLOCK ------------------------------------------------
17 
18 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 // ROS control
34 
35 // Joint-based
36 #include <control_msgs/FollowJointTrajectoryGoal.h>
37 #include <control_msgs/JointTolerance.h>
38 #include <trajectory_msgs/JointTrajectoryPoint.h>
39 #include <control_msgs/FollowJointTrajectoryAction.h>
40 
41 // Cartesian
42 #include <cartesian_control_msgs/CartesianTolerance.h>
43 #include <cartesian_control_msgs/CartesianTrajectoryPoint.h>
44 #include <cartesian_control_msgs/FollowCartesianTrajectoryGoal.h>
45 #include <cartesian_control_msgs/FollowCartesianTrajectoryAction.h>
46 
47 // Other
49 #include <vector>
50 #include <memory>
51 #include <atomic>
52 
54 {
55 struct JointBase
56 {
57  using Tolerance = std::vector<control_msgs::JointTolerance>;
58  using TrajectoryPoint = trajectory_msgs::JointTrajectoryPoint;
60  using FollowTrajectoryAction = control_msgs::FollowJointTrajectoryAction;
61  using FollowTrajectoryResult = control_msgs::FollowJointTrajectoryResult;
62  using GoalConstPtr = control_msgs::FollowJointTrajectoryGoalConstPtr;
63 };
64 
66 {
67  using Tolerance = cartesian_control_msgs::CartesianTolerance;
68  using TrajectoryPoint = cartesian_control_msgs::CartesianTrajectoryPoint;
70  using FollowTrajectoryAction = cartesian_control_msgs::FollowCartesianTrajectoryAction;
71  using FollowTrajectoryResult = cartesian_control_msgs::FollowCartesianTrajectoryResult;
72  using GoalConstPtr = cartesian_control_msgs::FollowCartesianTrajectoryGoalConstPtr;
73 };
74 
105 template <class TrajectoryInterface>
107  : public controller_interface::MultiInterfaceController<TrajectoryInterface,
108  scaled_controllers::SpeedScalingInterface>,
109  public std::conditional<std::is_same<TrajectoryInterface, hardware_interface::JointTrajectoryInterface>::value,
110  JointBase, CartesianBase>::type
111 {
112 public:
114  : controller_interface::MultiInterfaceController<TrajectoryInterface,
115  scaled_controllers::SpeedScalingInterface>(
116  true) // Make speed scaling optional
117  {
118  }
119 
120  // Alias for full qualifications of inherited types.
121  // This enables a compact definition of member functions for both joint-based
122  // and Cartesian-based PassThroughControllers.
123  using Base =
124  typename std::conditional<std::is_same<TrajectoryInterface, hardware_interface::JointTrajectoryInterface>::value,
126 
127  bool init(hardware_interface::RobotHW* hw, ros::NodeHandle& root_nh, ros::NodeHandle& controller_nh);
128 
129  void starting(const ros::Time& time);
130 
131  void stopping(const ros::Time& time);
132 
133  void update(const ros::Time& time, const ros::Duration& period);
134 
152  void executeCB(const typename Base::GoalConstPtr& goal);
153 
169  void preemptCB();
170 
171 private:
177  {
178  ActionDuration() : target(0.0), current(0.0)
179  {
180  }
181 
184  };
185 
191  void monitorExecution(const typename Base::TrajectoryFeedback& feedback);
192 
201  bool withinTolerances(const typename Base::TrajectoryPoint& error, const typename Base::Tolerance& tolerances);
202 
210  bool isValid(const typename Base::GoalConstPtr& goal);
211 
215  void doneCB(const hardware_interface::ExecutionState& state);
216 
217  std::atomic<bool> done_;
219  std::unique_ptr<scaled_controllers::SpeedScalingHandle> speed_scaling_;
220  std::vector<std::string> joint_names_;
221  typename Base::Tolerance path_tolerances_;
222  typename Base::Tolerance goal_tolerances_;
223  TrajectoryInterface* trajectory_interface_;
224  std::unique_ptr<actionlib::SimpleActionServer<typename Base::FollowTrajectoryAction> > action_server_;
225 };
226 
227 } // namespace trajectory_controllers
228 
std::unique_ptr< actionlib::SimpleActionServer< typename Base::FollowTrajectoryAction > > action_server_
ros::Duration current
Real duration of the current action.
void init(const M_string &remappings)
std::vector< control_msgs::JointTolerance > Tolerance
A ROS controller for forwarding trajectories to a robot for interpolation.
cartesian_control_msgs::CartesianTrajectoryPoint TrajectoryPoint
hardware_interface::CartesianTrajectoryFeedback TrajectoryFeedback
std::unique_ptr< scaled_controllers::SpeedScalingHandle > speed_scaling_
cartesian_control_msgs::CartesianTolerance Tolerance
control_msgs::FollowJointTrajectoryAction FollowTrajectoryAction
trajectory_msgs::JointTrajectoryPoint TrajectoryPoint
control_msgs::FollowJointTrajectoryGoalConstPtr GoalConstPtr
control_msgs::FollowJointTrajectoryFeedback JointTrajectoryFeedback
FeedbackType for joint-based trajectories.
void update(controller_manager::ControllerManager &cm, const ros::TimerEvent &e)
ExecutionState
Hardware-generic done flags for trajectory execution.
cartesian_control_msgs::FollowCartesianTrajectoryResult FollowTrajectoryResult
cartesian_control_msgs::FollowCartesianTrajectoryGoalConstPtr GoalConstPtr
control_msgs::FollowJointTrajectoryResult FollowTrajectoryResult
cartesian_control_msgs::FollowCartesianTrajectoryAction FollowTrajectoryAction
bool isValid(const trajectory_msgs::JointTrajectoryPoint &point, const unsigned int joint_dim)
cartesian_control_msgs::FollowCartesianTrajectoryFeedback CartesianTrajectoryFeedback
FeedbackType for Cartesian trajectories.
hardware_interface::JointTrajectoryFeedback TrajectoryFeedback
ros::Duration target
Target duration of the current action.


pass_through_controllers
Author(s):
autogenerated on Fri May 20 2022 02:26:01