control_plugin.cpp
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 #include "GeomController.h"
19 #include "WheelControllerBase.h"
20 
21 #include <dynamic_reconfigure/server.h>
22 #include <cob_omni_drive_controller/SteerCtrlConfig.h>
23 
25 {
26 
27 class WheelController : public WheelControllerBase< GeomController<hardware_interface::VelocityJointInterface, UndercarriageCtrl> >
28 {
29 public:
31 
32  wheel_params_t wheel_params;
33  if(!parseWheelParams(wheel_params, controller_nh) || !GeomController::init(hw, wheel_params)) return false;
34 
35  pos_ctrl_.init(wheel_params, controller_nh);
36 
37  return setup(root_nh, controller_nh);
38  }
39  virtual void update(const ros::Time& time, const ros::Duration& period){
40 
41  updateState();
43 
44  updateCtrl(time, period);
45 
46  for (unsigned i=0; i<wheel_commands_.size(); i++){
47  steer_joints_[i].setCommand(wheel_commands_[i].dVelGearSteerRadS);
48  drive_joints_[i].setCommand(wheel_commands_[i].dVelGearDriveRadS);
49  }
50 
51  }
52  class PosCtrl {
53  public:
54  PosCtrl() : updated(false) {}
56  boost::recursive_mutex::scoped_try_lock lock(mutex);
57  if(lock && updated){
59  updated = false;
60  }
61  }
62  void init(const wheel_params_t &params, const ros::NodeHandle &nh){
63  boost::recursive_mutex::scoped_lock lock(mutex);
64  pos_ctrl_params.resize(params.size());
66 
67  reconfigure_server_.reset( new dynamic_reconfigure::Server<SteerCtrlConfig>(mutex,ros::NodeHandle(nh, "default/steer_ctrl")));
68  reconfigure_server_->setCallback(boost::bind(&PosCtrl::setForAll, this, _1, _2)); // this writes the default into pos_ctrl_params
69  {
70  SteerCtrlConfig config;
71  copy(config, params.front().pos_ctrl);
72  reconfigure_server_->setConfigDefault(config);
73  }
74 
75  for(size_t i=0; i< pos_ctrl_params.size(); ++i) {
76  boost::shared_ptr<dynamic_reconfigure::Server<SteerCtrlConfig> > dr(new dynamic_reconfigure::Server<SteerCtrlConfig>(mutex, ros::NodeHandle(nh, params[i].geom.steer_name)));
77  SteerCtrlConfig config;
78  copy(config, params[i].pos_ctrl);
79  dr->setConfigDefault(config);
80  dr->updateConfig(config);
81  dr->setCallback(boost::bind(&PosCtrl::setForOne, this, i, _1, _2)); // this writes the joint-specific config into pos_ctrl_params
82  reconfigure_server_axes_.push_back(dr);
83  }
84  }
85  private:
86  static void copy(PosCtrlParams &params, const SteerCtrlConfig &config){
87  params.dSpring = config.spring;
88  params.dDamp = config.damp;
89  params.dVirtM = config.virt_mass;
90  params.dDPhiMax = config.d_phi_max;
91  params.dDDPhiMax = config.dd_phi_max;
92  }
93  static void copy(SteerCtrlConfig &config, const PosCtrlParams &params){
94  config.spring = params.dSpring;
95  config.damp = params.dDamp;
96  config.virt_mass = params.dVirtM;
97  config.d_phi_max = params.dDPhiMax;
98  config.dd_phi_max = params.dDDPhiMax;
99  }
100  // these function don't get locked
101  void setForAll(SteerCtrlConfig &config, uint32_t /*level*/) {
102  ROS_INFO("configure all steers: s: %lf, d: %lf, m: %lf, v: %lf, a: %lf", config.spring, config.damp, config.virt_mass, config.d_phi_max, config.dd_phi_max);
103  for(size_t i=0; i< pos_ctrl_params.size(); ++i) {
104  copy(pos_ctrl_params[i], config);
105  if(!reconfigure_server_axes_.empty()){
106  reconfigure_server_axes_[i]->setConfigDefault(config);
107  reconfigure_server_axes_[i]->updateConfig(config);
108  }
109  }
110  updated = true;
111  }
112  void setForOne(size_t i, SteerCtrlConfig &config, uint32_t /*level*/) {
113  ROS_INFO("configure steer %d: s: %lf, d: %lf, m: %lf, v: %lf, a: %lf", (int)i, config.spring, config.damp, config.virt_mass, config.d_phi_max, config.dd_phi_max);
114  copy(pos_ctrl_params[i], config);
115  updated = true;
116  }
117  std::vector<PosCtrlParams> pos_ctrl_params;
118  boost::recursive_mutex mutex; // dynamic_reconfigure::Server calls the callback from the setCallback function
119  bool updated;
120  boost::scoped_ptr< dynamic_reconfigure::Server<SteerCtrlConfig> > reconfigure_server_;
121  std::vector<boost::shared_ptr< dynamic_reconfigure::Server<SteerCtrlConfig> > > reconfigure_server_axes_; // TODO: use unique_ptr
122  } pos_ctrl_;
123 
124 };
125 
126 }
127 
void setForOne(size_t i, SteerCtrlConfig &config, uint32_t)
bool parseWheelParams(std::vector< UndercarriageGeom::WheelParams > &params, const ros::NodeHandle &nh, bool read_urdf=true)
boost::scoped_ptr< dynamic_reconfigure::Server< SteerCtrlConfig > > reconfigure_server_
virtual void update(const ros::Time &time, const ros::Duration &period)
static void copy(PosCtrlParams &params, const SteerCtrlConfig &config)
void setForAll(SteerCtrlConfig &config, uint32_t)
void init(const wheel_params_t &params, const ros::NodeHandle &nh)
void configure(const std::vector< PosCtrlParams > &pos_ctrl)
#define ROS_INFO(...)
class cob_omni_drive_controller::WheelController::PosCtrl pos_ctrl_
std::vector< boost::shared_ptr< dynamic_reconfigure::Server< SteerCtrlConfig > > > reconfigure_server_axes_
bool init(Interface *hw, ros::NodeHandle &controller_nh)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
virtual bool init(hardware_interface::VelocityJointInterface *hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh)
static void copy(SteerCtrlConfig &config, const PosCtrlParams &params)


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