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