DMC60C API
This is the C/C++ API for the DMC60C.
WPI_DMC60C Class Reference

High Level DMC60C Interface. More...

Inheritance diagram for WPI_DMC60C:
DMC60C

Public Member Functions

 WPI_DMC60C (int deviceNumber)
 Creates a DMC60C object for use in an open loop setup. More...
 
 WPI_DMC60C (int deviceNumber, double wheelDiametermm, double gearRatio, int encoderTicks)
 Creates a DMC60C object for use in a closed loop setup. More...
 
void Set (double speed) override
 Set command used in WPI Speedcontroller class. Sets the speed to the specified duty cycle. More...
 
double Get () const override
 Get command used in WPI Speedcontroller class. Gets the current duty cycle. More...
 
void SetInverted (bool isInverted) override
 Inverts the motor direction. More...
 
bool GetInverted () const override
 Returns whether or not the motor is inverted. More...
 
void Disable () override
 Disable command used in WPI Speedcontroller class. Disables the motor.
 
void PIDWrite (double output) override
 Virtual function overload from PIDOutput class in SpeedController. Sets the duty cycle. More...
 
void StopMotor () override
 Stops the motor.
 
void GetDescription (wpi::raw_ostream &desc) const override
 Prints the DMC ID to an output stream. More...
 
- Public Member Functions inherited from DMC60C
 DMC60C (int deviceNumber)
 Creates a DMC60C object for use in an open loop setup. More...
 
 DMC60C (int deviceNumber, double wheelDiametermm, double gearRatio, int encoderTicks)
 Creates a DMC60C object for use in a closed loop setup. More...
 
int getDeviceNumber () const
 Get the device number associated with this DMC60C object. More...
 
void configWheel (double wheelDiametermm, double gearRatio, int encoderTicks)
 Reconfigure the wheel attached to the DMC60C. More...
 
DMC_Code configPID (unsigned int slot, float P, float I, float D, float F)
 Configures the PID and F constants for use in the closed loop. More...
 
DMC_Code configClosedLoopRampRate (unsigned int slot, unsigned int rampRate)
 Sets the Closed Loop Ramp Rate for the specified PID slot. The closed loop ramp rate specifies the maximum number of throttle units the output can change by each time the control loop executes in closed loop control mode (Velocity, Position, or Current). For example, If the closed loop ramp rate is set to 1000 and the PID update function determines that the throttle should be increased by 5000 units then the immediate throttle increase will be limited to 1000 units. If the next PID Update doesn't change the target throttle output value, the throttle will be increased by another 1000 units the next time the control loop executes. This process will continue until the target throttle is reached or a new throttle value is calculated. The control loop executes once every 500 µs. Therefore, specifying a closed loop ramp rate of 16 would result in it taking approximately 1.02 seconds to go from 0% throttle (0) to 100% throttle (32767). Specifying a value of 0 for the closed loop ramp rate disables throttling and allows the output to be immediately set to the target value. This parameter is stored in nonvolatile memory and is preserved across power cycles. More...
 
void configOpenLoopRampRate (unsigned short rampRate)
 Sets the Open Loop Ramp Rate. If a value of 0 is specified in the vltgRampSet field, then the output throttle will be immediately set to the target duty cycle the next time the control loop executes. If a non-zero value is specified in the vltgRampSet field, then the number of throttle units that the output can change by each time the control loop executes will be limited to the value that was specified. For example, if the output throttle is currently set to 5000, the trgt field specifies 10000, and the vltgRampSet field specifies 2500, then the control loop will need to execute twice before the output throttle is set to a target duty cycle of 10000. The control loop executes every 500 µs. In this example it may take up to 1 millisecond for the output throttle to be set to the target duty cycle. More...
 
DMC_Code setContinuousCurrentLimit (double currentAmps)
 Sets the continuous current limit. This applies only if current limiting is enabled. The continuous current limit is the maximum current that can be drawn by the DMC60C AFTER the peak current limit has been hit for the peak current duration. If the continuous current limit is greater than or equal to the peak current limit, then the DMC60C will begin limiting the current immediately after the continuous current limit is exceeded. More...
 
DMC_Code setPeakCurrentLimit (double currentAmps)
 Sets the peak current limit. This only applies if current limiting is enabled. The peak current is the max current that can be applied to the motor at any given time. This limit can be applied for up to [peak current duration] milliseconds. Afterwards the continuous current limit will be applied. If the peak current limit is set to a value lower than the continuous current limit, the DMC60C will apply the continuous current limit immediately after it detects that the continuous current limit has been exceeded. More...
 
DMC_Code setPeakCurrentDuration (int durationMs)
 Sets the peak current duration. This only applies if current limiting is enabled. The peak current duration is the maximum amount of time the peak current can be applied to the motor. After this duration, the continuous current limit will be applied. If the duration is set to 0, the DMC60C will begin applying the continuous current limit immediately after the peak current limit has been exceeded. More...
 
DMC_Code enableCurrentLimiting (bool enabled)
 Enables or disables current limiting mode. More...
 
ControlMode getControlMode ()
 Returns the currently used control mode. More...
 
void driveVoltage (double percentVoltage)
 Drive the motor using open loop voltage mode. More...
 
void drivePosition (double revolutions)
 Drive the motor using closed loop position mode. This function uses the gearbox ratio and encoderticks values to set the position of the wheel and hold it there. The wheel's position is set to 0 at DMC60C power on. This position can also be reset using zeroEncoderPosition(). More...
 
void driveDistance (double meters)
 Drive the motor using closed loop position mode. This function uses the wheel's diameter, gearbox ratio, and encoderticks values to set the position of the wheel and hold it there. The wheel's position is set to 0 at DMC60C power on. This position can also be reset using zeroEncoderPosition(). More...
 
void driveVelocity (double metersPerSecond)
 Drive the motor using closed loop velocity mode. This function uses the wheel's diameter, gearbox ratio, and encoderticks values to set the velocity of the wheel and maintain that speed. More...
 
void driveVoltageCompensation (double voltage)
 Drive the motor using open loop voltage compensation mode. This function applies the specified voltage to the motor. More...
 
void driveCurrent (double currentAmps)
 Drive the motor using closed loop current mode. This mode drives the motor with a specific load current. More...
 
void followerMode (int deviceNumbertoFollow)
 Sets the motor to slave follower mode. This mode behaves similar to voltage mode, however the duty cycle will be set to the master's duty cycle. More...
 
void setPIDSlot (unsigned int slot)
 Sets the active PID slot. More...
 
float getP (unsigned int slot)
 Retrieves the P gain value of the specified PID slot from the DMC60C. More...
 
float getI (unsigned int slot)
 Retrieves the I gain value of the specified PID slot from the DMC60C. More...
 
float getD (unsigned int slot)
 Retrieves the D gain value of the specified PID slot from the DMC60C. More...
 
float getF (unsigned int slot)
 Retrieves the F gain value of the specified PID slot from the DMC60C. More...
 
double getClosedLoopError ()
 Gets the current closed loop error from the DMC60C. This function can be used to help configure the PID values of a closed loop system. More...
 
void setLimitSwitches (bool overrideEnable, bool forwardSwitchEnable, bool reverseSwitchEnable)
 Overrides the limit switch settings to the specified configuration. More...
 
bool getFwdLimitSwitch ()
 Gets the current state of the forward limit switch pin. This does not require the limit switch to be active. More...
 
bool getRevLimitSwitch ()
 Gets the current state of the reverse limit switch pin. This does not require the limit switch to be active. More...
 
bool isFwdLimitSwitchActive ()
 Returns whether or not the forward limit switch is active or not. This will only return true if the limit switch is enabled and active. More...
 
bool isRevLimitSwitchActive ()
 Returns whether or not the reverse limit switch is active or not. This will only return true if the limit switch is enabled and active. More...
 
LimitSwitch getFwdLimitSwitchStatus ()
 Returns all information regarding the forward limit switch. More...
 
LimitSwitch getRevLimitSwitchStatus ()
 Returns all information regarding the reverse limit switch. More...
 
bool isCurrentLimitActive ()
 Returns whether or not the current limit is actively throttling the output current. More...
 
bool isOverTempFaultActive ()
 Returns whether or not the over temperature fault is active. More...
 
bool isUnderVoltageFaultActive ()
 Returns whether or not the under voltage fault is active. More...
 
bool isGateDriveFaultActive ()
 Returns whether or not the Gate Driver fault is active. More...
 
void setBrakeCoast (bool overrideEnable, bool brakeEnable)
 Overrides the brake/coast settings to the specified configuration. More...
 
float getBusVoltage ()
 Reads the DMC60C's bus (battery) voltage. More...
 
float getAIN1Voltage ()
 Reads the voltage applied to the AIN1 pin on the DMC60C. More...
 
float getLoadCurrent ()
 Reads the load current of the DMC60C. This is the current that is running through the motor. More...
 
float getAmbientTemp ()
 Reads the ambient temperature of the DMC60C. More...
 
DMC_Code zeroEncoderPosition ()
 Resets the encoder position to 0. This is used in position control mode. More...
 
double getRevolutionsTraveled ()
 Reads the number of revolutions the DMC60C has traveled relative to the encoder's zero position. More...
 
double getDistanceTraveled ()
 Reads the distance the DMC60C has traveled relative to the encoder's zero position. More...
 
double getMetersPerSecond ()
 Reads the current velocity in meters per second. More...
 
double getCurrentDutyCycle () const
 Get the duty cycle that is currently applied the the motor. More...
 
int getEncoderPositionCount ()
 Reads the current position count the DMC60C has logged from the encoder. More...
 
int getEncoderVelocityCount ()
 Reads the current velocity count the DMC60C has logged from the encoder in the past 100ms. More...
 
void disableMotor ()
 Disables the motor.
 
bool isEnabled ()
 Checks to see if the motor is enabled. More...
 
void invertEncoder (bool isInverted)
 Inverts the signals of the feedback sensor. This alleviates the need to swap the QEA and QEB signals when the quadrature encoder does not match that of the motor. More...
 
void configPositionReset (bool resetOnFwdLimit, bool resetOnRevLimit, bool resetOnIndex)
 Configures the DMC60C to reset the position count when a limit switch is hit. More...
 
void configIndexActiveEdge (bool edge)
 Configures the index pin on the DMC60C to trigger on rising or falling edge. More...
 
void SetInverted (bool isInverted)
 Inverts the motor direction. More...
 
bool GetInverted () const
 Returns whether or not the motor is inverted. More...
 

Protected Member Functions

void InitSendable (frc::SendableBuilder &builder)
 Initializes the DMC60C for use as a sendable object in the FRC smart dashboard.
 

Additional Inherited Members

- Protected Attributes inherited from DMC60C
std::unique_ptr< DMC60LowLevel_DMC60LowLevel
 
int _deviceNumber
 
double _wheelDiametermm
 
double _gearRatio
 
int _encoderTicks
 
ControlMode _controlMode
 
bool _isEnabled
 
bool _isMotorReversed
 
bool _isEncoderReversed
 

Detailed Description

High Level DMC60C Interface.

This class contains all of the high level functions used to communicate with the DMC60C.

Constructor & Destructor Documentation

◆ WPI_DMC60C() [1/2]

WPI_DMC60C ( int  deviceNumber)

Creates a DMC60C object for use in an open loop setup.

Parameters
deviceNumberThe deviceNumber of the DMC60C Motor

◆ WPI_DMC60C() [2/2]

WPI_DMC60C ( int  deviceNumber,
double  wheelDiametermm,
double  gearRatio,
int  encoderTicks 
)

Creates a DMC60C object for use in a closed loop setup.

Parameters
deviceNumberThe deviceNumber of the DMC60C Motor
wheelDiametermmThe diameter of the wheel attached to the DMC60C in millimeters.
gearRatioThe ratio of the gearbox (EX: 12 if using a 12:1 gearbox)
encoderTicksThe number of pulses per channel per revolution on the quadrature encoder attached to the DMC60C motor.

Member Function Documentation

◆ Set()

void Set ( double  speed)
override

Set command used in WPI Speedcontroller class. Sets the speed to the specified duty cycle.

Parameters
speedDuty cycle (-1.0 to 1.0)

◆ Get()

double Get ( ) const
override

Get command used in WPI Speedcontroller class. Gets the current duty cycle.

Returns
Duty cycle (-1.0 to 1.0)

◆ SetInverted()

void SetInverted ( bool  isInverted)
override

Inverts the motor direction.

Parameters
isInvertedIf true, motor will spin in reverse direction.

◆ GetInverted()

bool GetInverted ( ) const
override

Returns whether or not the motor is inverted.

Returns
True if motor is inverted, false otherwise.

◆ PIDWrite()

void PIDWrite ( double  output)
override

Virtual function overload from PIDOutput class in SpeedController. Sets the duty cycle.

Parameters
outputSigned duty cycle (-1 to 1).

◆ GetDescription()

void GetDescription ( wpi::raw_ostream &  desc) const
override

Prints the DMC ID to an output stream.

Parameters
descAddress of output stream.