action_server.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017, 2018 Jarek Potiuk (low bandwidth trajectory follower)
3  *
4  * Copyright 2017, 2018 Simon Rasmussen (refactor)
5  *
6  * Copyright 2015, 2016 Thomas Timm Andersen (original version)
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #pragma once
22 
25 #include <control_msgs/FollowJointTrajectoryAction.h>
26 #include <ros/ros.h>
27 #include <atomic>
28 #include <chrono>
29 #include <condition_variable>
30 #include <mutex>
31 #include <set>
32 #include <thread>
33 #include "ur_modern_driver/log.h"
39 
40 class ActionServer : public Service, public URRTPacketConsumer
41 {
42 private:
43  typedef control_msgs::FollowJointTrajectoryAction Action;
44  typedef control_msgs::FollowJointTrajectoryResult Result;
47 
49  Server as_;
50 
51  std::vector<std::string> joint_names_;
52  std::set<std::string> joint_set_;
53  double max_velocity_;
54 
55  GoalHandle curr_gh_;
56  std::atomic<bool> interrupt_traj_;
57  std::atomic<bool> has_goal_, running_;
58  std::mutex tj_mutex_;
59  std::condition_variable tj_cv_;
60  std::thread tj_thread_;
61 
63 
65  std::array<double, 6> q_actual_, qd_actual_;
66 
67  void onGoal(GoalHandle gh);
68  void onCancel(GoalHandle gh);
69 
70  bool validate(GoalHandle& gh, Result& res);
71  bool validateState(GoalHandle& gh, Result& res);
72  bool validateJoints(GoalHandle& gh, Result& res);
73  bool validateTrajectory(GoalHandle& gh, Result& res);
74 
75  bool try_execute(GoalHandle& gh, Result& res);
76  void interruptGoal(GoalHandle& gh);
77 
78  std::vector<size_t> reorderMap(std::vector<std::string> goal_joints);
79 
80  void trajectoryThread();
81  bool updateState(RTShared& data);
82 
83 public:
84  ActionServer(ActionTrajectoryFollowerInterface& follower, std::vector<std::string>& joint_names, double max_velocity);
85 
86  void start();
87  virtual void onRobotStateChange(RobotState state);
88 
89  virtual bool consume(RTState_V1_6__7& state);
90  virtual bool consume(RTState_V1_8& state);
91  virtual bool consume(RTState_V3_0__1& state);
92  virtual bool consume(RTState_V3_2__3& state);
93 };
std::condition_variable tj_cv_
Definition: action_server.h:59
void interruptGoal(GoalHandle &gh)
RobotState state_
Definition: action_server.h:64
ros::NodeHandle nh_
Definition: action_server.h:48
bool validateState(GoalHandle &gh, Result &res)
bool validateJoints(GoalHandle &gh, Result &res)
control_msgs::FollowJointTrajectoryResult Result
Definition: action_server.h:44
std::atomic< bool > running_
Definition: action_server.h:57
virtual bool consume(RTState_V1_6__7 &state)
std::atomic< bool > has_goal_
Definition: action_server.h:57
control_msgs::FollowJointTrajectoryAction Action
Definition: action_server.h:43
actionlib::ServerGoalHandle< Action > GoalHandle
Definition: action_server.h:45
GoalHandle curr_gh_
Definition: action_server.h:55
void onGoal(GoalHandle gh)
bool validate(GoalHandle &gh, Result &res)
actionlib::ActionServer< Action > Server
Definition: action_server.h:46
std::array< double, 6 > qd_actual_
Definition: action_server.h:65
double max_velocity_
Definition: action_server.h:53
virtual void onRobotStateChange(RobotState state)
bool updateState(RTShared &data)
ActionServer(ActionTrajectoryFollowerInterface &follower, std::vector< std::string > &joint_names, double max_velocity)
std::mutex tj_mutex_
Definition: action_server.h:58
std::vector< std::string > joint_names_
Definition: action_server.h:51
RobotState
bool try_execute(GoalHandle &gh, Result &res)
void trajectoryThread()
std::thread tj_thread_
Definition: action_server.h:60
bool validateTrajectory(GoalHandle &gh, Result &res)
std::set< std::string > joint_set_
Definition: action_server.h:52
std::vector< size_t > reorderMap(std::vector< std::string > goal_joints)
std::atomic< bool > interrupt_traj_
Definition: action_server.h:56
void onCancel(GoalHandle gh)
ActionTrajectoryFollowerInterface & follower_
Definition: action_server.h:62
std::array< double, 6 > q_actual_
Definition: action_server.h:65


ur_modern_driver
Author(s): Thomas Timm Andersen, Simon Rasmussen
autogenerated on Fri Jun 26 2020 03:37:00