cob_frame_tracker.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef COB_FRAME_TRACKER_H
19 #define COB_FRAME_TRACKER_H
20 
21 #include <string>
22 #include <vector>
23 #include <math.h>
24 #include <algorithm>
25 #include <ros/ros.h>
26 
27 #include <std_msgs/String.h>
28 #include <std_msgs/Float64.h>
29 #include <std_msgs/Float64MultiArray.h>
30 #include <sensor_msgs/JointState.h>
31 #include <geometry_msgs/Twist.h>
32 #include <std_srvs/Trigger.h>
33 #include <cob_srvs/SetString.h>
34 
36 #include <cob_frame_tracker/FrameTrackerConfig.h>
37 #include <cob_frame_tracker/FrameTrackingAction.h>
38 
39 #include <tf/transform_listener.h>
40 #include <tf/transform_datatypes.h>
41 
43 #include <kdl/chainiksolvervel_pinv.hpp>
44 #include <kdl/chainfksolvervel_recursive.hpp>
45 #include <kdl/frames.hpp>
46 #include <kdl/jntarray.hpp>
47 #include <kdl/jntarrayvel.hpp>
48 
49 #include <control_toolbox/pid.h>
50 #include <dynamic_reconfigure/server.h>
51 #include <dynamic_reconfigure/Reconfigure.h>
52 #include <boost/thread/mutex.hpp>
53 
54 
56 
57 struct HoldTf
58 {
60  bool hold;
61 };
62 
63 
65 {
66 public:
68  {
69  ht_.hold = false;
70  }
71 
73  {
74  jntToCartSolver_vel_.reset();
75  as_.reset();
76  reconfigure_server_.reset();
77  }
78 
79  bool initialize();
80  void run(const ros::TimerEvent& event);
81 
82  void jointstateCallback(const sensor_msgs::JointState::ConstPtr& msg);
83 
84  bool startTrackingCallback(cob_srvs::SetString::Request& request, cob_srvs::SetString::Response& response);
85  bool startLookatCallback(cob_srvs::SetString::Request& request, cob_srvs::SetString::Response& response);
86  bool stopCallback(std_srvs::Trigger::Request& request, std_srvs::Trigger::Response& response);
87 
88  bool getTransform(const std::string& from, const std::string& to, tf::StampedTransform& stamped_tf);
89 
90  void publishZeroTwist();
91  void publishTwist(ros::Duration period, bool do_publish = true);
92  void publishHoldTwist(const ros::Duration& period);
93 
95  void goalCB();
96  void preemptCB();
97  void action_success();
98  void action_abort();
99 
100 private:
102 
103  double update_rate_;
105 
106  bool tracking_;
108  bool lookat_;
109  std::string chain_base_link_;
110  std::string chain_tip_link_;
111  std::string lookat_focus_frame_;
112  std::string tracking_frame_; // the frame tracking the target (i.e. chain_tip or lookat_focus)
113  std::string target_frame_; // the frame to be tracked
114 
115  double max_vel_lin_;
116  double max_vel_rot_;
117 
118  std::vector<std::string> joints_;
119  unsigned int dof_;
120 
123 
127 
131 
137 
139 
143 
148 
150  std::string action_name_;
152 
153  cob_frame_tracker::FrameTrackingFeedback action_feedback_;
154  cob_frame_tracker::FrameTrackingResult action_result_;
155 
156  boost::recursive_mutex reconfig_mutex_;
158  void reconfigureCallback(cob_frame_tracker::FrameTrackerConfig& config, uint32_t level);
159 
161  int checkStatus();
162  bool checkInfinitesimalTwist(const KDL::Twist current);
163  bool checkCartDistanceViolation(const double dist, const double rot);
164  bool checkTwistViolation(const KDL::Twist current, const KDL::Twist target);
165 
166  int checkServiceCallStatus();
167 
171 
179 
182 
185 
186  unsigned int abortion_counter_;
187  unsigned int max_abortions_;
188 };
189 
190 #endif
std::string chain_tip_link_
std::string chain_base_link_
double twist_dead_threshold_rot_
KDL::Twist target_twist_
ros::Time tracking_start_time_
KDL::JntArray last_q_dot_
actionlib::SimpleActionServer< cob_frame_tracker::FrameTrackingAction > SAS_FrameTrackingAction_t
ROSCONSOLE_DECL void initialize()
std::string tracking_frame_
boost::shared_ptr< KDL::ChainFkSolverVel_recursive > jntToCartSolver_vel_
ros::ServiceServer start_tracking_server_
boost::shared_ptr< dynamic_reconfigure::Server< cob_frame_tracker::FrameTrackerConfig > > reconfigure_server_
ros::ServiceServer stop_server_
control_toolbox::Pid pid_controller_rot_z_
cob_frame_tracker::FrameTrackingResult action_result_
double twist_dead_threshold_lin_
double twist_deviation_threshold_lin_
KDL::Twist current_twist_
boost::recursive_mutex reconfig_mutex_
double twist_deviation_threshold_rot_
unsigned int abortion_counter_
control_toolbox::Pid pid_controller_trans_z_
control_toolbox::Pid pid_controller_rot_y_
cob_frame_tracker::FrameTrackingFeedback action_feedback_
tf::TransformListener tf_listener_
tf::StampedTransform transform_tf
boost::shared_ptr< SAS_FrameTrackingAction_t > as_
KDL::Chain chain_
KDL Conversion.
std::string target_frame_
std::string lookat_focus_frame_
std::vector< std::string > joints_
KDL::JntArray last_q_
double cart_min_dist_threshold_lin_
ros::Publisher error_pub_
control_toolbox::Pid pid_controller_trans_y_
unsigned int max_abortions_
control_toolbox::Pid pid_controller_trans_x_
ros::Subscriber jointstate_sub_
ros::ServiceClient reconfigure_client_
void run(ClassLoader *loader)
control_toolbox::Pid pid_controller_rot_x_
std::string action_name_
Action interface.
ros::ServiceServer start_lookat_server_
ros::Publisher twist_pub_
double cart_min_dist_threshold_rot_


cob_frame_tracker
Author(s): Felix Messmer
autogenerated on Thu Apr 8 2021 02:39:38