NoU_Motor
-
class NoU_Motor
Controls the output to one of the motor ports on the NoU2. The duty cycle of the 39 kHz PWM signal generated has 10 bits of precision (i.e. 0…1023).
Public Functions
-
NoU_Motor(uint8_t motorPort)
Constructs a new
NoU_Motor
on the specified port.- Parameters:
uint8_t motorPort – The port number of the motor, visible in front of each terminal block on the NoU2.
Example usage:
NoU_Motor myMotor(1);
Constructs a new motor on motor port 1.
-
void set(float output)
Sets the power being applied to the motor and the direction of spin. Affects the state of the motor by changing it to
FORWARD
orBACKWARD
, but neverBRAKE
orRELEASE
(seesetState()
for more information on these motor states).- Parameters:
float output – -1…1 The percentage of power to apply to the motor. The sign reverses the direction.
Example usage:
myMotor.set(-0.5);
Sets
myMotor
to spin in reverse at half speed.
-
void setPower(uint16_t power)
Sets the power being applied to the motor, not affecting the direction the motor spins. To control motor spin direction when using this function, use
setState()
.- Parameters:
uint16_t power – 0…1023 The duty cycle to send to the motor drivers, with 1023 being 100%.
Warning
This function is left public mainly to help with debugging issues with motor movement because it’s a bit closer to the hardware than
set()
, allowing users to set the duty cycle with explicit 10-bit precision. It shouldn’t be used on complete projects, but instead when you’re not sure why a motor isn’t behaving correctly and want to bypass any filtering you’ve applied to theset()
function (i.e usingsetInputExponent()
,setMaximumInput()
,setInverted()
, etc.).
-
void setState(uint8_t state)
Sets the state of the motor, changing the behaviour of subsequent calls to
setPower()
. Typical usage of this function is to set the motor to the brake or release states. Generally, this function shouldn’t be used to set the state to forward or backward, asset()
accomplishes that behaviour based on the sign of its parameter.- Parameters:
uint8_t state – The state to set the motor to. The possible inputs are defined as the following macros in Alfredo_NoU2.h:
FORWARD
,BACKWARD
,BRAKE
, andRELEASE
.
Example usage:
myMotor.setState(BRAKE);
Sets
myMotor
to brake mode. This state would be cleared the next timeset()
is called.See also
This more technical explanation of how the brake (slow decay) and release (fast decay) states work.
-
void setInverted(boolean isInverted)
Sets whether the motor should always spin in the direction opposite of standard. This function is usually meant to be used called just once during setup, not repeatedly during operation. To switch the direction of a motor dynamically, use the
set()
function.- Parameters:
boolean isInverted – If
true
, sets the motor to spin in the opposite direction of standard. Iffalse
, sets the motor to spin normally.
Example usage:
myMotor.setInverted(true);
Sets
myMotor
to be inverted.
-
boolean isInverted()
Gets whether the motor has been set as inverted using the
setInverted()
function.- Returns:
Returns
true
if the motor has be set as inverted;false
otherwise.
-
void setMinimumOutput(float minimumOutput)
Sets the minimum power that should be sent to the motor when using the
set()
function. Together withsetMaximumOutput()
, this function allows users to map inputs on the interval (0, 1] to (minimumOutput
,maximumOutput
]. That is, ifset()
was passed an input just above zero, it would be mapped to an output just aboveminimumOutput
, which would be sent to the motor.- Parameters:
float minimumOutput – 0…1 The minimum power that should be sent to the motor when using
set
.
Note
For motors in a
NoU_Drivetrain
, thesetMinimumOutput
method of theNoU_Drivetrain
class should be used, not this one.
-
void setMaximumOutput(float maximumOutput)
Sets the maximum power that should be sent to the motor when using the
set()
function. Together withsetMinimumOutput()
, this function allows users to map inputs on the interval (0, 1] to (minimumOutput
,maximumOutput
]. That is, ifset
was passed 1 as an input (i.e. full power), it would be mapped tomaximumOutput
, which would be sent to the motor.- Parameters:
float maximumOutput – 0…1 The maximum power that should be sent to the motor when using
set
.
Note
For motors in a
NoU_Drivetrain
, thesetMaximumOutput
method of theNoU_Drivetrain
class should be used, not this one.
-
void setExponent(float exponent)
Sets the exponent to apply to inputs to the
set()
function.- Parameters:
float exponent – The positive exponent to apply to inputs to
set()
.
Note
For motors in a
NoU_Drivetrain
, thesetExponent
method of theNoU_Drivetrain
class should be used, not this one.
-
void setDeadband(float deadband)
Sets the range of inputs to
set()
that should be mapped to zero.- Parameters:
float deadband – 0…1 All inputs to
set()
with a smaller magnitude than this parameter will be mapped to zero.
Note
For motors in a
NoU_Drivetrain
, thesetDeadband
method of theNoU_Drivetrain
class should be used, not this one.
-
float getOutput()
Gets the current percentage of power being delivered to the motor. Updates when
set()
andsetPower()
are called.- Returns:
-1…1 The percentage of power being delivered to the motor, with negative values representing the reverse direction
-
NoU_Motor(uint8_t motorPort)