kmlMotBase.h
Go to the documentation of this file.
1 //
2 // C++ Interface: MotBase
3 //
4 // Description:
5 //
6 //
7 // Author: Tiziano Müller <tiziano.mueller@neuronics.ch>, (C) 2006
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 
13 #ifndef KMLMOTBASE_H
14 #define KMLMOTBASE_H
15 
16 #include "common/exception.h"
17 #include "common/dllexport.h"
18 
19 #include "KNI/kmlCommon.h"
20 #include "KNI/cplBase.h"
21 
22 #include <vector>
23 
24 class CKatBase; // forward declaration
25 class CMotBase; // forward declaration
26 
27 
28 /****************************************************************************/
29 // CMotBase ----------------------------------------------------------------//
30 /****************************************************************************/
31 
34 struct TMotDesc {
36 };
37 
40 struct TKatMOT {
41  short cnt;
44 };
45 
48 enum TMotCmdFlg {
49  MCF_OFF = 0,
50  MCF_CALIB = 4,
51  MCF_FREEZE = 8,
52  MCF_ON = 24,
54 };
55 
58 enum TMotStsFlg {
60  MSF_MAXPOS = 2,
61  MSF_MINPOS = 4,
62  MSF_DESPOS = 8,
65  MSF_NLINMOV = 88,
66  MSF_LINMOV = 152,
67  MSF_NOTVALID = 128
68 };
69 enum TSearchDir {
72 };
73 
74 
75 //--------------------------------------------------------------------------//
76 
79 struct TMotGNL {
82 };
83 
86 struct TMotSFW {
92 };
93 
96 struct TMotAPS {
98  short actpos;
99 };
100 
103 struct TMotTPS {
105  short tarpos;
106 };
107 
110 struct TMotSCP {
111 
112  //--------------- Motor old parameters -------------------------------//
113  //
120  //byte kSpeed; //!< prop. factor of speed limit comp
124 
125  //--------------- Motor new parameters -------------------------------//
126  //
134 };
135 
138 struct TMotDYL {
139 
140  //--------------- Motor old parameters -------------------------------//
141  //
144  short minpos;
145  short maxpspeed;
146  short maxnspeed;
147  //byte maxpcurr; // no more active
148  //byte maxncurr; // no more active
151 
152  //--------------- Motor new parameters -------------------------------//
153  //
158 };
159 
162 struct TMotPVP {
164  short pos;
165  short vel;
167 };
168 
171 struct TMotENL {
172  int enc_range;
177 };
178 
179 
182 struct TMotCLB {
183  bool enable;
184  short order;
185 
188 
191 
194 };
195 
196 
199 struct TMotInit {
202  double angleOffset;
203  double angleRange;
205 
206  // calculated ones:
207  double angleStop;
208 };
209 
210 //--------------------------------------------------------------------------//
211 
221 
222  friend class CKatBase;
223 
224 
225 protected:
236  bool freedom;
237  bool blocked;
238 
239 
240 public:
241  const TMotGNL* GetGNL() { return &gnl; }
242  const TMotAPS* GetAPS() { return &aps; }
243  const TMotTPS* GetTPS() { return &tps; }
244  const TMotSCP* GetSCP() { return &scp; }
245  const TMotDYL* GetDYL() { return &dyl; }
246  const TMotPVP* GetPVP() { return &pvp; }
247  const TMotSFW* GetSFW() { return &sfw; }
248  const TMotCLB* GetCLB() { return &_calibrationParameters; }
249 
250  const TMotInit* GetInitialParameters() { return &_initialParameters; }
251  int GetEncoderTolerance() { return _encoderLimits.enc_tolerance; }
252  int GetEncoderMinPos() { return _encoderLimits.enc_minpos; }
253  int GetEncoderMaxPos() { return _encoderLimits.enc_maxpos; }
254  int GetEncoderRange() { return _encoderLimits.enc_range; }
255 bool GetFreedom() { return freedom; }bool GetBlocked() { return blocked; }
260 
261 protected:
263 
264 public:
265  virtual ~CMotBase() {} //destructor
266 
267  bool init(CKatBase* _own, const TMotDesc _motDesc, CCplBase* protocol);
268  void sendAPS(const TMotAPS* _aps); void sendTPS(const TMotTPS* _tps);
273  void recvPVP(); void recvSFW();
278 
279  void setSCP(TMotSCP _scp) { scp = _scp; }
280  void setDYL(TMotDYL _dyl) { dyl = _dyl; }
281 
282 
283  void setInitialParameters(double angleOffset, double angleRange, int encodersPerCycle, int encoderOffset, int rotationDirection);
284  void setCalibrationParameters(bool doCalibration, short order, TSearchDir direction, TMotCmdFlg motorFlagAfter, int encoderPositionAfter);
285  void setCalibrated(bool calibrated);
286 
287  void setTolerance(int tolerance);
288 
291  bool checkAngleInRange(double angle);
292  bool checkEncoderInRange(int encoder);
293 
296  void inc(int dif, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
299  void dec(int dif, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
302  void mov(int tar, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
303 
306  void waitForMotor(int tar, int encTolerance = 100, short mode = 0, int waitTimeout = TM_ENDLESS);
307 
310  void incDegrees(double dif, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
313  void decDegrees(double dif, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
316  void movDegrees(double tar, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
317 
320  void resetBlocked();
321 
322 
326  void sendSpline(short targetPosition, short duration, short p1, short p2, short p3, short p4);
327 
330  void setSpeedLimits(short positiveVelocity, short negativeVelocity);
331  void setSpeedLimit(short velocity) { setSpeedLimits(velocity, velocity); }
332 
335  void setAccelerationLimit( short acceleration );
336 
339  void setPwmLimits(byte maxppwm, byte maxnpwm);
340 
343  void setControllerParameters(byte kSpeed, byte kPos, byte kI);
344 
347  void setCrashLimit(int limit);
349  void setCrashLimitLinear(int limit_lin);
351  void setSpeedCollisionLimit(int limit);
353  void setPositionCollisionLimit(int limit);
354 
361  void getParameterOrLimit(int subcommand, byte* R1, byte* R2, byte* R3);
362 };
363 
364 
365 #endif
short actpos
actual position
Definition: kmlMotBase.h:98
int acceleration
TMotCmdFlg mcf
motor flag after calibration
Definition: kmlMotBase.h:187
motor data not valid
Definition: kmlMotBase.h:67
byte actcurr
actual current
Definition: kmlMotBase.h:150
unsigned char byte
type specification (8 bit)
Definition: cdlBase.h:29
TMotTPS tps
target position
Definition: kmlMotBase.h:228
int encoderPositionAfter
Definition: kmlMotBase.h:189
const TMotCLB * GetCLB()
Definition: kmlMotBase.h:248
[PVP] position, velocity, pulse width modulation
Definition: kmlMotBase.h:162
byte maxppwm
max. val for pos. voltage
Definition: kmlMotBase.h:114
virtual bool init(const TKatGNL _gnl, const TKatMOT _mot, const TKatSCT _sct, const TKatEFF _eff, CCplBase *_protocol)
Definition: kmlBase.cpp:27
TMotPVP pvp
reading motor parameters
Definition: kmlMotBase.h:231
byte kI_speed
Integral factor of the speed compensator.
Definition: kmlMotBase.h:122
TMotInit _initialParameters
Definition: kmlMotBase.h:235
CCplBase * protocol
protocol interface
Definition: kmlMotBase.h:262
int GetEncoderMinPos()
Returns the min Position of the Encoder.
Definition: kmlMotBase.h:252
setControllerParameters
Definition: KNI.py:171
byte kD
derivate factor of pos comp
Definition: kmlMotBase.h:118
Abstract base class for protocol definiton.
Definition: cplBase.h:47
[SFW] slave firmware
Definition: kmlMotBase.h:86
TMotGNL gnl
motor generals
Definition: kmlMotBase.h:226
bool enable
enable/disable
Definition: kmlMotBase.h:183
TMotSCP scp
Definition: kmlMotBase.h:193
int enc_per_cycle
number of encoder units needed to complete 360 degrees;
Definition: kmlMotBase.h:175
motor has crashed, new: collision
Definition: kmlMotBase.h:64
#define DLLDIR
Definition: dllexport.h:30
const TMotPVP * GetPVP()
Definition: kmlMotBase.h:246
int encoderOffset
Definition: kmlMotBase.h:200
void setSpeedCollisionLimit(long idx, int limit)
set collision speed limits
Definition: kmlBase.cpp:213
const TMotTPS * GetTPS()
Definition: kmlMotBase.h:243
Initial motor parameters.
Definition: kmlMotBase.h:199
byte kI
not yet active
Definition: kmlMotBase.h:117
int encodersPerCycle
Definition: kmlMotBase.h:201
non-linear movement ended, new: poly move finished
Definition: kmlMotBase.h:65
#define TM_ENDLESS
timeout symbol for &#39;endless&#39; waiting
Definition: kmlBase.h:51
const TMotAPS * GetAPS()
Definition: kmlMotBase.h:242
Base Katana class.
Definition: kmlBase.h:132
[TPS] target position
Definition: kmlMotBase.h:103
byte kD_speed
Derivative factor of the speed compensator.
Definition: kmlMotBase.h:123
CKatBase * own
parent robot
Definition: kmlMotBase.h:80
int GetEncoderTolerance()
Definition: kmlMotBase.h:251
CMotBase * arr
array of motors
Definition: kmlMotBase.h:42
clear the movebuffer
Definition: kmlMotBase.h:53
calibrate
Definition: kmlMotBase.h:50
byte maxppwm_nmp
Max. value for positive voltage (0 => 0%, +70 => 100%)
Definition: kmlMotBase.h:127
byte revision
firmware revision number
Definition: kmlMotBase.h:89
[APS] actual position
Definition: kmlMotBase.h:96
byte kARW
not yet active
Definition: kmlMotBase.h:119
TSearchDir
Definition: kmlMotBase.h:69
[GNL] motor generals
Definition: kmlMotBase.h:79
TMotStsFlg
status flags
Definition: kmlMotBase.h:58
[ENL] limits in encoder values (INTERNAL STRUCTURE!)
Definition: kmlMotBase.h:171
bool freedom
if it is set, it will move on a parallel movement
Definition: kmlMotBase.h:236
short maxnspeed
max. allowed reverse speed; pos!
Definition: kmlMotBase.h:146
virtual ~CMotBase()
Definition: kmlMotBase.h:265
byte maxnpwm
max. val for neg. voltage; pos!
Definition: kmlMotBase.h:115
byte maxcurr
max current
Definition: kmlMotBase.h:149
int crash_limit_lin_nmp
Limit of error in position in linear movement.
Definition: kmlMotBase.h:133
bool blocked
true if the motor was blocked due to a crash of the robot
Definition: kmlMotBase.h:237
[DYL] dynamic limits
Definition: kmlMotBase.h:138
const TMotDYL * GetDYL()
Definition: kmlMotBase.h:245
TMotSFW sfw
slave firmware
Definition: kmlMotBase.h:232
bool isCalibrated
Definition: kmlMotBase.h:190
double angleStop
Definition: kmlMotBase.h:207
Calibration structure for single motors.
Definition: kmlMotBase.h:182
byte subtype
slave subtype
Definition: kmlMotBase.h:91
[MOT] every motor&#39;s attributes
Definition: kmlMotBase.h:40
setPositionCollisionLimit
Definition: KNI.py:175
void setSCP(TMotSCP _scp)
Definition: kmlMotBase.h:279
TMotAPS aps
actual position
Definition: kmlMotBase.h:227
search direction for the meachanical stopper
Definition: kmlMotBase.h:70
TMotCLB _calibrationParameters
calibration structure
Definition: kmlMotBase.h:233
byte kI_nmp
Integral factor (1/kI) of control output added to the final control output.
Definition: kmlMotBase.h:131
byte SID
slave ID
Definition: kmlMotBase.h:81
int rotationDirection
Definition: kmlMotBase.h:204
short maxpspeed
max. allowed forward speed
Definition: kmlMotBase.h:145
const TMotGNL * GetGNL()
Definition: kmlMotBase.h:241
short minpos
not yet active
Definition: kmlMotBase.h:144
double angleRange
Definition: kmlMotBase.h:203
short tarpos
target position
Definition: kmlMotBase.h:105
[SCP] static controller parameters
Definition: kmlMotBase.h:110
TMotDesc * desc
description[]
Definition: kmlMotBase.h:43
TMotDYL dyl
dynamic limits
Definition: kmlMotBase.h:230
byte slvID
slave number
Definition: kmlMotBase.h:35
min. position was reached, new: calibrating
Definition: kmlMotBase.h:61
void setSpeedLimit(short velocity)
Definition: kmlMotBase.h:331
byte maxcurr_nmp
set the maximal current
Definition: kmlMotBase.h:157
linear movement ended, new: moving poly, polymb full
Definition: kmlMotBase.h:66
double angleOffset
Definition: kmlMotBase.h:202
short pos
position
Definition: kmlMotBase.h:164
FloatVector * angle
int enc_minpos
motor&#39;s minimum position in encoder values
Definition: kmlMotBase.h:173
int crash_limit_nmp
Limit of error in position.
Definition: kmlMotBase.h:132
TMotSCP scp
static controller parameters
Definition: kmlMotBase.h:229
const TMotInit * GetInitialParameters()
Definition: kmlMotBase.h:250
short order
order in which this motor will be calibrated. range: 0..5
Definition: kmlMotBase.h:184
int enc_maxpos
motor&#39;s maximum position in encoder values
Definition: kmlMotBase.h:174
TSearchDir dir
search direction for mech. stopper
Definition: kmlMotBase.h:186
byte kP_speed
Proportional factor of the speed compensator.
Definition: kmlMotBase.h:121
short cnt
count of motors
Definition: kmlMotBase.h:41
TMotStsFlg msf
motor status flag
Definition: kmlMotBase.h:163
set the motor on
Definition: kmlMotBase.h:52
motor description (partly)
Definition: kmlMotBase.h:34
void setCrashLimit(long idx, int limit)
set collision limits
Definition: kmlBase.cpp:197
int velocity
byte maxdecel
max deceleration
Definition: kmlMotBase.h:143
const TMotSFW * GetSFW()
Definition: kmlMotBase.h:247
Motor class.
Definition: kmlMotBase.h:220
short vel
velocity
Definition: kmlMotBase.h:165
max. position was reached, new: unused
Definition: kmlMotBase.h:60
int GetEncoderRange()
Returns Encoder Range of the Encoder.
Definition: kmlMotBase.h:254
TMotCmdFlg mcfAPS
motor command flag
Definition: kmlMotBase.h:97
TKatGNL gnl
katana general
Definition: kmlBase.h:135
byte type
controller type
Definition: kmlMotBase.h:90
byte maxaccel_nmp
Maximal acceleration and deceleration.
Definition: kmlMotBase.h:154
byte maxaccel
max acceleration
Definition: kmlMotBase.h:142
TMotCmdFlg
command flags
Definition: kmlMotBase.h:48
byte subversion
firmware subversion number
Definition: kmlMotBase.h:88
freeze the motor
Definition: kmlMotBase.h:51
byte maxnpwm_nmp
Max. value for negative voltage (0 => 0%, +70 => 100%)
Definition: kmlMotBase.h:128
trying to follow target, new: moving (polymb not full)
Definition: kmlMotBase.h:63
void setDYL(TMotDYL _dyl)
Definition: kmlMotBase.h:280
TMotDYL dyl
Definition: kmlMotBase.h:192
int enc_range
motor&#39;s range in encoder values
Definition: kmlMotBase.h:172
TMotCmdFlg mcfTPS
motor command flag
Definition: kmlMotBase.h:104
int GetEncoderMaxPos()
Returns the max Position of the Encoder.
Definition: kmlMotBase.h:253
byte pwm
pulse with modulation
Definition: kmlMotBase.h:166
byte kP
prop. factor of pos comp
Definition: kmlMotBase.h:116
short maxpspeed_nmp
Max. allowed forward speed.
Definition: kmlMotBase.h:155
int enc_tolerance
encoder units of tolerance to accept that a position has been reached
Definition: kmlMotBase.h:176
const TMotSCP * GetSCP()
Definition: kmlMotBase.h:244
byte version
firmware version number
Definition: kmlMotBase.h:87
byte kpos_nmp
Proportional factor of position compensator.
Definition: kmlMotBase.h:130
in desired position, new: fixed, state holding
Definition: kmlMotBase.h:62
short maxnspeed_nmp
Max. allowed reverse speed.
Definition: kmlMotBase.h:156
TMotENL _encoderLimits
motor limits in encoder values
Definition: kmlMotBase.h:234
mechanical stopper reached, new: unused (default value)
Definition: kmlMotBase.h:59
byte kspeed_nmp
Proportional factor of speed compensator.
Definition: kmlMotBase.h:129
set the motor off
Definition: kmlMotBase.h:49


kni
Author(s): Martin Günther
autogenerated on Fri Jun 7 2019 22:06:44