ART v1.0-alpha
A Robot Template that raises the floor for VRC teams
Loading...
Searching...
No Matches
art::SimpleMotor Class Reference

A Simple Motor Wrapper Class. More...

#include <SimpleMotor.h>

Inheritance diagram for art::SimpleMotor:

Public Member Functions

 SimpleMotor (vex::motor mot)
 Construct a new Simple Motor object.
 
SimpleMotorwithSpeedMode (bool speedMode)
 Returns a SimpleMotor refrence with the specified speedMode.
 
void setSpeedMode (bool speedMode)
 Set the SpeedMode of the SimpleMotor.
 
bool getSpeedMode ()
 Get the SpeedMode of the SimpleMotor.
 
void set (double cmd)
 Sets the motor to spin at the specified command.
 
double get ()
 Returns the command the motor was last commanded to.
 

Private Attributes

double m_cmd {0}
 The command the motor is set to, as a percentage of the max.
 
bool m_speedMode {false}
 Whether or not the motor should use speed, rather than voltage.
 

Detailed Description

A Simple Motor Wrapper Class.

The Simple Motor class aims to provide a simpler and more efficient way to command motors. The class inherits the vex::motor class and retains all the same functionality, but gains quality of life functions, allowing the motor's use to be as simple as get() and set().

For more complex motor controls, such as position or velocity, use the SmartMotor class (planned for a later version)

Todo
make stop() functions withbrakeModes, also set the cmd to 0

Definition at line 36 of file SimpleMotor.h.

Constructor & Destructor Documentation

◆ SimpleMotor()

art::SimpleMotor::SimpleMotor ( vex::motor mot)

Construct a new Simple Motor object.

Uses a vex::motor (a normal v5 motor) to construct a Simple Motor object

Parameters
motA vex::motor, which is a normal v5 motor

Example:

SimpleMotor testMotor = SimpleMotor( vex::motor(vex::PORT10 ) );
A Simple Motor Wrapper Class.
Definition SimpleMotor.h:37
SimpleMotor(vex::motor mot)
Construct a new Simple Motor object.

Definition at line 20 of file SimpleMotor.cpp.

Member Function Documentation

◆ get()

double art::SimpleMotor::get ( )

Returns the command the motor was last commanded to.

This method returns the command of the SimpleMotor. The command defaults to 0 and is changed whenever SimpleMotor::set(double cmd) is called. If the motor is stopped using vex::motor::stop() without using SimpleMotor::set(0), the command will continue to be whatever it last was, although the motor will continue to spin.

Todo
Fix persisting motor command with vex::motor::stop();
Returns
The command the motor is set to, as a percentage of the max

Definition at line 50 of file SimpleMotor.cpp.

◆ getSpeedMode()

bool art::SimpleMotor::getSpeedMode ( )

Get the SpeedMode of the SimpleMotor.

This method just returns whether the SimpleMotor is using SpeedMode. Nothing special here.

Returns
true the SimpleMotor is using SpeedMode
false the SimpleMotor is not using SpeedMode

Definition at line 33 of file SimpleMotor.cpp.

◆ set()

void art::SimpleMotor::set ( double cmd)

Sets the motor to spin at the specified command.

This method sets the motor's command and makes it spin according to that. The command should be a percentage with 100 being the max in the positive direction and -100 being the max in the negative direction. Commanding the motor to 0 will make it stop, but if you wish to control the kind of stop (coast, brake, hold), I'd recommend using the .stop() method from the vex::motor class;

Aditionally, if the SimpleMotor currently has SpeedMode set to true, the Motor will spin at a percent of the max speed, otherwise, it will simply command a percentage of the maximum of 12 volts. In some scenarios, SpeedMode will allow the motor to maintain approximately constant speed even once a load is applied.

Parameters
cmdThe command to set the motor to, as a percentage of the max

Example:

SimpleMotor testMotor = SimpleMotor( vex::motor(vex::PORT10 ) );
testMotor.set( -75 );
void set(double cmd)
Sets the motor to spin at the specified command.

Definition at line 38 of file SimpleMotor.cpp.

◆ setSpeedMode()

void art::SimpleMotor::setSpeedMode ( bool speedMode)

Set the SpeedMode of the SimpleMotor.

This method simply sets the SpeedMode of the SimpleMotor. It doesn't return anything, so additional methods cannot be chained to it.

Parameters
speedModeWhether or not the motor should use speed, rather than voltage

Example:

SimpleMotor testMotor = SimpleMotor( vex::motor(vex::PORT10 ) );
testMotor.setSpeedMode( false );
void setSpeedMode(bool speedMode)
Set the SpeedMode of the SimpleMotor.

Definition at line 28 of file SimpleMotor.cpp.

◆ withSpeedMode()

SimpleMotor & art::SimpleMotor::withSpeedMode ( bool speedMode)

Returns a SimpleMotor refrence with the specified speedMode.

Modifies the SimpleMotor object so that it has the speedMode specified by the parameter. A refrence to the SimpleMotor is returned, allowing more methods to be chained to it. This also means that it can be used directly as an extension to the contructor.

Parameters
speedModeWhether or not the motor should use speed, rather than voltage
Returns
SimpleMotor& (SimpleMotor Refrence)

Example:

SimpleMotor testMotor = SimpleMotor( vex::motor(vex::PORT10 ) );
testMotor.withSpeedMode( true );
SimpleMotor & withSpeedMode(bool speedMode)
Returns a SimpleMotor refrence with the specified speedMode.

Chained Methods Example:

Because a refrence to the object is returned, that refrence can be used to call other methods.

SimpleMotor testMotor = SimpleMotor( vex::motor(vex::PORT10 ) );
testMotor.withSpeedMode( true ).set( 50 );

Chained Methods Example:

Warning
Methods that don't return a refrence to a SimpleMotor Object can't be used to create a new Object. Even though you could chain .set(double cmd) onto the end, it doesn't return an object refrence, so it couldn't be used to construct testMotor.
SimpleMotor testMotor = SimpleMotor( vex::motor(vex::PORT10 ) ).withSpeedMode( true );

Definition at line 22 of file SimpleMotor.cpp.

Member Data Documentation

◆ m_cmd

double art::SimpleMotor::m_cmd {0}
private

The command the motor is set to, as a percentage of the max.

The command represents a percentage of the maximum voltage, 12 volts, or a percentage of the motor's max speed, depending on whether m_speedMode is set to true of false. The command is a percentage with 100 being the max in the positive direction and -100 being the max in the negative direction.

Because this member variable is private, it can only be accessed within the class. In order to modify or access this member, use the "get" and "set" methods provided.

Definition at line 179 of file SimpleMotor.h.

◆ m_speedMode

bool art::SimpleMotor::m_speedMode {false}
private

Whether or not the motor should use speed, rather than voltage.

The SpeedMode simple stores whether the motor interprets the command as a percentage of the max speed, or the precentage of the max voltage, 12 volts. Using speed rather than voltage should allow the motor to perform similarly whether or not load is applied, although this can lead to some unexpected behavior if something gets jammed. In most applications, using either is acceptable and safe.

Because this member variable is private, it can only be accessed within the class. In order to modify or access this member, use the "get" and "set" methods provided.

Definition at line 195 of file SimpleMotor.h.


The documentation for this class was generated from the following files: