yumi_hw.h
Go to the documentation of this file.
00001 #ifndef __YUMI_HW_H
00002 #define __YUMI_HW_H
00003 
00004 // boost
00005 #include <boost/scoped_ptr.hpp>
00006 
00007 // ROS headers
00008 #include <std_msgs/Duration.h>
00009 #include <urdf/model.h>
00010 
00011 // ROS control
00012 #include <hardware_interface/robot_hw.h>
00013 #include <hardware_interface/joint_state_interface.h>
00014 #include <hardware_interface/joint_command_interface.h>
00015 #include <transmission_interface/transmission_info.h>
00016 #include <transmission_interface/transmission_parser.h>
00017 #include <joint_limits_interface/joint_limits.h>
00018 #include <joint_limits_interface/joint_limits_interface.h>
00019 #include <joint_limits_interface/joint_limits_rosparam.h>
00020 #include <joint_limits_interface/joint_limits_urdf.h>
00021 #include <control_toolbox/filters.h>
00022 
00023 // KDL
00024 #include <kdl/kdl.hpp>
00025 #include <kdl/tree.hpp>
00026 #include <kdl/chain.hpp>
00027 #include <kdl/chaindynparam.hpp> //this to compute the gravity verctor
00028 #include <kdl_parser/kdl_parser.hpp>
00029 
00034 class YumiHW : public hardware_interface::RobotHW
00035 {
00036     public:
00037 
00038         YumiHW() 
00039         {
00040             n_joints_=14;
00041         }
00042         virtual ~YumiHW() {}
00043 
00044         void create(std::string name, std::string urdf_string);
00045 
00046         // Strings
00047         std::string robot_namespace_;
00048 
00049         // Model
00050         std::string urdf_string_;
00051         urdf::Model urdf_model_;
00052 
00053         // control strategies
00054         // JOINT_POSITION -> strategy 10 -> triggered with PoitionJointInterface
00055         // JOINT_VELOCITY -> strategy 15 -> triggered with VelJointInterface
00056         // JOINT_EFFORT -> strategy 20 -> TODO
00057         enum ControlStrategy {JOINT_POSITION = 10, JOINT_VELOCITY = 15};
00058         virtual bool canSwitch(const std::list<hardware_interface::ControllerInfo> &start_list, const std::list<hardware_interface::ControllerInfo> &stop_list) const;
00059         virtual void doSwitch(const std::list<hardware_interface::ControllerInfo> &start_list, const std::list<hardware_interface::ControllerInfo> &stop_list);
00060 
00061         // This functions must be implemented depending on the outlet (Real, Gazebo, etc.)
00062         virtual bool init() = 0;
00063         virtual void read(ros::Time time, ros::Duration period) = 0;
00064         virtual void write(ros::Time time, ros::Duration period) = 0;
00065 
00066         // get/set control method
00067         void setControlStrategy( ControlStrategy strategy){current_strategy_ = strategy;};
00068         ControlStrategy getControlStrategy(){ return current_strategy_;};
00069 
00070         // Hardware interfaces
00071         hardware_interface::JointStateInterface state_interface_;
00072         //hardware_interface::EffortJointInterface effort_interface_; //TODO
00073         hardware_interface::PositionJointInterface position_interface_;
00074         hardware_interface::VelocityJointInterface velocity_interface_;
00075 
00076         ControlStrategy current_strategy_;
00077 
00078         // joint limits interfaces
00079         //joint_limits_interface::EffortJointSaturationInterface     ej_sat_interface_;
00080         //joint_limits_interface::EffortJointSoftLimitsInterface     ej_limits_interface_;
00081         joint_limits_interface::VelocityJointSaturationInterface   vj_sat_interface_;
00082         joint_limits_interface::VelocityJointSoftLimitsInterface   vj_limits_interface_;
00083         joint_limits_interface::PositionJointSaturationInterface   pj_sat_interface_;
00084         joint_limits_interface::PositionJointSoftLimitsInterface   pj_limits_interface_;
00085 
00086         // Before write, you can use this function to enforce limits for all values
00087         void enforceLimits(ros::Duration period);
00088 
00089         // configuration
00090         int n_joints_; // all joints of yumi
00091         std::vector<std::string> joint_names_;
00092 
00093         // limits
00094         std::vector<double>
00095             joint_lower_limits_,
00096             joint_upper_limits_; 
00097 
00098         // state and commands
00099         std::vector<double>
00100             joint_position_,
00101             joint_position_prev_,
00102             joint_velocity_,
00103             joint_effort_,
00104             joint_position_command_,
00105             joint_velocity_command_;
00106 
00107         // Set all members to default values
00108         void reset();
00109         
00110         // Transmissions in this plugin's scope
00111         std::vector<transmission_interface::TransmissionInfo> transmissions_;
00112 
00113         //TODO: KDL stuff is not implemented yet
00114         // KDL stuff to compute ik, gravity term, etc.
00115         /*
00116         KDL::Chain yumi_chain_;
00117         boost::scoped_ptr<KDL::ChainDynParam> f_dyn_solver_;
00118         KDL::JntArray joint_position_kdl_, gravity_effort_;
00119         KDL::Vector gravity_;
00120         */
00121 
00122     private:
00123 
00124         // Get Transmissions from the URDF
00125         bool parseTransmissionsFromURDF(const std::string& urdf_string);
00126 
00127         // Register all interfaces 
00128         void registerInterfaces(const urdf::Model *const urdf_model,
00129                 std::vector<transmission_interface::TransmissionInfo> transmissions);
00130 
00131         // Initialize all KDL members
00132         // bool initKDLdescription(const urdf::Model *const urdf_model);
00133 
00134         // Helper function to register limit interfaces
00135         void registerJointLimits(const std::string& joint_name,
00136                 const hardware_interface::JointHandle& joint_handle_position,
00137                 const hardware_interface::JointHandle& joint_handle_velocity,
00138                 const urdf::Model *const urdf_model,
00139                 double *const lower_limit, double *const upper_limit);
00140 
00141 }; // class
00142 
00143 
00144 
00145 #endif


yumi_hw
Author(s):
autogenerated on Sat Jun 8 2019 20:47:40