VEXcode IQ C++ Unofficial documentation for version 3.0.4.1
Loading...
Searching...
No Matches
vex_drivetrain.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* */
3/* Copyright (c) Innovation First 2019, All rights reserved. */
4/* */
5/* Module: vex_drivetrain.h */
6/* Author: James Pearman */
7/* Created: 7 April 2019 */
8/* */
9/* Revisions: */
10/* V1.00 TBD - Initial release */
11/* */
12/*----------------------------------------------------------------------------*/
13
14#ifndef VEX_DRIVETRAIN_CLASS_H
15#define VEX_DRIVETRAIN_CLASS_H
16
17#include "vex_motorgroup.h"
18
19/*-----------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace vex {
25
26 class drivetrain {
27 private:
30
31 double _wheel_circumference;
32 double _wheel_track;
33 double _wheel_base;
34 double _wheel_motor_gear_ratio;
35
36 int32_t _timeout;
37 bool _waitForCompletionAll();
38 double _distanceToRevs( double distance, distanceUnits units );
39 double _angleToRevs( double angle, rotationUnits units );
40
41 public:
42 drivetrain( motor_group &l, motor_group &r, double wheelTravel=200, double trackWidth=200, double wheelBase=50, distanceUnits unit=distanceUnits::mm, double externalGearRatio = 1.0 );
43 drivetrain( vex::motor &l, vex::motor &r, double wheelTravel=200, double trackWidth=200, double wheelBase=50, distanceUnits unit=distanceUnits::mm, double externalGearRatio = 1.0 );
44
46
47 void setGearRatio( double ratio );
48
54 void setDriveVelocity( double velocity, velocityUnits units );
55
56 void setDriveVelocity( double velocity, percentUnits units );
57
63 void setTurnVelocity( double velocity, velocityUnits units );
64
65 void setTurnVelocity( double velocity, percentUnits units );
66
72 void setTimeout( int32_t time, timeUnits units );
73
78 void setStopping( brakeType mode );
79
84 void drive( directionType dir ) ;
85
92 void drive( directionType dir, double velocity, velocityUnits units );
93
101 bool driveFor( double distance, distanceUnits units, bool waitForCompletion=true );
102
103 bool driveFor( directionType dir, double distance, distanceUnits units, bool waitForCompletion=true );
104
114 bool driveFor( double distance, distanceUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true );
115
116 bool driveFor( directionType dir, double distance, distanceUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true );
117
122 void turn( turnType dir );
123
130 void turn( turnType dir, double velocity, velocityUnits units );
131
139 virtual bool turnFor( double angle, rotationUnits units, bool waitForCompletion=true );
140
141 virtual bool turnFor( turnType dir, double angle, rotationUnits units, bool waitForCompletion=true );
142
152 virtual bool turnFor( double angle, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true );
153
154 virtual bool turnFor( turnType dir, double angle, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true );
155
160 virtual bool isMoving( void );
161
166 bool isDone( void );
167
171 void stop();
172
177 void stop( brakeType mode );
178
179 void arcade( double drivePower, double turnPower, percentUnits units=percentUnits::pct );
180
186 double velocity( velocityUnits units );
187
188 double velocity( percentUnits units ) {
189 return velocity( static_cast<velocityUnits>(units) );
190 };
191
197 double current( currentUnits units = currentUnits::amp );
198
204 double current( percentUnits units );
205
206 // these are all V5 compatibility functions and do not return any valid values
207 // data from the motor for these is not available on IQ
208
214 double voltage( voltageUnits units = voltageUnits::volt );
215
221 double power( powerUnits units = powerUnits::watt );
222
228 double torque( torqueUnits units = torqueUnits::Nm );
229
235 double efficiency( percentUnits units = percentUnits::pct );
236
242 double temperature( percentUnits units );
243
244 protected:
245 // Helper functions that can used by sub classes
246 double distanceToMm( double distance, distanceUnits units );
247 double angleToDeg( double angle, rotationUnits units );
248 int32_t timeoutGet();
249
250 double _turnvelocity;
251 velocityUnits _turnvelocityUnits;
252 uint8_t _turnmode;
253 };
254};
255
256#endif // VEX_DRIVETRAIN_CLASS_H
Use the distance class to control the distance sensor.
double current(currentUnits units=currentUnits::amp)
Gets the total current of the drivetrain;.
void setTimeout(int32_t time, timeUnits units)
Sets the timeout for the motor group. If the motor group does not reach its' commanded position prior...
double temperature(percentUnits units)
Gets the average temperature of the drivetrain;.
virtual bool isMoving(void)
Checks to see if any of the motors are rotating to a specific target.
double torque(torqueUnits units=torqueUnits::Nm)
Gets the average torque of the drivetrain;.
void setDriveVelocity(double velocity, velocityUnits units)
Sets the velocity of the drive based on the parameters set in the command. This command will not run ...
void turn(turnType dir, double velocity, velocityUnits units)
Turns the motors on, and rotate in the specified direction and a specified velocity.
double current(percentUnits units)
Gets the electrical current of the drivetrain as percentage of maximum.
bool isDone(void)
Checks to see if all the motor are done rotating to a specific target.
void stop(brakeType mode)
Stops the drive using a specified brake mode.
virtual bool turnFor(double angle, rotationUnits units, bool waitForCompletion=true)
Turn on the motors and rotate an angle at the default velocity.
double velocity(velocityUnits units)
Gets the average velocity of the drivetrain;.
void setTurnVelocity(double velocity, velocityUnits units)
Sets the turn velocity of the drive based on the parameters set in the command. This command will not...
bool driveFor(double distance, distanceUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true)
Turn on the motors and drive a distance at a specified velocity.
void stop()
Stops the drive using the default brake mode.
bool driveFor(double distance, distanceUnits units, bool waitForCompletion=true)
Turn on the motors and drive a distance at the default velocity.
double power(powerUnits units=powerUnits::watt)
Gets the average power of the drivetrain;.
double voltage(voltageUnits units=voltageUnits::volt)
Gets the average voltage of the drivetrain;.
void setStopping(brakeType mode)
Sets the stopping mode of the motor group by passing a brake mode as a parameter.
double efficiency(percentUnits units=percentUnits::pct)
Gets the average efficiency of the drivetrain;.
void turn(turnType dir)
Turns the motors on, and rotate in the specified direction.
void drive(directionType dir)
Turns the motors on, and drive in the specified direction.
virtual bool turnFor(double angle, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true)
Turn on the motors and rotate an angle at a specified velocity.
void drive(directionType dir, double velocity, velocityUnits units)
Turn on the motors and drive in the specified direction and a specified velocity.
Use the motor class to control motor devices.
Definition vex_motor.h:34
Bumper switch device class
Definition vex_brain.h:24
Motor group class header.