00001 /* 00002 * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA) 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 00018 #ifndef COB_TWIST_CONTROLLER_COB_TWIST_CONTROLLER_H 00019 #define COB_TWIST_CONTROLLER_COB_TWIST_CONTROLLER_H 00020 00021 #include <ros/ros.h> 00022 00023 #include <std_msgs/ColorRGBA.h> 00024 #include <sensor_msgs/JointState.h> 00025 #include <geometry_msgs/Twist.h> 00026 #include <nav_msgs/Odometry.h> 00027 00028 #include <urdf/model.h> 00029 00030 #include <kdl_parser/kdl_parser.hpp> 00031 #include <kdl/chainfksolvervel_recursive.hpp> 00032 #include <kdl/jntarray.hpp> 00033 #include <kdl/jntarrayvel.hpp> 00034 #include <kdl/frames.hpp> 00035 00036 #include <tf/transform_listener.h> 00037 #include <tf/tf.h> 00038 00039 #include <boost/thread/mutex.hpp> 00040 #include <boost/shared_ptr.hpp> 00041 00042 #include <dynamic_reconfigure/server.h> 00043 #include <pluginlib/class_loader.h> 00044 00045 #include <cob_twist_controller/TwistControllerConfig.h> 00046 #include "cob_twist_controller/cob_twist_controller_data_types.h" 00047 #include <cob_twist_controller/inverse_differential_kinematics_solver.h> 00048 #include "cob_twist_controller/controller_interfaces/controller_interface_base.h" 00049 #include "cob_twist_controller/callback_data_mediator.h" 00050 00051 class CobTwistController 00052 { 00053 private: 00054 ros::NodeHandle nh_; 00055 00056 ros::Subscriber jointstate_sub_; 00057 00058 ros::Subscriber twist_sub_; 00059 ros::Subscriber twist_stamped_sub_; 00060 00061 ros::Subscriber odometry_sub_; 00062 00063 ros::Publisher twist_direction_pub_; 00064 00065 ros::ServiceClient register_link_client_; 00066 ros::Subscriber obstacle_distance_sub_; 00067 00068 KDL::Chain chain_; 00069 JointStates joint_states_; 00070 KDL::Twist twist_odometry_cb_; 00071 00072 TwistControllerParams twist_controller_params_; 00073 00074 boost::shared_ptr<KDL::ChainFkSolverVel_recursive> jntToCartSolver_vel_; 00075 boost::shared_ptr<InverseDifferentialKinematicsSolver> p_inv_diff_kin_solver_; 00076 boost::shared_ptr<cob_twist_controller::ControllerInterfaceBase> controller_interface_; 00077 boost::shared_ptr<pluginlib::ClassLoader<cob_twist_controller::ControllerInterfaceBase> > interface_loader_; 00078 00079 CallbackDataMediator callback_data_mediator_; 00080 00081 tf::TransformListener tf_listener_; 00082 00083 public: 00084 CobTwistController() 00085 { 00086 } 00087 00088 ~CobTwistController() 00089 { 00090 this->jntToCartSolver_vel_.reset(); 00091 this->p_inv_diff_kin_solver_.reset(); 00092 this->controller_interface_.reset(); 00093 this->reconfigure_server_.reset(); 00094 } 00095 00096 bool initialize(); 00097 00098 bool registerCollisionLinks(); 00099 00100 void reconfigureCallback(cob_twist_controller::TwistControllerConfig& config, uint32_t level); 00101 void checkSolverAndConstraints(cob_twist_controller::TwistControllerConfig& config); 00102 void jointstateCallback(const sensor_msgs::JointState::ConstPtr& msg); 00103 void odometryCallback(const nav_msgs::Odometry::ConstPtr& msg); 00104 00105 void twistCallback(const geometry_msgs::Twist::ConstPtr& msg); 00106 void twistStampedCallback(const geometry_msgs::TwistStamped::ConstPtr& msg); 00107 00108 void solveTwist(KDL::Twist twist); 00109 void visualizeTwist(KDL::Twist twist); 00110 00111 boost::recursive_mutex reconfig_mutex_; 00112 boost::shared_ptr< dynamic_reconfigure::Server<cob_twist_controller::TwistControllerConfig> > reconfigure_server_; 00113 }; 00114 00115 #endif // COB_TWIST_CONTROLLER_COB_TWIST_CONTROLLER_H