UndercarriageCtrlGeom.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 UndercarriageCtrlGeom_INCLUDEDEF_H
19 #define UndercarriageCtrlGeom_INCLUDEDEF_H
20 
21 #include <vector>
22 #include <string>
23 #include <stdexcept>
24 #include <boost/make_shared.hpp>
25 
27  double dVelLongMMS;
28  double dVelLatMMS;
29  double dRotRobRadS;
30 
31  const double getVelX() { return dVelLongMMS / 1000.0; }
32  const double getVelY() { return dVelLatMMS / 1000.0; }
33 
34  void setVelX(const double val) { dVelLongMMS = val * 1000.0; }
35  void setVelY(const double val) { dVelLatMMS = val * 1000.0; }
36 
37  PlatformState() : dVelLongMMS(0), dVelLatMMS(0),dRotRobRadS(0) {}
38 };
39 struct WheelState {
43  WheelState() : dVelGearDriveRadS(0), dVelGearSteerRadS(0), dAngGearSteerRad(0) {}
44 };
45 struct WheelCommand : public WheelState {
47  WheelCommand() : dAngGearSteerRadDelta(0) {}
48 };
49 struct WheelGeom{
50  std::string steer_name, drive_name;
51 
56  double dWheelXPosMM;
57  double dWheelYPosMM;
58 
60 
63 
64 };
65 struct WheelData {
67 
72  double dFactorVel;
73 
75 
84 
86 
87  void updateState(const WheelState &state);
88  double getVelX() const;
89  double getVelY() const;
90 
91  static double mergeRotRobRadS(const WheelData &wheel1, const WheelData &wheel2);
92 
93  WheelData(const WheelGeom &geom)
94  : geom_(geom),
95  dFactorVel(-geom_.dSteerDriveCoupling + geom_.dDistSteerAxisToDriveWheelMM / geom_.dRadiusWheelMM) {
96  updateState(WheelState());
97  }
98 };
99 
101 {
102 public:
103  // Get result of direct kinematics
104  virtual void calcDirect(PlatformState &state) const = 0;
105 
106  // Set actual values of wheels (steer/drive velocity/position) (Istwerte)
107  virtual void updateWheelStates(const std::vector<WheelState> &states) = 0;
108 
110 
111 protected:
112  template<typename V> static void updateWheelStates(V& wheels, const std::vector<WheelState> &states)
113  {
114  if(wheels.size() != states.size()) throw std::length_error("number of states does not match number of wheels");
115 
116  for(size_t i = 0; i < wheels.size(); ++i){
117  wheels[i]->updateState(states[i]);
118  }
119  }
120 
121  template<typename V> static void calcDirect(PlatformState &state, const V& wheels)
122  {
123  double dtempRotRobRADPS = 0; // Robot-Rotation-Rate in rad/s (in Robot-Coordinateframe)
124  double dtempVelXRobMMS = 0; // Robot-Velocity in x-Direction (longitudinal) in mm/s (in Robot-Coordinateframe)
125  double dtempVelYRobMMS = 0; // Robot-Velocity in y-Direction (lateral) in mm/s (in Robot-Coordinateframe)
126 
127  // calculate rotational rate of robot and current "virtual" axis between all wheels
128  for(int i = 0; i < wheels.size() ; i++)
129  {
130  const WheelData &wheel = *wheels[i];
131  const WheelData &other_wheel = *wheels[(i+1) % wheels.size()];
132 
133  dtempRotRobRADPS += WheelData::mergeRotRobRadS(wheel, other_wheel);
134  dtempVelXRobMMS += wheel.getVelX();
135  dtempVelYRobMMS += wheel.getVelY();
136  }
137 
138  // assign rotational velocities for output
139  state.dRotRobRadS = dtempRotRobRADPS/wheels.size();
140 
141  // assign linear velocity of robot for output
142  state.dVelLongMMS = dtempVelXRobMMS/wheels.size();
143  state.dVelLatMMS = dtempVelYRobMMS/wheels.size();
144 
145  }
146 
147 };
148 
150 public:
151  struct WheelParams {
153  };
154 
155  // Constructor
156  UndercarriageGeom(const std::vector<WheelParams> &params);
157 
158  // Get result of direct kinematics
159  virtual void calcDirect(PlatformState &state) const;
160 
161  // Set actual values of wheels (steer/drive velocity/position) (Istwerte)
162  virtual void updateWheelStates(const std::vector<WheelState> &states);
163 
164 private:
165  std::vector<boost::shared_ptr<WheelData> > wheels_;
166 };
167 
168 double limitValue(double value, double limit);
169 
170 template<typename T> class UndercarriageCtrlBase : public UndercarriageGeomBase {
171 public:
172  // Constructor
173  template<typename T2> UndercarriageCtrlBase(const std::vector<T2> &params){
174  for(typename std::vector<T2>::const_iterator it = params.begin(); it != params.end(); ++it){
175  wheels_.push_back(boost::make_shared<T>(*it));
176  }
177  }
178 
179  // Get result of direct kinematics
180  virtual void calcDirect(PlatformState &state) const {
181  UndercarriageGeomBase::calcDirect(state, wheels_);
182  }
183 
184  // Set actual values of wheels (steer/drive velocity/position) (Istwerte)
185  virtual void updateWheelStates(const std::vector<WheelState> &states) {
187  }
188  // Set desired value for Plattform Velocity to UndercarriageCtrl (Sollwertvorgabe)
189  void setTarget(const PlatformState &state) {
190  for(size_t i = 0; i < wheels_.size(); ++i){
191  wheels_[i]->setTarget(state);
192  }
193  }
194 
195  // Get set point values for the Wheels (including controller) from UndercarriangeCtrl
196  void calcControlStep(std::vector<WheelCommand> &commands, double dCmdRateS, bool reset) {
197  commands.resize(wheels_.size());
198 
199  for(size_t i = 0; i < wheels_.size(); ++i){
200  wheels_[i]->calcControlStep(commands[i], dCmdRateS, reset);
201  }
202  }
203 
204  void reset() {
205  for(size_t i = 0; i < wheels_.size(); ++i){
206  wheels_[i]->reset();
207  }
208  }
209 
210 protected:
211  std::vector<boost::shared_ptr<T> > wheels_;
212 };
213 
214 struct CtrlParams{
216 
219 };
220 
224 };
225 
226 struct CtrlData : public WheelData {
228 
229  double m_dAngGearSteerTargetRad; // choosen alternativ for steering angle
231 
232  // calculate inverse kinematics
233  void setTarget(const PlatformState &state);
234 
235  virtual void calcControlStep(WheelCommand &command, double dCmdRateS, bool reset);
236 
237  virtual void reset();
238 
239  template<typename P> CtrlData(const P &params)
240  : WheelData(params.geom), params_(params.ctrl) {
241  state_.dAngGearSteerRad = params_.dWheelNeutralPos;
242  updateState(WheelState());
243  setTarget(PlatformState());
244  m_dAngGearSteerTargetRad = params_.dWheelNeutralPos;
245  }
246 };
247 
248 class UndercarriageDirectCtrl : public UndercarriageCtrlBase < CtrlData > {
249 public:
251  UndercarriageDirectCtrl(const std::vector<WheelParams> &params) : UndercarriageCtrlBase(params) {}
252 };
253 
265  double dSpring, dDamp, dVirtM, dDPhiMax, dDDPhiMax;
266 };
267 
272 };
273 
274 struct PosCtrlData : public CtrlData {
276 
277  // previous Commanded deltaPhi e(k-1)
278  // double m_dCtrlDeltaPhi; not used
279  // previous Commanded Velocity u(k-1)
281 
282  virtual void calcControlStep(WheelCommand &command, double dCmdRateS, bool reset);
283 
284  virtual void reset();
285 
287  : CtrlData(params), pos_params_(params.pos_ctrl),m_dCtrlVelCmdInt(0) {
288  state_.dAngGearSteerRad = params_.dWheelNeutralPos;
289  updateState(WheelState());
290  setTarget(PlatformState());
291  m_dAngGearSteerTargetRad = params_.dWheelNeutralPos;
292  }
293 };
294 
295 class UndercarriageCtrl : public UndercarriageCtrlBase < PosCtrlData > {
296 public:
298  void configure(const std::vector<PosCtrlParams> &pos_ctrl);
299  UndercarriageCtrl(const std::vector<WheelParams> &params) : UndercarriageCtrlBase(params) {}
300 };
301 
302 #endif
WheelData(const WheelGeom &geom)
void setVelY(const double val)
CtrlData(const P &params)
double dSteerDriveCoupling
virtual void calcDirect(PlatformState &state) const
const double getVelY()
void setTarget(const PlatformState &state)
PosCtrlData(const WheelCtrlPosParams &params)
PosCtrlParams pos_params_
virtual void updateWheelStates(const std::vector< WheelState > &states)
CtrlParams params_
static double mergeRotRobRadS(const WheelData &wheel1, const WheelData &wheel2)
std::vector< boost::shared_ptr< T > > wheels_
static void updateWheelStates(V &wheels, const std::vector< WheelState > &states)
WheelCtrlPosParams WheelParams
std::vector< boost::shared_ptr< WheelData > > wheels_
double getVelX() const
void calcControlStep(std::vector< WheelCommand > &commands, double dCmdRateS, bool reset)
UndercarriageCtrl(const std::vector< WheelParams > &params)
const double getVelX()
WheelState state_
double limitValue(double value, double limit)
double dDistSteerAxisToDriveWheelMM
UndercarriageCtrlBase(const std::vector< T2 > &params)
static void calcDirect(PlatformState &state, const V &wheels)
std::string steer_name
double getVelY() const
double m_dVelGearDriveTargetRadS
virtual void updateWheelStates(const std::vector< WheelState > &states)=0
void setVelX(const double val)
double m_dAngGearSteerTargetRad
virtual void calcDirect(PlatformState &state) const =0
UndercarriageDirectCtrl(const std::vector< WheelParams > &params)


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