hardware_interface_adapter.h
Go to the documentation of this file.
00001 //
00002 // Created by tom on 10/04/16.
00003 //
00004 
00005 #ifndef ROBOTICAN_CONTROLLERS_HARDWARE_INTERFACE_ADAPTER_H
00006 #define ROBOTICAN_CONTROLLERS_HARDWARE_INTERFACE_ADAPTER_H
00007 
00008 
00009 #include <cassert>
00010 #include <string>
00011 #include <vector>
00012 
00013 #include <boost/shared_ptr.hpp>
00014 
00015 #include <ros/node_handle.h>
00016 #include <ros/time.h>
00017 
00018 #include <control_toolbox/pid.h>
00019 #include <hardware_interface/joint_command_interface.h>
00020 #include <hardware_interface/posvel_command_interface.h>
00021 
00022 template <class HardwareInterface, class State>
00023 class HardwareInterfaceAdapter
00024 {
00025 public:
00026     bool init(std::vector<typename HardwareInterface::ResourceHandleType>& /*joint_handles*/, ros::NodeHandle& /*controller_nh*/)
00027     {
00028         return false;
00029     }
00030 
00031     void starting(const ros::Time& /*time*/) {}
00032     void stopping(const ros::Time& /*time*/) {}
00033 
00034     void updateCommand(const ros::Time&     /*time*/,
00035                        const ros::Duration& /*period*/,
00036                        const State&         /*desired_state*/,
00037                        const State&         /*state_error*/) {}
00038 };
00039 
00040 template <class State>
00041 class HardwareInterfaceAdapter<hardware_interface::PosVelJointInterface, State> {
00042 private:
00043     std::vector<hardware_interface::PosVelJointHandle>* joint_handles_ptr_;
00044 public:
00045     HardwareInterfaceAdapter() : joint_handles_ptr_(NULL) {}
00046     bool init(std::vector<hardware_interface::PosVelJointHandle>& joint_handles, ros::NodeHandle& controller_nh){
00047         joint_handles_ptr_ = &joint_handles;
00048     }
00049 
00050     void starting(const ros::Time& /*time*/) {
00051         if (!joint_handles_ptr_) {return;}
00052         for (unsigned int i = 0; i < joint_handles_ptr_->size(); ++i)
00053         {
00054             (*joint_handles_ptr_)[i].setCommand((*joint_handles_ptr_)[i].getPosition(), 0.05);
00055         }
00056     }
00057 
00058     void stopping(const ros::Time& /*time*/) { }
00059 
00060     void updateCommand(const ros::Time&     /*time*/,
00061                        const ros::Duration& /*period*/,
00062                        const State&         desired_state,
00063                        const State&         /*state_error*/)
00064     {
00065         // Forward desired position to command
00066         const unsigned int n_joints = joint_handles_ptr_->size();
00067         for (unsigned int i = 0; i < n_joints; ++i) {(*joint_handles_ptr_)[i].setCommand(desired_state.position[i], desired_state.velocity[i]);}
00068     }
00069 
00070 
00071 };
00072 
00073 #endif //ROBOTICAN_CONTROLLERS_HARDWARE_INTERFACE_ADAPTER_H


robotican_controllers
Author(s):
autogenerated on Fri Oct 27 2017 03:02:40