GeomController.h
Go to the documentation of this file.
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 H_GEOM_CONTROLLER_IMPL
00019 #define H_GEOM_CONTROLLER_IMPL
00020 
00021 #include <controller_interface/controller.h>
00022 #include <cob_omni_drive_controller/UndercarriageCtrlGeomROS.h>
00023 #include <boost/scoped_ptr.hpp>
00024 
00025 namespace cob_omni_drive_controller
00026 {
00027 
00028 template<typename HandleType, typename Controller> class GeomControllerBase {
00029 protected:
00030     std::vector<HandleType> steer_joints_;
00031     std::vector<HandleType> drive_joints_;
00032     std::vector<WheelState> wheel_states_;
00033     boost::scoped_ptr<Controller> geom_;
00034 
00035 public:
00036     void updateState(){
00037 
00038         for (unsigned i=0; i<wheel_states_.size(); i++){
00039             wheel_states_[i].dAngGearSteerRad = steer_joints_[i].getPosition();
00040             wheel_states_[i].dVelGearSteerRadS = steer_joints_[i].getVelocity();
00041             wheel_states_[i].dVelGearDriveRadS = drive_joints_[i].getVelocity();
00042         }
00043         geom_->updateWheelStates(wheel_states_);
00044     }
00045 protected:
00046     bool setup(const std::vector<typename Controller::WheelParams> &wheel_params){
00047         if (wheel_params.size() < 3){
00048             ROS_ERROR("At least three wheel are needed.");
00049             return false;
00050         }
00051         wheel_states_.resize(wheel_params.size());
00052         geom_.reset(new Controller(wheel_params));
00053         return true;
00054 
00055     }
00056 };
00057 
00058 template<typename Interface, typename Controller> class GeomController:
00059     public GeomControllerBase<typename Interface::ResourceHandleType, Controller>,
00060         public controller_interface::Controller<Interface> {
00061 public:
00062     typedef std::vector<typename Controller::WheelParams> wheel_params_t;
00063     bool init(Interface* hw, ros::NodeHandle& controller_nh){
00064         std::vector<typename Controller::WheelParams> wheel_params;
00065         if(!parseWheelParams(wheel_params, controller_nh)) return false;
00066         return init(hw, wheel_params);
00067     }
00068     bool init(Interface* hw, const wheel_params_t & wheel_params){
00069         if(!this->setup(wheel_params)) return false;
00070         try{
00071             for (unsigned i=0; i<wheel_params.size(); i++){
00072                 this->steer_joints_.push_back(hw->getHandle(wheel_params[i].geom.steer_name));
00073                 this->drive_joints_.push_back(hw->getHandle(wheel_params[i].geom.drive_name));
00074             }
00075         }
00076         catch(const std::exception &e){
00077             ROS_ERROR_STREAM("Error while attaching handles: " << e.what());
00078             return false;
00079         }
00080         return true;
00081     }
00082 };
00083 
00084 }
00085 
00086 #endif


cob_omni_drive_controller
Author(s): Christian Connette, Mathias Lüdtke
autogenerated on Thu Jun 6 2019 21:19:19