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