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 
cob_omni_drive_controller::WheelController::PosCtrl::init
void init(const wheel_params_t &params, const ros::NodeHandle &nh)
Definition: control_plugin.cpp:62
PosCtrlParams
Definition: UndercarriageCtrlGeom.h:254
cob_omni_drive_controller::WheelController::pos_ctrl_
class cob_omni_drive_controller::WheelController::PosCtrl pos_ctrl_
cob_omni_drive_controller::parseWheelParams
bool parseWheelParams(std::vector< UndercarriageGeom::WheelParams > &params, const ros::NodeHandle &nh, bool read_urdf=true)
Definition: param_parser.cpp:270
boost::shared_ptr
cob_omni_drive_controller::GeomControllerBase< hardware_interface::VelocityJointInterface ::ResourceHandleType, UndercarriageCtrl >::geom_
boost::scoped_ptr< UndercarriageCtrl > geom_
Definition: GeomController.h:33
cob_omni_drive_controller::GeomControllerBase< hardware_interface::VelocityJointInterface ::ResourceHandleType, UndercarriageCtrl >::drive_joints_
std::vector< hardware_interface::VelocityJointInterface ::ResourceHandleType > drive_joints_
Definition: GeomController.h:31
cob_omni_drive_controller::GeomControllerBase< hardware_interface::VelocityJointInterface ::ResourceHandleType, UndercarriageCtrl >::updateState
void updateState()
Definition: GeomController.h:36
WheelControllerBase.h
GeomController.h
cob_omni_drive_controller::GeomController< hardware_interface::VelocityJointInterface, UndercarriageCtrl >::wheel_params_t
std::vector< typename UndercarriageCtrl ::WheelParams > wheel_params_t
Definition: GeomController.h:62
cob_omni_drive_controller::WheelControllerBase
Definition: WheelControllerBase.h:39
cob_omni_drive_controller::WheelController::init
virtual bool init(hardware_interface::VelocityJointInterface *hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh)
Definition: control_plugin.cpp:30
cob_omni_drive_controller::WheelController::PosCtrl::PosCtrl
PosCtrl()
Definition: control_plugin.cpp:54
PosCtrlParams::dDPhiMax
double dDPhiMax
Definition: UndercarriageCtrlGeom.h:265
PosCtrlParams::dVirtM
double dVirtM
Definition: UndercarriageCtrlGeom.h:265
cob_omni_drive_controller::WheelController::PosCtrl
Definition: control_plugin.cpp:52
cob_omni_drive_controller::WheelController::PosCtrl::reconfigure_server_
boost::scoped_ptr< dynamic_reconfigure::Server< SteerCtrlConfig > > reconfigure_server_
Definition: control_plugin.cpp:120
PosCtrlParams::dDDPhiMax
double dDDPhiMax
Definition: UndercarriageCtrlGeom.h:265
cob_omni_drive_controller::WheelController::PosCtrl::copy
static void copy(PosCtrlParams &params, const SteerCtrlConfig &config)
Definition: control_plugin.cpp:86
cob_omni_drive_controller::WheelController
Definition: control_plugin.cpp:27
cob_omni_drive_controller::WheelController::PosCtrl::updated
bool updated
Definition: control_plugin.cpp:119
UndercarriageCtrl::configure
void configure(const std::vector< PosCtrlParams > &pos_ctrl)
Definition: UndercarriageCtrlGeom.cpp:211
cob_omni_drive_controller::WheelController::PosCtrl::copy
static void copy(SteerCtrlConfig &config, const PosCtrlParams &params)
Definition: control_plugin.cpp:93
controller_interface::ControllerBase
cob_omni_drive_controller::WheelControllerBase< GeomController< hardware_interface::VelocityJointInterface, UndercarriageCtrl > >::setup
bool setup(ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh)
Definition: WheelControllerBase.h:42
hardware_interface::VelocityJointInterface
cob_omni_drive_controller::WheelController::PosCtrl::mutex
boost::recursive_mutex mutex
Definition: control_plugin.cpp:118
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
PosCtrlParams::dSpring
double dSpring
Definition: UndercarriageCtrlGeom.h:265
cob_omni_drive_controller::WheelController::PosCtrl::try_configure
void try_configure(UndercarriageCtrl &ctrl)
Definition: control_plugin.cpp:55
cob_omni_drive_controller::WheelController::update
virtual void update(const ros::Time &time, const ros::Duration &period)
Definition: control_plugin.cpp:39
PosCtrlParams::dDamp
double dDamp
Definition: UndercarriageCtrlGeom.h:265
cob_omni_drive_controller::WheelControllerBase< GeomController< hardware_interface::VelocityJointInterface, UndercarriageCtrl > >::updateCtrl
void updateCtrl(const ros::Time &time, const ros::Duration &period)
Definition: WheelControllerBase.h:80
cob_omni_drive_controller::WheelControllerBase< GeomController< hardware_interface::VelocityJointInterface, UndercarriageCtrl > >::wheel_commands_
std::vector< WheelCommand > wheel_commands_
Definition: WheelControllerBase.h:128
ros::Time
cob_omni_drive_controller::GeomController::init
bool init(Interface *hw, ros::NodeHandle &controller_nh)
Definition: GeomController.h:63
UndercarriageCtrl
Definition: UndercarriageCtrlGeom.h:295
cob_omni_drive_controller::GeomControllerBase< hardware_interface::VelocityJointInterface ::ResourceHandleType, UndercarriageCtrl >::steer_joints_
std::vector< hardware_interface::VelocityJointInterface ::ResourceHandleType > steer_joints_
Definition: GeomController.h:30
ROS_INFO
#define ROS_INFO(...)
ros::Duration
cob_omni_drive_controller::WheelController::PosCtrl::pos_ctrl_params
std::vector< PosCtrlParams > pos_ctrl_params
Definition: control_plugin.cpp:117
cob_omni_drive_controller::WheelController::PosCtrl::reconfigure_server_axes_
std::vector< boost::shared_ptr< dynamic_reconfigure::Server< SteerCtrlConfig > > > reconfigure_server_axes_
Definition: control_plugin.cpp:121
ros::NodeHandle
cob_omni_drive_controller::WheelController::PosCtrl::setForOne
void setForOne(size_t i, SteerCtrlConfig &config, uint32_t)
Definition: control_plugin.cpp:112
cob_omni_drive_controller::WheelController::PosCtrl::setForAll
void setForAll(SteerCtrlConfig &config, uint32_t)
Definition: control_plugin.cpp:101
cob_omni_drive_controller
Definition: UndercarriageCtrlGeomROS.h:24


cob_omni_drive_controller
Author(s): Christian Connette, Mathias Lüdtke
autogenerated on Mon May 1 2023 02:44:36