00001 #ifndef __CPHIDGETMOTORCONTROL
00002 #define __CPHIDGETMOTORCONTROL
00003 #include "cphidget.h"
00004
00011 DPHANDLE(MotorControl)
00012 CHDRSTANDARD(MotorControl)
00013
00019 CHDRGET(MotorControl,MotorCount,int *count)
00020
00027 CHDRGETINDEX(MotorControl,Velocity,double *velocity)
00034 CHDRSETINDEX(MotorControl,Velocity,double velocity)
00041 CHDREVENTINDEX(MotorControl,VelocityChange,double velocity)
00042
00049 CHDRGETINDEX(MotorControl,Acceleration,double *acceleration)
00056 CHDRSETINDEX(MotorControl,Acceleration,double acceleration)
00063 CHDRGETINDEX(MotorControl,AccelerationMax,double *max)
00070 CHDRGETINDEX(MotorControl,AccelerationMin,double *min)
00071
00072
00079 CHDRGETINDEX(MotorControl,Current,double *current)
00086 CHDREVENTINDEX(MotorControl,CurrentChange,double current)
00087
00093 CHDRGET(MotorControl,InputCount,int *count)
00100 CHDRGETINDEX(MotorControl,InputState,int *inputState)
00107 CHDREVENTINDEX(MotorControl,InputChange,int inputState)
00108
00114 CHDRGET(MotorControl,EncoderCount,int *count)
00121 CHDRGETINDEX(MotorControl,EncoderPosition,int *position)
00128 CHDRSETINDEX(MotorControl,EncoderPosition,int position)
00135 CHDREVENTINDEX(MotorControl,EncoderPositionChange,int time,int positionChange)
00142 CHDREVENTINDEX(MotorControl,EncoderPositionUpdate,int positionChange)
00143
00150 CHDRGETINDEX(MotorControl,BackEMFSensingState,int *bEMFState)
00157 CHDRSETINDEX(MotorControl,BackEMFSensingState,int bEMFState)
00164 CHDRGETINDEX(MotorControl,BackEMF,double *voltage)
00171 CHDREVENTINDEX(MotorControl,BackEMFUpdate,double voltage)
00172
00178 CHDRGET(MotorControl,SupplyVoltage,double *supplyVoltage)
00179
00186 CHDRGETINDEX(MotorControl,Braking,double *braking)
00193 CHDRSETINDEX(MotorControl,Braking,double braking)
00194
00200 CHDRGET(MotorControl, SensorCount, int *count)
00207 CHDRGETINDEX(MotorControl, SensorValue, int *sensorValue)
00214 CHDRGETINDEX(MotorControl, SensorRawValue, int *sensorRawValue)
00221 CHDREVENTINDEX(MotorControl, SensorUpdate, int sensorValue)
00227 CHDRGET(MotorControl, Ratiometric, int *ratiometric)
00233 CHDRSET(MotorControl, Ratiometric, int ratiometric)
00234
00241 CHDREVENTINDEX(MotorControl,CurrentUpdate,double current)
00242
00243 #ifndef REMOVE_DEPRECATED
00244 DEP_CHDRGET("Deprecated - use CPhidgetMotorControl_getMotorCount",MotorControl,NumMotors,int *)
00245 DEP_CHDRGET("Deprecated - use CPhidgetMotorControl_getInputCount",MotorControl,NumInputs,int *)
00246 DEP_CHDRGETINDEX("Deprecated - use CPhidgetMotorControl_getVelocity",MotorControl,MotorSpeed,double *)
00247 DEP_CHDRSETINDEX("Deprecated - use CPhidgetMotorControl_setVelocity",MotorControl,MotorSpeed,double)
00248 DEP_CHDREVENTINDEX("Deprecated - use CPhidgetMotorControl_set_OnVelocityChange_Handler",MotorControl,MotorChange,double motorSpeed)
00249 #endif
00250
00251 #ifndef EXTERNALPROTO
00252 #define MOTORCONTROL_MAXMOTORS 2
00253 #define MOTORCONTROL_MAXINPUTS 4
00254 #define MOTORCONTROL_MAXENCODERS 1
00255 #define MOTORCONTROL_MAXSENSORS 2
00256
00257 #define MOTORCONTROL_ERRORFLAG_OVERTEMP 0x0001
00258 #define MOTORCONTROL_ERRORFLAG_UNDERVOLTAGE_LOCKOUT 0x0002
00259 #define MOTORCONTROL_ERRORFLAG_NOPOWER 0x0004
00260 #define MOTORCONTROL_ERRORFLAG_LOWPOWER 0x0008
00261 #define MOTORCONTROL_ERRORFLAG_HIGHPOWER 0x0010
00262 #define MOTORCONTROL_ERRORFLAG_DANGERPOWER 0x0020
00263
00264 struct _CPhidgetMotorControl {
00265 CPhidget phid;
00266
00267 int (CCONV *fptrVelocityChange)(CPhidgetMotorControlHandle, void *, int, double);
00268 int (CCONV *fptrInputChange)(CPhidgetMotorControlHandle, void *, int, int);
00269 int (CCONV *fptrCurrentChange)(CPhidgetMotorControlHandle, void *, int, double);
00270 int (CCONV *fptrEncoderPositionChange)(CPhidgetMotorControlHandle, void *, int, int, int);
00271 int (CCONV *fptrEncoderPositionUpdate)(CPhidgetMotorControlHandle, void *, int, int);
00272 int (CCONV *fptrBackEMFUpdate)(CPhidgetMotorControlHandle, void *, int, double);
00273 int (CCONV *fptrSensorUpdate)(CPhidgetMotorControlHandle, void *, int, int);
00274 int (CCONV *fptrCurrentUpdate)(CPhidgetMotorControlHandle, void *, int, double);
00275
00276 void *fptrInputChangeptr;
00277 void *fptrVelocityChangeptr;
00278 void *fptrCurrentChangeptr;
00279 void *fptrEncoderPositionChangeptr;
00280 void *fptrEncoderPositionUpdateptr;
00281 void *fptrBackEMFUpdateptr;
00282 void *fptrSensorUpdateptr;
00283 void *fptrCurrentUpdateptr;
00284
00285
00286 int (CCONV *fptrMotorChange)(CPhidgetMotorControlHandle, void *, int, double);
00287 void *fptrMotorChangeptr;
00288
00289
00290 unsigned char inputState[MOTORCONTROL_MAXINPUTS];
00291 double motorSpeedEcho[MOTORCONTROL_MAXMOTORS];
00292 double motorSensedCurrent[MOTORCONTROL_MAXMOTORS];
00293 double motorSensedBackEMF[MOTORCONTROL_MAXMOTORS];
00294 unsigned char backEMFSensingStateEcho[MOTORCONTROL_MAXMOTORS];
00295 double motorSetSpeedEcho[MOTORCONTROL_MAXMOTORS];
00296 double motorAccelerationEcho[MOTORCONTROL_MAXMOTORS];
00297 double motorBrakingEcho[MOTORCONTROL_MAXMOTORS];
00298 double supplyVoltage;
00299 int encoderPositionEcho[MOTORCONTROL_MAXENCODERS];
00300 int encoderTimeStamp[MOTORCONTROL_MAXENCODERS];
00301 unsigned char ratiometricEcho;
00302 int sensorRawValue[MOTORCONTROL_MAXSENSORS];
00303 int sensorValue[MOTORCONTROL_MAXSENSORS];
00304
00305 int lastPacketCount;
00306
00307
00308 double motorSpeed[MOTORCONTROL_MAXMOTORS];
00309 double motorAcceleration[MOTORCONTROL_MAXMOTORS];
00310 unsigned char backEMFSensingState[MOTORCONTROL_MAXMOTORS];
00311 double motorBraking[MOTORCONTROL_MAXMOTORS];
00312 unsigned char ratiometric;
00313
00314 int encoderPositionDelta[MOTORCONTROL_MAXENCODERS];
00315 unsigned short motorErrors[MOTORCONTROL_MAXMOTORS];
00316
00317
00318 double accelerationMax, accelerationMin;
00319
00320
00321 double lastVoltage;
00322 int encoderPositionUpdates[MOTORCONTROL_MAXENCODERS];
00323
00324 unsigned char outputPacket[8];
00325 unsigned int outputPacketLen;
00326 } typedef CPhidgetMotorControlInfo;
00327 #endif
00328
00331 #endif