LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
motor.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
8#include "api.h"
11
12namespace okapi {
13class Motor : public AbstractMotor {
14 public:
21 Motor(std::int8_t iport);
22
33 Motor(std::uint8_t iport,
34 bool ireverse,
36 AbstractMotor::encoderUnits iencoderUnits,
37 const std::shared_ptr<Logger> &logger = Logger::getDefaultLogger());
38
39 /******************************************************************************/
43 /******************************************************************************/
44
58 std::int32_t moveAbsolute(double iposition, std::int32_t ivelocity) override;
59
74 std::int32_t moveRelative(double iposition, std::int32_t ivelocity) override;
75
89 std::int32_t moveVelocity(std::int16_t ivelocity) override;
90
97 std::int32_t moveVoltage(std::int16_t ivoltage) override;
98
107 std::int32_t modifyProfiledVelocity(std::int32_t ivelocity) override;
108
109 /******************************************************************************/
113 /******************************************************************************/
114
121 double getTargetPosition() override;
122
129 double getPosition() override;
130
136 std::int32_t tarePosition() override;
137
144 std::int32_t getTargetVelocity() override;
145
152 double getActualVelocity() override;
153
159 std::int32_t getCurrentDraw() override;
160
167 std::int32_t getDirection() override;
168
178 double getEfficiency() override;
179
186 std::int32_t isOverCurrent() override;
187
194 std::int32_t isOverTemp() override;
195
205 std::int32_t isStopped() override;
206
216 std::int32_t getZeroPositionFlag() override;
217
225 uint32_t getFaults() override;
226
234 uint32_t getFlags() override;
235
244 std::int32_t getRawPosition(std::uint32_t *timestamp) override;
245
251 double getPower() override;
252
259 double getTemperature() override;
260
266 double getTorque() override;
267
273 std::int32_t getVoltage() override;
274
275 /******************************************************************************/
279 /******************************************************************************/
280
287 std::int32_t setBrakeMode(AbstractMotor::brakeMode imode) override;
288
296
303 std::int32_t setCurrentLimit(std::int32_t ilimit) override;
304
310 std::int32_t getCurrentLimit() override;
311
318 std::int32_t setEncoderUnits(AbstractMotor::encoderUnits iunits) override;
319
327
334 std::int32_t setGearing(AbstractMotor::gearset igearset) override;
335
342 gearset getGearing() override;
343
351 std::int32_t setReversed(bool ireverse) override;
352
359 std::int32_t setVoltageLimit(std::int32_t ilimit) override;
360
370 virtual std::int32_t setPosPID(double ikF, double ikP, double ikI, double ikD);
371
385 virtual std::int32_t setPosPIDFull(double ikF,
386 double ikP,
387 double ikI,
388 double ikD,
389 double ifilter,
390 double ilimit,
391 double ithreshold,
392 double iloopSpeed);
393
404 virtual std::int32_t setVelPID(double ikF, double ikP, double ikI, double ikD);
405
419 virtual std::int32_t setVelPIDFull(double ikF,
420 double ikP,
421 double ikI,
422 double ikD,
423 double ifilter,
424 double ilimit,
425 double ithreshold,
426 double iloopSpeed);
427
433 std::shared_ptr<ContinuousRotarySensor> getEncoder() override;
434
441 void controllerSet(double ivalue) override;
442
446 std::uint8_t getPort() const;
447
451 bool isReversed() const;
452
453 protected:
454 std::uint8_t port;
455 std::int8_t reversed{1};
456};
457} // namespace okapi
PROS API header provides high-level user functionality.
brakeMode
Indicates the 'brake mode' of a motor.
gearset
Indicates the internal gear ratio of a motor.
encoderUnits
Indicates the units used by the motor encoders.
static std::shared_ptr< Logger > getDefaultLogger()
double getActualVelocity() override
Gets the actual velocity of the motor.
std::uint8_t port
Definition motor.hpp:454
void controllerSet(double ivalue) override
Writes the value of the controller output.
std::int32_t getZeroPositionFlag() override
Checks if the motor is at its zero position.
std::int32_t setBrakeMode(AbstractMotor::brakeMode imode) override
Motor configuration functions
std::int32_t moveRelative(double iposition, std::int32_t ivelocity) override
Sets the relative target position for the motor to move to.
Motor(std::uint8_t iport, bool ireverse, AbstractMotor::gearset igearset, AbstractMotor::encoderUnits iencoderUnits, const std::shared_ptr< Logger > &logger=Logger::getDefaultLogger())
A V5 motor.
double getPosition() override
Gets the absolute position of the motor in its encoder units.
double getTorque() override
Gets the torque generated by the motor in Newton Metres (Nm).
std::int32_t setReversed(bool ireverse) override
Sets the reverse flag for the motor.
std::shared_ptr< ContinuousRotarySensor > getEncoder() override
Get the encoder associated with this motor.
std::int32_t setVoltageLimit(std::int32_t ilimit) override
Sets the voltage limit for the motor in Volts.
virtual std::int32_t setVelPID(double ikF, double ikP, double ikI, double ikD)
Sets new PID constants.
std::int32_t moveAbsolute(double iposition, std::int32_t ivelocity) override
Motor movement functions
std::int32_t moveVoltage(std::int16_t ivoltage) override
Sets the voltage for the motor from -12000 to 12000.
Motor(std::int8_t iport)
A V5 motor.
std::int32_t setGearing(AbstractMotor::gearset igearset) override
Sets one of AbstractMotor::gearset for the motor.
std::int32_t getDirection() override
Gets the direction of movement for the motor.
std::int32_t getRawPosition(std::uint32_t *timestamp) override
Gets the raw encoder count of the motor at a given timestamp.
bool isReversed() const
double getEfficiency() override
Gets the efficiency of the motor in percent.
uint32_t getFaults() override
Gets the faults experienced by the motor.
virtual std::int32_t setVelPIDFull(double ikF, double ikP, double ikI, double ikD, double ifilter, double ilimit, double ithreshold, double iloopSpeed)
Sets new PID constants.
gearset getGearing() override
Gets the gearset that was set for the motor.
std::int32_t modifyProfiledVelocity(std::int32_t ivelocity) override
Changes the output velocity for a profiled movement (moveAbsolute or moveRelative).
encoderUnits getEncoderUnits() override
Gets the encoder units that were set for the motor.
std::int32_t isOverTemp() override
Checks if the motor's temperature is above its limit.
std::int32_t setEncoderUnits(AbstractMotor::encoderUnits iunits) override
Sets one of AbstractMotor::encoderUnits for the motor encoder.
double getPower() override
Gets the power drawn by the motor in Watts.
std::int32_t tarePosition() override
Sets the "absolute" zero position of the motor to its current position.
std::int32_t isStopped() override
Checks if the motor is stopped.
std::int32_t setCurrentLimit(std::int32_t ilimit) override
Sets the current limit for the motor in mA.
double getTemperature() override
Gets the temperature of the motor in degrees Celsius.
brakeMode getBrakeMode() override
Gets the brake mode that was set for the motor.
std::uint8_t getPort() const
std::int32_t getCurrentDraw() override
Gets the current drawn by the motor in mA.
uint32_t getFlags() override
Gets the flags set by the motor's operation.
virtual std::int32_t setPosPIDFull(double ikF, double ikP, double ikI, double ikD, double ifilter, double ilimit, double ithreshold, double iloopSpeed)
Sets new PID constants.
std::int8_t reversed
Definition motor.hpp:455
std::int32_t getCurrentLimit() override
Gets the current limit for the motor in mA.
virtual std::int32_t setPosPID(double ikF, double ikP, double ikI, double ikD)
Sets new PID constants.
std::int32_t getTargetVelocity() override
Gets the velocity commanded to the motor by the user.
double getTargetPosition() override
Motor telemetry functions
std::int32_t getVoltage() override
Gets the voltage delivered to the motor in millivolts.
std::int32_t moveVelocity(std::int16_t ivelocity) override
Sets the velocity for the motor.
std::int32_t isOverCurrent() override
Checks if the motor is drawing over its current limit.