LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
abstractMotor.hpp
Go to the documentation of this file.
1/*
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 */
6#pragma once
7
10#include <memory>
11
12namespace okapi {
13class AbstractMotor : public ControllerOutput<double> {
14 public:
18 enum class brakeMode {
19 coast = 0,
20 brake = 1,
21 hold = 2,
22 invalid = INT32_MAX
23 };
24
28 enum class encoderUnits {
29 degrees = 0,
30 rotations = 1,
31 counts = 2,
32 invalid = INT32_MAX
33 };
34
38 enum class gearset {
39 red = 100,
40 green = 200,
41 blue = 600,
42 invalid = INT32_MAX
43 };
44
58 GearsetRatioPair(const gearset igearset, const double iratio = 1)
59 : internalGearset(igearset), ratio(iratio) {
60 }
61
62 ~GearsetRatioPair() = default;
63
65 double ratio = 1;
66 };
67
68 virtual ~AbstractMotor();
69
70 /******************************************************************************/
74 /******************************************************************************/
75
92 virtual std::int32_t moveAbsolute(double iposition, std::int32_t ivelocity) = 0;
93
111 virtual std::int32_t moveRelative(double iposition, std::int32_t ivelocity) = 0;
112
129 virtual std::int32_t moveVelocity(std::int16_t ivelocity) = 0;
130
140 virtual std::int32_t moveVoltage(std::int16_t ivoltage) = 0;
141
153 virtual std::int32_t modifyProfiledVelocity(std::int32_t ivelocity) = 0;
154
155 /******************************************************************************/
159 /******************************************************************************/
160
170 virtual double getTargetPosition() = 0;
171
181 virtual double getPosition() = 0;
182
194
203 virtual std::int32_t tarePosition() = 0;
204
214 virtual std::int32_t getTargetVelocity() = 0;
215
225 virtual double getActualVelocity() = 0;
226
238
248 virtual std::int32_t getCurrentDraw() = 0;
249
260 virtual std::int32_t getDirection() = 0;
261
275 virtual double getEfficiency() = 0;
276
287 virtual std::int32_t isOverCurrent() = 0;
288
299 virtual std::int32_t isOverTemp() = 0;
300
310 virtual std::int32_t isStopped() = 0;
311
321 virtual std::int32_t getZeroPositionFlag() = 0;
322
334 virtual uint32_t getFaults() = 0;
335
347 virtual uint32_t getFlags() = 0;
348
361 virtual std::int32_t getRawPosition(std::uint32_t *timestamp) = 0;
362
372 virtual double getPower() = 0;
373
384 virtual double getTemperature() = 0;
385
395 virtual double getTorque() = 0;
396
406 virtual std::int32_t getVoltage() = 0;
407
408 /******************************************************************************/
412 /******************************************************************************/
413
423 virtual std::int32_t setBrakeMode(brakeMode imode) = 0;
424
434 virtual brakeMode getBrakeMode() = 0;
435
445 virtual std::int32_t setCurrentLimit(std::int32_t ilimit) = 0;
446
457 virtual std::int32_t getCurrentLimit() = 0;
458
468 virtual std::int32_t setEncoderUnits(encoderUnits iunits) = 0;
469
480
490 virtual std::int32_t setGearing(gearset igearset) = 0;
491
501 virtual gearset getGearing() = 0;
502
514 virtual std::int32_t setReversed(bool ireverse) = 0;
515
525 virtual std::int32_t setVoltageLimit(std::int32_t ilimit) = 0;
526
532 virtual std::shared_ptr<ContinuousRotarySensor> getEncoder() = 0;
533};
534
536
537} // namespace okapi
virtual std::int32_t getZeroPositionFlag()=0
Checks if the motor is at its zero position.
brakeMode
Indicates the 'brake mode' of a motor.
@ coast
Motor coasts when stopped, traditional behavior.
@ hold
Motor actively holds position when stopped.
@ brake
Motor brakes when stopped.
virtual double getTargetPosition()=0
Motor telemetry functions
virtual brakeMode getBrakeMode()=0
Gets the brake mode that was set for the motor.
virtual std::int32_t moveVoltage(std::int16_t ivoltage)=0
Sets the voltage for the motor from -12000 to 12000.
virtual std::int32_t modifyProfiledVelocity(std::int32_t ivelocity)=0
Changes the output velocity for a profiled movement (moveAbsolute or moveRelative).
virtual double getEfficiency()=0
Gets the efficiency of the motor in percent.
virtual std::int32_t setVoltageLimit(std::int32_t ilimit)=0
Sets the voltage limit for the motor in Volts.
virtual std::int32_t moveVelocity(std::int16_t ivelocity)=0
Sets the velocity for the motor.
virtual std::int32_t isOverCurrent()=0
Checks if the motor is drawing over its current limit.
virtual double getActualVelocity()=0
Gets the actual velocity of the motor.
virtual double getPosition()=0
Gets the absolute position of the motor in its encoder units.
virtual std::int32_t moveRelative(double iposition, std::int32_t ivelocity)=0
Sets the relative target position for the motor to move to.
virtual std::int32_t isOverTemp()=0
Checks if the motor's temperature is above its limit.
virtual std::int32_t setReversed(bool ireverse)=0
Sets the reverse flag for the motor.
virtual std::int32_t getCurrentDraw()=0
Gets the current drawn by the motor in mA.
virtual std::int32_t getVoltage()=0
Gets the voltage delivered to the motor in millivolts.
gearset
Indicates the internal gear ratio of a motor.
@ blue
6:1, 600 RPM, Blue gear set
@ green
18:1, 200 RPM, Green gear set
@ red
36:1, 100 RPM, Red gear set
virtual std::int32_t getDirection()=0
Gets the direction of movement for the motor.
virtual double getTorque()=0
Gets the torque generated by the motor in Newton Metres (Nm).
virtual std::int32_t getTargetVelocity()=0
Gets the velocity commanded to the motor by the user.
virtual double getTemperature()=0
Gets the temperature of the motor in degrees Celsius.
virtual std::int32_t getRawPosition(std::uint32_t *timestamp)=0
Gets the raw encoder count of the motor at a given timestamp.
virtual std::int32_t isStopped()=0
Checks if the motor is stopped.
virtual uint32_t getFlags()=0
Gets the flags set by the motor's operation.
virtual std::int32_t setEncoderUnits(encoderUnits iunits)=0
Sets one of encoderUnits for the motor encoder.
double getPositionError()
Gets the positional error (target position minus actual position) of the motor in its encoder units.
virtual std::int32_t getCurrentLimit()=0
Gets the current limit for the motor in mA.
virtual std::int32_t moveAbsolute(double iposition, std::int32_t ivelocity)=0
Motor movement functions
virtual std::int32_t setGearing(gearset igearset)=0
Sets one of gearset for the motor.
virtual std::int32_t tarePosition()=0
Sets the "absolute" zero position of the motor to its current position.
virtual ~AbstractMotor()
virtual std::shared_ptr< ContinuousRotarySensor > getEncoder()=0
Returns the encoder associated with this motor.
double getVelocityError()
Gets the difference between the target velocity of the motor and the actual velocity of the motor.
virtual gearset getGearing()=0
Gets the gearset that was set for the motor.
virtual uint32_t getFaults()=0
Gets the faults experienced by the motor.
encoderUnits
Indicates the units used by the motor encoders.
virtual encoderUnits getEncoderUnits()=0
Gets the encoder units that were set for the motor.
virtual std::int32_t setCurrentLimit(std::int32_t ilimit)=0
Sets the current limit for the motor in mA.
virtual double getPower()=0
Gets the power drawn by the motor in Watts.
virtual std::int32_t setBrakeMode(brakeMode imode)=0
Motor configuration functions
AbstractMotor::GearsetRatioPair operator*(AbstractMotor::gearset gearset, double ratio)
A simple structure representing the full ratio between motor and wheel.
GearsetRatioPair(const gearset igearset, const double iratio=1)
A simple structure representing the full ratio between motor and wheel.