GeomController.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9 
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
18 #ifndef H_GEOM_CONTROLLER_IMPL
19 #define H_GEOM_CONTROLLER_IMPL
20 
23 #include <boost/scoped_ptr.hpp>
24 
26 {
27 
28 template<typename HandleType, typename Controller> class GeomControllerBase {
29 protected:
30  std::vector<HandleType> steer_joints_;
31  std::vector<HandleType> drive_joints_;
32  std::vector<WheelState> wheel_states_;
33  boost::scoped_ptr<Controller> geom_;
34 
35 public:
36  void updateState(){
37 
38  for (unsigned i=0; i<wheel_states_.size(); i++){
39  wheel_states_[i].dAngGearSteerRad = steer_joints_[i].getPosition();
40  wheel_states_[i].dVelGearSteerRadS = steer_joints_[i].getVelocity();
41  wheel_states_[i].dVelGearDriveRadS = drive_joints_[i].getVelocity();
42  }
43  geom_->updateWheelStates(wheel_states_);
44  }
45 protected:
46  bool setup(const std::vector<typename Controller::WheelParams> &wheel_params){
47  if (wheel_params.size() < 3){
48  ROS_ERROR("At least three wheel are needed.");
49  return false;
50  }
51  wheel_states_.resize(wheel_params.size());
52  geom_.reset(new Controller(wheel_params));
53  return true;
54 
55  }
56 };
57 
58 template<typename Interface, typename Controller> class GeomController:
59  public GeomControllerBase<typename Interface::ResourceHandleType, Controller>,
60  public controller_interface::Controller<Interface> {
61 public:
62  typedef std::vector<typename Controller::WheelParams> wheel_params_t;
63  bool init(Interface* hw, ros::NodeHandle& controller_nh){
64  std::vector<typename Controller::WheelParams> wheel_params;
65  if(!parseWheelParams(wheel_params, controller_nh)) return false;
66  return init(hw, wheel_params);
67  }
68  bool init(Interface* hw, const wheel_params_t & wheel_params){
69  if(!this->setup(wheel_params)) return false;
70  try{
71  for (unsigned i=0; i<wheel_params.size(); i++){
72  this->steer_joints_.push_back(hw->getHandle(wheel_params[i].geom.steer_name));
73  this->drive_joints_.push_back(hw->getHandle(wheel_params[i].geom.drive_name));
74  }
75  }
76  catch(const std::exception &e){
77  ROS_ERROR_STREAM("Error while attaching handles: " << e.what());
78  return false;
79  }
80  return true;
81  }
82 };
83 
84 }
85 
86 #endif
std::vector< typename Controller::WheelParams > wheel_params_t
bool parseWheelParams(std::vector< UndercarriageGeom::WheelParams > &params, const ros::NodeHandle &nh, bool read_urdf=true)
boost::scoped_ptr< Controller > geom_
bool setup(const std::vector< typename Controller::WheelParams > &wheel_params)
bool init(Interface *hw, const wheel_params_t &wheel_params)
bool init(Interface *hw, ros::NodeHandle &controller_nh)
#define ROS_ERROR_STREAM(args)
#define ROS_ERROR(...)


cob_omni_drive_controller
Author(s): Christian Connette, Mathias Lüdtke
autogenerated on Thu Apr 8 2021 02:39:52