Go to the documentation of this file.00001
00027 #ifndef _SRH_CONTROLLER_HPP_
00028 #define _SRH_CONTROLLER_HPP_
00029
00030 #include <ros/node_handle.h>
00031
00032 #include <controller_interface/controller.h>
00033 #include <ros_ethercat_model/robot_state.hpp>
00034 #include <control_toolbox/pid.h>
00035 #include <boost/scoped_ptr.hpp>
00036 #include <boost/thread/condition.hpp>
00037 #include <realtime_tools/realtime_publisher.h>
00038 #include <std_msgs/Float64.h>
00039 #include <std_srvs/Empty.h>
00040 #include <control_msgs/JointControllerState.h>
00041
00042 #include <utility>
00043
00044 #include <sr_robot_msgs/SetPidGains.h>
00045
00046 #include <sr_utilities/sr_deadband.hpp>
00047
00048 #include <sr_mechanism_controllers/sr_friction_compensation.hpp>
00049
00050
00051 namespace controller
00052 {
00053
00054 class SrController : public controller_interface::Controller<ros_ethercat_model::RobotState>
00055 {
00056 public:
00057
00058 SrController();
00059 virtual ~SrController();
00060
00061 virtual bool init(ros_ethercat_model::RobotState *robot, ros::NodeHandle &n) = 0;
00062
00063 virtual void starting(const ros::Time& time) {};
00064
00068 virtual void update(const ros::Time& time, const ros::Duration& period) = 0;
00069
00070 virtual bool resetGains(std_srvs::Empty::Request& req, std_srvs::Empty::Response& resp) { return true; };
00071
00072 virtual void getGains(double &p, double &i, double &d, double &i_max, double &i_min) {};
00073
00074 std::string getJointName();
00075 ros_ethercat_model::JointState *joint_state_;
00076 ros_ethercat_model::JointState *joint_state_2;
00077 bool has_j2;
00078 double command_;
00080 protected:
00081
00082 bool is_joint_0();
00083
00084
00085 void get_joints_states_1_2();
00086
00088 void after_init();
00089
00098 virtual double clamp_command( double cmd );
00099
00107 void get_min_max( urdf::Model model, std::string joint_name );
00108
00110 double min_, max_;
00111
00112 int loop_count_;
00113 bool initialized_;
00114 ros_ethercat_model::RobotState *robot_;
00116 ros::NodeHandle node_, n_tilde_;
00117 std::string joint_name_;
00118
00119 boost::scoped_ptr<realtime_tools::RealtimePublisher<control_msgs::JointControllerState> > controller_state_publisher_ ;
00120
00121 boost::scoped_ptr<sr_friction_compensation::SrFrictionCompensator> friction_compensator;
00122
00124 virtual void setCommandCB(const std_msgs::Float64ConstPtr& msg) {}
00125 ros::Subscriber sub_command_;
00126 ros::ServiceServer serve_set_gains_;
00127 ros::ServiceServer serve_reset_gains_;
00128
00130 double max_force_demand;
00132 int friction_deadband;
00133
00135 sr_deadband::HysteresisDeadband<double> hysteresis_deadband;
00136
00137
00138
00139
00140 double max_force_factor_;
00141 ros::Subscriber sub_max_force_factor_;
00147 void maxForceFactorCB(const std_msgs::Float64ConstPtr& msg);
00148 };
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158 #endif