VEXcode IQ C++ Unofficial documentation for version 3.0.4.1
All Classes Namespaces Files Functions Variables Enumerations
vex_motor.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* */
3/* Copyright (c) Innovation First 2017-2019, All rights reserved. */
4/* */
5/* Module: vex_motor.h */
6/* Author: James Pearman */
7/* Created: 2 June 2017 */
8/* */
9/* Revisions: */
10/* V1.00 TBD - Initial release */
11/* */
12/*----------------------------------------------------------------------------*/
13
14#ifndef VEX_MOTOR_CLASS_H
15#define VEX_MOTOR_CLASS_H
16
17/*-----------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22#define VEXIQ_MOTOR_OVERTEMP_FLAG 0x02
23#define VEXIQ_MOTOR_CURLIMIT_FLAG 0x04
24#define VEXIQ_MOTOR_ZEROVEL_FLAG 0x08
25#define VEXIQ_MOTOR_ZEROPOS_FLAG 0x10
26
27/*-----------------------------------------------------------------------------*/
29/*-----------------------------------------------------------------------------*/
30namespace vex {
34 class motor : public device {
35 public:
40 motor( int32_t index );
41 ~motor();
42
43 bool installed();
44 int32_t value();
45
51 motor( int32_t index, bool reverse );
52
58 motor( int32_t index, double gearRatio );
59
66 motor( int32_t index, double gearRatio, bool reverse );
67
72 void setReversed( bool value );
73
79 void setVelocity( double velocity, velocityUnits units );
80
86 void setVelocity( double velocity, percentUnits units ){
87 setVelocity( velocity, static_cast<velocityUnits>(units) );
88 };
89
90 //Legacy
91 void setBrake( brakeType mode );
92
97 void setStopping( brakeType mode );
98
102 void resetPosition( void );
103
109 void setPosition( double value, rotationUnits units );
110
116 void setTimeout( int32_t time, timeUnits units );
117
118 //Actions
119
124 void spin( directionType dir );
125
132 void spin( directionType dir, double velocity, velocityUnits units );
133
134 void spin( directionType dir, double velocity, percentUnits units ){
135 spin( dir, velocity, static_cast<velocityUnits>(units) );
136 }
137
144 void spin( directionType dir, double voltage, voltageUnits units );
145
155 bool spinTo( double rotation, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true );
156
157 bool spinToPosition( double rotation, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true );
158
166 bool spinTo( double rotation, rotationUnits units, bool waitForCompletion=true );
167
168 bool spinToPosition( double rotation, rotationUnits units, bool waitForCompletion=true );
169
179 bool spinFor( double rotation, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true );
180
181 bool spinFor( directionType dir, double rotation, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true );
182
190 bool spinFor( double rotation, rotationUnits units, bool waitForCompletion=true );
191
192 bool spinFor( directionType dir, double rotation, rotationUnits units, bool waitForCompletion=true );
193
202 bool spinFor( double time, timeUnits units, double velocity, velocityUnits units_v );
203
204 bool spinFor( directionType dir, double time, timeUnits units, double velocity, velocityUnits units_v );
205
212 bool spinFor( double time, timeUnits units );
213
214 bool spinFor( directionType dir, double time, timeUnits units );
215
220 bool isSpinning( void );
221
226 bool isDone( void );
227
228 bool isSpinningMode( void );
229
233 void stop( void );
234
239 void stop( brakeType mode );
240
246 void setMaxTorque( double value, percentUnits units );
247
253 void setMaxTorque( double value, torqueUnits units );
254
260 void setMaxTorque( double value, currentUnits units );
261
262 // sensing
263
268 directionType direction( void );
269
275 double position( rotationUnits units );
276
282 double velocity( velocityUnits units );
283
284 double velocity( percentUnits units ) {
285 return velocity( static_cast<velocityUnits>(units) );
286 };
287
293 double current( currentUnits units = currentUnits::amp );
294
300 double current( percentUnits units );
301
302 // these are all V5 compatibility functions and do not return any valid values
303 // data from the motor for these is not available on IQ
304
310 double voltage( voltageUnits units = voltageUnits::volt );
311
317 double power( powerUnits units = powerUnits::watt );
318
324 double torque( torqueUnits units = torqueUnits::Nm );
325
331 double efficiency( percentUnits units = percentUnits::pct );
332
338 double temperature( percentUnits units = percentUnits::pct );
339
345 double temperature( temperatureUnits units );
346
347
348 protected:
349 int32_t getTimeout();
350 double getVelocity( velocityUnits units );
351
352 private:
353 int32_t _timeout;
354 int16_t _velocity;
355 int16_t _last_velocity;
356 int32_t _offset;
357 bool _bReverse;
358 brakeType _brakeMode;
359 bool _spinMode;
360 int32_t _flagDelay;
361 int32_t _initDelay;
362 float _gearRatio;
363
364 void defaultStopping( brakeType mode );
365
366 bool zeroPositionFlag( void );
367 uint8_t modeGet( void );
368
369 double velocityToScaled( int32_t velocity, velocityUnits units );
370 int32_t scaledToVelocity( double value, velocityUnits units );
371 double encoderToScaled( int32_t counts, rotationUnits units );
372 int32_t scaledToEncoder( double position, rotationUnits units );
373 double torqueToCurrent( double torque );
374 };
375};
376
377#endif // VEX_MOTOR_CLASS_H
Use the motor class to control motor devices.
Definition vex_motor.h:34
void setVelocity(double velocity, velocityUnits units)
Sets the velocity of the motor based on the parameters set in the command. This command will not run ...
bool spinFor(double rotation, rotationUnits units, bool waitForCompletion=true)
Turns on the motor and spins it to a relative target rotation value.
motor(int32_t index)
Creates a new motor object on the port specified.
bool spinTo(double rotation, rotationUnits units, bool waitForCompletion=true)
Turns on the motor and spins it to an absolute target rotation value.
double position(rotationUnits units)
Gets the current position of the motor's encoder.
bool isSpinning(void)
Checks to see if the motor is rotating to a specific target.
motor(int32_t index, bool reverse)
Creates a new motor object on the port specified and sets the reversed flag.
void setMaxTorque(double value, percentUnits units)
Sets the max torque of the motor.
void setStopping(brakeType mode)
Sets the stopping mode of the motor by passing a brake mode as a parameter.
directionType direction(void)
Gets which direction the motor is spinning.
void setTimeout(int32_t time, timeUnits units)
Sets the timeout for the motor. If the motor does not reach its' commanded position prior to the comp...
double torque(torqueUnits units=torqueUnits::Nm)
Gets the torque of the motor.
bool spinFor(double rotation, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true)
Turns on the motor and spins it to a relative target rotation value at a specified velocity.
void setReversed(bool value)
Sets the motor mode to "reverse", which will make motor commands spin the motor in the opposite direc...
void stop(brakeType mode)
Stops the motor using a specified brake mode.
double voltage(voltageUnits units=voltageUnits::volt)
Gets the electrical voltage of the motor.
motor(int32_t index, double gearRatio)
Creates a new motor object on the port specified and sets the output gear ratio.
void spin(directionType dir, double voltage, voltageUnits units)
Turns on the motor and spins it in a specified direction and a specified voltage.
motor(int32_t index, double gearRatio, bool reverse)
Creates a new motor object on the port specified and sets the output gear ratio and reverse flag.
bool isDone(void)
Checks to see if the motor is done rotating to a specific target.
void setMaxTorque(double value, torqueUnits units)
Sets the max torque of the motor.
double temperature(percentUnits units=percentUnits::pct)
Gets the temperature of the motor.
void spin(directionType dir)
Turns the motor on, and spins it in the specified direction.
bool spinTo(double rotation, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true)
Turns on the motor and spins it to an absolute target rotation value at a specified velocity.
double current(percentUnits units)
Gets the electrical current of the motor in percentage of maximum.
double efficiency(percentUnits units=percentUnits::pct)
Gets the efficiency of the motor.
void spin(directionType dir, double velocity, velocityUnits units)
Turns on the motor and spins it in a specified direction and a specified velocity.
void setMaxTorque(double value, currentUnits units)
Sets the max torque of the motor.
void resetPosition(void)
Resets the motor's encoder to the value of zero.
double power(powerUnits units=powerUnits::watt)
Gets the power of the motor.
void setPosition(double value, rotationUnits units)
Sets the value of the motor's encoder to the value specified in the parameter.
bool spinFor(double time, timeUnits units, double velocity, velocityUnits units_v)
Turns on the motor and spins it to a relative target time value at a specified velocity.
double temperature(temperatureUnits units)
Gets the temperature of the motor.
void setVelocity(double velocity, percentUnits units)
Sets the velocity of the motor based on the parameters set in the command. This command will not run ...
Definition vex_motor.h:86
bool spinFor(double time, timeUnits units)
Turns on the motor and spins it to a relative target time value.
void stop(void)
Stops the motor using the default brake mode.
double current(currentUnits units=currentUnits::amp)
Gets the electrical current of the motor.
double velocity(velocityUnits units)
Gets the current velocity of the motor.
Bumper switch device class
Definition vex_brain.h:24