KatanaNativeInterface  $VERSION$
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
53 };
54 
57 enum TMotStsFlg {
59  MSF_MAXPOS = 2,
60  MSF_MINPOS = 4,
61  MSF_DESPOS = 8,
64  MSF_NLINMOV = 88,
65  MSF_LINMOV = 152,
66  MSF_NOTVALID = 128
67 };
68 enum TSearchDir {
71 };
72 
73 
74 //--------------------------------------------------------------------------//
75 
78 struct TMotGNL {
81 };
82 
85 struct TMotSFW {
91 };
92 
95 struct TMotAPS {
97  short actpos;
98 };
99 
102 struct TMotTPS {
104  short tarpos;
105 };
106 
109 struct TMotSCP {
110 
111  //--------------- Motor old parameters -------------------------------//
112  //
119  //byte kSpeed; //!< prop. factor of speed limit comp
123 
124  //--------------- Motor new parameters -------------------------------//
125  //
133 };
134 
137 struct TMotDYL {
138 
139  //--------------- Motor old parameters -------------------------------//
140  //
143  short minpos;
144  short maxpspeed;
145  short maxnspeed;
146  //byte maxpcurr; // no more active
147  //byte maxncurr; // no more active
150 
151  //--------------- Motor new parameters -------------------------------//
152  //
157 };
158 
161 struct TMotPVP {
163  short pos;
164  short vel;
166 };
167 
170 struct TMotENL {
171  int enc_range;
176 };
177 
178 
181 struct TMotCLB {
182  bool enable;
183  short order;
184 
187 
190 
193 };
194 
195 
198 struct TMotInit {
201  double angleOffset;
202  double angleRange;
204 
205  // calculated ones:
206  double angleStop;
207 };
208 
209 //--------------------------------------------------------------------------//
210 
220 
221  friend class CKatBase;
222 
223 
224 protected:
235  bool freedom;
236  bool nmp;
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  const int GetEncoderTolerance() { return _encoderLimits.enc_tolerance; }
252  const int GetEncoderMinPos() { return _encoderLimits.enc_minpos; }
253  const int GetEncoderMaxPos() { return _encoderLimits.enc_maxpos; }
254  const int GetEncoderRange() { return _encoderLimits.enc_range; }
255 const bool GetFreedom() { return freedom; }const bool GetBlocked() { return blocked; }const bool GetNmp() { return nmp; }
262 
263 protected:
265 
266 public:
267  virtual ~CMotBase() {} //destructor
268 
269  bool init(CKatBase* _own, const TMotDesc _motDesc, CCplBase* protocol);
270  void sendAPS(const TMotAPS* _aps); void sendTPS(const TMotTPS* _tps); void sendSCP(const TMotSCP* _scp); void sendDYL(const TMotDYL* _dyl);
279  void recvPVP(); void recvSCP(); void recvDYL(); void recvSFW();
288 
289  void setSCP(TMotSCP _scp) { scp = _scp; }
290  void setDYL(TMotDYL _dyl) { dyl = _dyl; }
291 
296  void setTPSP(int tar);
297  void setTPSPDegrees(double tar); void resetTPSP();
302 
303 
304  void setInitialParameters(double angleOffset, double angleRange, int encodersPerCycle, int encoderOffset, int rotationDirection);
305  void setCalibrationParameters(bool doCalibration, short order, TSearchDir direction, TMotCmdFlg motorFlagAfter, int encoderPositionAfter);
306  void setCalibrated(bool calibrated);
307 
308  void setTolerance(int tolerance);
309 
312  bool checkAngleInRange(double angle);
313  bool checkEncoderInRange(int encoder);
314 
317  void inc(int dif, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
320  void dec(int dif, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
323  void mov(int tar, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
324 
327  void waitForMotor(int tar, int encTolerance = 100, short mode = 0, int waitTimeout = TM_ENDLESS);
328 
331  void incDegrees(double dif, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
334  void decDegrees(double dif, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
337  void movDegrees(double tar, bool wait = false, int tolerance = 100, long timeout = TM_ENDLESS);
338 
341  void resetBlocked();
342 
343 
347  void sendSpline(short targetPosition, short duration, short p1, short p2, short p3, short p4);
348 
353  void sendFourSplines(short targetPosition, short duration, std::vector<short>& coefficients);
354 
355 
358  void setSpeedLimits(short positiveVelocity, short negativeVelocity);
359  void setSpeedLimit(short velocity) { setSpeedLimits(velocity, velocity); }
360 
363  void setAccelerationLimit( short acceleration );
364 
367  void setPwmLimits(byte maxppwm, byte maxnpwm);
368 
371  void setControllerParameters(byte kSpeed, byte kPos, byte kI);
372 
375  void setCrashLimit(int limit);
377  void setCrashLimitLinear(int limit_lin);
379  void setSpeedCollisionLimit(int limit);
381  void setPositionCollisionLimit(int limit);
382 
389  void getParameterOrLimit(int subcommand, byte* R1, byte* R2, byte* R3);
390 };
391 
392 
393 #endif
short actpos
actual position
Definition: kmlMotBase.h:97
TMotCmdFlg mcf
motor flag after calibration
Definition: kmlMotBase.h:186
motor data not valid
Definition: kmlMotBase.h:66
byte actcurr
actual current
Definition: kmlMotBase.h:149
unsigned char byte
type specification (8 bit)
Definition: cdlBase.h:29
TMotTPS tps
target position
Definition: kmlMotBase.h:227
int encoderPositionAfter
Definition: kmlMotBase.h:188
const TMotCLB * GetCLB()
Definition: kmlMotBase.h:248
[PVP] position, velocity, pulse width modulation
Definition: kmlMotBase.h:161
byte maxppwm
max. val for pos. voltage
Definition: kmlMotBase.h:113
TMotPVP pvp
reading motor parameters
Definition: kmlMotBase.h:230
byte kI_speed
Integral factor of the speed compensator.
Definition: kmlMotBase.h:121
TMotInit _initialParameters
Definition: kmlMotBase.h:234
CCplBase * protocol
protocol interface
Definition: kmlMotBase.h:264
byte kD
derivate factor of pos comp
Definition: kmlMotBase.h:117
Abstract base class for protocol definiton.
Definition: cplBase.h:47
[SFW] slave firmware
Definition: kmlMotBase.h:85
TMotGNL gnl
motor generals
Definition: kmlMotBase.h:225
bool enable
enable/disable
Definition: kmlMotBase.h:182
TMotSCP scp
Definition: kmlMotBase.h:192
int enc_per_cycle
number of encoder units needed to complete 360 degrees;
Definition: kmlMotBase.h:174
const int GetEncoderTolerance()
Definition: kmlMotBase.h:251
motor has crashed
Definition: kmlMotBase.h:63
#define DLLDIR
Definition: dllexport.h:30
const TMotPVP * GetPVP()
Definition: kmlMotBase.h:246
int encoderOffset
Definition: kmlMotBase.h:199
void setSpeedCollisionLimit(long idx, int limit)
set collision speed limits
const TMotTPS * GetTPS()
Definition: kmlMotBase.h:243
Initial motor parameters.
Definition: kmlMotBase.h:198
byte kI
not yet active
Definition: kmlMotBase.h:116
int encodersPerCycle
Definition: kmlMotBase.h:200
non-linear movement ended
Definition: kmlMotBase.h:64
#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:102
byte kD_speed
Derivative factor of the speed compensator.
Definition: kmlMotBase.h:122
CKatBase * own
parent robot
Definition: kmlMotBase.h:79
CMotBase * arr
array of motors
Definition: kmlMotBase.h:42
calibrate
Definition: kmlMotBase.h:50
byte maxppwm_nmp
Max. value for positive voltage (0 => 0%, +70 => 100%)
Definition: kmlMotBase.h:126
byte revision
firmware revision number
Definition: kmlMotBase.h:88
[APS] actual position
Definition: kmlMotBase.h:95
byte kARW
not yet active
Definition: kmlMotBase.h:118
TSearchDir
Definition: kmlMotBase.h:68
[GNL] motor generals
Definition: kmlMotBase.h:78
TMotStsFlg
status flags
Definition: kmlMotBase.h:57
[ENL] limits in encoder values (INTERNAL STRUCTURE!)
Definition: kmlMotBase.h:170
bool freedom
if it is set, it will move on a parallel movement
Definition: kmlMotBase.h:235
short maxnspeed
max. allowed reverse speed; pos!
Definition: kmlMotBase.h:145
bool nmp
true if new motor parameters are implemented on the firmware
Definition: kmlMotBase.h:236
virtual ~CMotBase()
Definition: kmlMotBase.h:267
byte maxnpwm
max. val for neg. voltage; pos!
Definition: kmlMotBase.h:114
byte maxcurr
max current
Definition: kmlMotBase.h:148
int crash_limit_lin_nmp
Limit of error in position in linear movement.
Definition: kmlMotBase.h:132
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:137
const TMotDYL * GetDYL()
Definition: kmlMotBase.h:245
TMotSFW sfw
slave firmware
Definition: kmlMotBase.h:231
bool isCalibrated
Definition: kmlMotBase.h:189
double angleStop
Definition: kmlMotBase.h:206
Calibration structure for single motors.
Definition: kmlMotBase.h:181
byte subtype
firmware subtype
Definition: kmlMotBase.h:90
[MOT] every motor&#39;s attributes
Definition: kmlMotBase.h:40
void setSCP(TMotSCP _scp)
Definition: kmlMotBase.h:289
const int GetEncoderMaxPos()
Returns the max Position of the Encoder.
Definition: kmlMotBase.h:253
TMotAPS aps
actual position
Definition: kmlMotBase.h:226
search direction for the meachanical stopper
Definition: kmlMotBase.h:69
TMotCLB _calibrationParameters
calibration structure
Definition: kmlMotBase.h:232
byte kI_nmp
Integral factor (1/kI) of control output added to the final control output.
Definition: kmlMotBase.h:130
byte SID
slave ID
Definition: kmlMotBase.h:80
int rotationDirection
Definition: kmlMotBase.h:203
short maxpspeed
max. allowed forward speed
Definition: kmlMotBase.h:144
const TMotGNL * GetGNL()
Definition: kmlMotBase.h:241
short minpos
not yet active
Definition: kmlMotBase.h:143
double angleRange
Definition: kmlMotBase.h:202
short tarpos
target position
Definition: kmlMotBase.h:104
[SCP] static controller parameters
Definition: kmlMotBase.h:109
TMotDesc * desc
description[]
Definition: kmlMotBase.h:43
TMotDYL dyl
dynamic limits
Definition: kmlMotBase.h:229
byte slvID
slave number
Definition: kmlMotBase.h:35
min. position was reached
Definition: kmlMotBase.h:60
void setSpeedLimit(short velocity)
Definition: kmlMotBase.h:359
byte maxcurr_nmp
set the maximal current
Definition: kmlMotBase.h:156
linear movement ended
Definition: kmlMotBase.h:65
double angleOffset
Definition: kmlMotBase.h:201
short pos
position
Definition: kmlMotBase.h:163
int enc_minpos
motor&#39;s minimum position in encoder values
Definition: kmlMotBase.h:172
int crash_limit_nmp
Limit of error in position.
Definition: kmlMotBase.h:131
TMotSCP scp
static controller parameters
Definition: kmlMotBase.h:228
const TMotInit * GetInitialParameters()
Definition: kmlMotBase.h:250
short order
order in which this motor will be calibrated. range: 0..5
Definition: kmlMotBase.h:183
int enc_maxpos
motor&#39;s maximum position in encoder values
Definition: kmlMotBase.h:173
TSearchDir dir
search direction for mech. stopper
Definition: kmlMotBase.h:185
byte kP_speed
Proportional factor of the speed compensator.
Definition: kmlMotBase.h:120
short cnt
count of motors
Definition: kmlMotBase.h:41
TMotStsFlg msf
motor status flag
Definition: kmlMotBase.h:162
set the motor on
Definition: kmlMotBase.h:52
motor description (partly)
Definition: kmlMotBase.h:34
void setCrashLimit(long idx, int limit)
set collision limits
byte maxdecel
max deceleration
Definition: kmlMotBase.h:142
const TMotSFW * GetSFW()
Definition: kmlMotBase.h:247
Motor class.
Definition: kmlMotBase.h:219
short vel
velocity
Definition: kmlMotBase.h:164
max. position was reached
Definition: kmlMotBase.h:59
const int GetEncoderRange()
Returns Encoder Range of the Encoder.
Definition: kmlMotBase.h:254
TMotCmdFlg mcfAPS
motor command flag
Definition: kmlMotBase.h:96
TKatGNL gnl
katana general
Definition: kmlBase.h:135
byte type
firmware type
Definition: kmlMotBase.h:89
byte maxaccel_nmp
Maximal acceleration and deceleration.
Definition: kmlMotBase.h:153
byte maxaccel
max acceleration
Definition: kmlMotBase.h:141
TMotCmdFlg
command flags
Definition: kmlMotBase.h:48
void setPositionCollisionLimit(long idx, int limit)
set collision position limits
byte subversion
firmware subversion number
Definition: kmlMotBase.h:87
freeze the motor
Definition: kmlMotBase.h:51
byte maxnpwm_nmp
Max. value for negative voltage (0 => 0%, +70 => 100%)
Definition: kmlMotBase.h:127
trying to follow target
Definition: kmlMotBase.h:62
void setDYL(TMotDYL _dyl)
Definition: kmlMotBase.h:290
TMotDYL dyl
Definition: kmlMotBase.h:191
int enc_range
motor&#39;s range in encoder values
Definition: kmlMotBase.h:171
TMotCmdFlg mcfTPS
motor command flag
Definition: kmlMotBase.h:103
byte pwm
pulse with modulation
Definition: kmlMotBase.h:165
byte kP
prop. factor of pos comp
Definition: kmlMotBase.h:115
short maxpspeed_nmp
Max. allowed forward speed.
Definition: kmlMotBase.h:154
int enc_tolerance
encoder units of tolerance to accept that a position has been reached
Definition: kmlMotBase.h:175
const TMotSCP * GetSCP()
Definition: kmlMotBase.h:244
byte version
firmware version number
Definition: kmlMotBase.h:86
byte kpos_nmp
Proportional factor of position compensator.
Definition: kmlMotBase.h:129
in desired position
Definition: kmlMotBase.h:61
short maxnspeed_nmp
Max. allowed reverse speed.
Definition: kmlMotBase.h:155
TMotENL _encoderLimits
motor limits in encoder values
Definition: kmlMotBase.h:233
mechanical stopper reached
Definition: kmlMotBase.h:58
byte kspeed_nmp
Proportional factor of speed compensator.
Definition: kmlMotBase.h:128
set the motor off
Definition: kmlMotBase.h:49
const int GetEncoderMinPos()
Returns the min Position of the Encoder.
Definition: kmlMotBase.h:252
virtual bool init(const TKatGNL _gnl, const TKatMOT _mot, const TKatSCT _sct, const TKatEFF _eff, CCplBase *_protocol)