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

Mid level DMC60C Interface. More...

Inheritance diagram for DMC60C:
WPI_DMC60C

Public Member Functions

 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 Attributes

std::unique_ptr< DMC60LowLevel_DMC60LowLevel
 
int _deviceNumber
 
double _wheelDiametermm
 
double _gearRatio
 
int _encoderTicks
 
ControlMode _controlMode
 
bool _isEnabled
 
bool _isMotorReversed
 
bool _isEncoderReversed
 

Detailed Description

Mid level DMC60C Interface.

This class contains all of the mid level functions used to communicate with the DMC60C. This is used in Java, Labview and CPP implementations.

Constructor & Destructor Documentation

◆ DMC60C() [1/2]

DMC60C ( int  deviceNumber = 0)

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

Parameters
deviceNumberThe deviceNumber of the DMC60C Motor

◆ DMC60C() [2/2]

DMC60C ( int  deviceNumber = 0,
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

◆ getDeviceNumber()

int getDeviceNumber ( ) const

Get the device number associated with this DMC60C object.

Returns
Device number of this DMC60C object (0 - 64)

◆ configWheel()

void configWheel ( double  wheelDiametermm,
double  gearRatio,
int  encoderTicks 
)

Reconfigure the wheel attached to the DMC60C.

Parameters
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.

◆ configPID()

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.

Parameters
slot0 to configure PID slot 0, 1 to configure slot 1
Pvalue to set P constant to
Ivalue to set I constant to
Dvalue to set D constant to
Fvalue to set F constant to
Returns
DMC_Code Status code

◆ configClosedLoopRampRate()

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.

Parameters
slotPID slot to configure
rampRatevalue to set ramp rate to (0 - 32767). Lower values = slower ramp rate.
Returns
DMC_Code Status code

◆ configOpenLoopRampRate()

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.

Parameters
rampRatevalue to set ramp rate to (0 - 32767)

◆ setContinuousCurrentLimit()

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.

Parameters
currentAmpsThe continuous current limit to set in amps.
Returns
DMC_Code Status code

◆ setPeakCurrentLimit()

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.

Parameters
currentAmpsThe peak current limit to set in amps.
Returns
DMC_Code Status code

◆ setPeakCurrentDuration()

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.

Parameters
durationMsThe peak current duration in milliseconds.
Returns
DMC_Code Status code

◆ enableCurrentLimiting()

DMC_Code enableCurrentLimiting ( bool  enabled)

Enables or disables current limiting mode.

Parameters
enabledIf true, enabled current limiting. If false, disables current limiting.
Returns
DMC_Code Status code

◆ getControlMode()

ControlMode getControlMode ( )

Returns the currently used control mode.

Returns
ControlMode The currently used control mode, as seen in the DMC60C general status packet.

◆ driveVoltage()

void driveVoltage ( double  percentVoltage)

Drive the motor using open loop voltage mode.

Parameters
percentVoltagePercent to set the duty cycle of the motor to (-100.00 to 100.00)

◆ drivePosition()

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().

Parameters
revolutionsSigned number of revolutions to turn the wheel relative to it's starting position.

◆ driveDistance()

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().

Parameters
metersSigned distance to drive relative of the wheel's starting position.

◆ driveVelocity()

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.

Parameters
metersPerSecondSpeed to set the wheel to.

◆ driveVoltageCompensation()

void driveVoltageCompensation ( double  voltage)

Drive the motor using open loop voltage compensation mode. This function applies the specified voltage to the motor.

Parameters
voltageSigned voltage to send to the motor. If the specified output voltage exceeds the input voltage, then the duty cycle is limited to 100% (or -100%).

◆ driveCurrent()

void driveCurrent ( double  currentAmps)

Drive the motor using closed loop current mode. This mode drives the motor with a specific load current.

Parameters
currentAmpsThe desired current in amps.

◆ followerMode()

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.

Parameters
deviceNumbertoFollowDevice number of the master DMC60C controller.

◆ setPIDSlot()

void setPIDSlot ( unsigned int  slot)

Sets the active PID slot.

Parameters
slot0 to use PID slot 0, 1 to use PID slot 1.

◆ getP()

float getP ( unsigned int  slot)

Retrieves the P gain value of the specified PID slot from the DMC60C.

Parameters
slotWhich PID slot to get value from.
Returns
Value of the P gain.

◆ getI()

float getI ( unsigned int  slot)

Retrieves the I gain value of the specified PID slot from the DMC60C.

Parameters
slotWhich PID slot to get value from.
Returns
Value of the I gain.

◆ getD()

float getD ( unsigned int  slot)

Retrieves the D gain value of the specified PID slot from the DMC60C.

Parameters
slotWhich PID slot to get value from.
Returns
Value of the D gain.

◆ getF()

float getF ( unsigned int  slot)

Retrieves the F gain value of the specified PID slot from the DMC60C.

Parameters
slotWhich PID slot to get value from.
Returns
Value of the F gain.

◆ getClosedLoopError()

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.

Returns
Value of the closed loop error. Depending on the mode, units can vary.

◆ setLimitSwitches()

void setLimitSwitches ( bool  overrideEnable,
bool  forwardSwitchEnable,
bool  reverseSwitchEnable 
)

Overrides the limit switch settings to the specified configuration.

Parameters
overrideEnableEnables the limit switch override. If disabled, the DMC60C will use the parameters stored in memory.
forwardSwitchEnableEnables or disables the forward limit switch when override is enabled.
reverseSwitchEnableEnables or disables the reverse limit switch when override is enabled.

◆ getFwdLimitSwitch()

bool getFwdLimitSwitch ( )

Gets the current state of the forward limit switch pin. This does not require the limit switch to be active.

Returns
The state of the limit switch pin.

◆ getRevLimitSwitch()

bool getRevLimitSwitch ( )

Gets the current state of the reverse limit switch pin. This does not require the limit switch to be active.

Returns
The state of the limit switch pin.

◆ isFwdLimitSwitchActive()

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.

Returns
True if limit switch is active, false if not.

◆ isRevLimitSwitchActive()

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.

Returns
True if limit switch is active, false if not.

◆ getFwdLimitSwitchStatus()

LimitSwitch getFwdLimitSwitchStatus ( )

Returns all information regarding the forward limit switch.

Returns
A struct containing the current status of the limit switch.

◆ getRevLimitSwitchStatus()

LimitSwitch getRevLimitSwitchStatus ( )

Returns all information regarding the reverse limit switch.

Returns
A struct containing the current status of the limit switch.

◆ isCurrentLimitActive()

bool isCurrentLimitActive ( )

Returns whether or not the current limit is actively throttling the output current.

Returns
True if current limit is active.

◆ isOverTempFaultActive()

bool isOverTempFaultActive ( )

Returns whether or not the over temperature fault is active.

Returns
True if there is an active over temperature fault.

◆ isUnderVoltageFaultActive()

bool isUnderVoltageFaultActive ( )

Returns whether or not the under voltage fault is active.

Returns
True if there is an active under voltage fault.

◆ isGateDriveFaultActive()

bool isGateDriveFaultActive ( )

Returns whether or not the Gate Driver fault is active.

Returns
True if there is an active gate driver fault.

◆ setBrakeCoast()

void setBrakeCoast ( bool  overrideEnable,
bool  brakeEnable 
)

Overrides the brake/coast settings to the specified configuration.

Parameters
overrideEnableEnables the brake/coast override. If disabled, the DMC60C will use the parameters stored in memory.
brakeEnableIf true, DMC60C will brake when neutral throttle is applied. If false, DMC60C will coast when neutral throttle is applied.

◆ getBusVoltage()

float getBusVoltage ( )

Reads the DMC60C's bus (battery) voltage.

Returns
The input voltage applied to the DMC60C in volts.

◆ getAIN1Voltage()

float getAIN1Voltage ( )

Reads the voltage applied to the AIN1 pin on the DMC60C.

Returns
Voltage of the AIN1 pin in volts.

◆ getLoadCurrent()

float getLoadCurrent ( )

Reads the load current of the DMC60C. This is the current that is running through the motor.

Returns
Load current in amps.

◆ getAmbientTemp()

float getAmbientTemp ( )

Reads the ambient temperature of the DMC60C.

Returns
Ambient temperature of the DMC60C in degrees C.

◆ zeroEncoderPosition()

DMC_Code zeroEncoderPosition ( )

Resets the encoder position to 0. This is used in position control mode.

Returns
Status code

◆ getRevolutionsTraveled()

double getRevolutionsTraveled ( )

Reads the number of revolutions the DMC60C has traveled relative to the encoder's zero position.

Returns
Signed number of revolutions.

◆ getDistanceTraveled()

double getDistanceTraveled ( )

Reads the distance the DMC60C has traveled relative to the encoder's zero position.

Returns
Distance in meters.

◆ getMetersPerSecond()

double getMetersPerSecond ( )

Reads the current velocity in meters per second.

Returns
Velocity in meters per second.

◆ getCurrentDutyCycle()

double getCurrentDutyCycle ( ) const

Get the duty cycle that is currently applied the the motor.

Returns
Signed percent duty cycle.

◆ getEncoderPositionCount()

int getEncoderPositionCount ( )

Reads the current position count the DMC60C has logged from the encoder.

Returns
Signed position count.

◆ getEncoderVelocityCount()

int getEncoderVelocityCount ( )

Reads the current velocity count the DMC60C has logged from the encoder in the past 100ms.

Returns
Velocity count read from encoder.

◆ isEnabled()

bool isEnabled ( )

Checks to see if the motor is enabled.

Returns
True if enabled, false if not.

◆ invertEncoder()

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.

Parameters
isInvertedTrue to invert, false otherwise.

◆ configPositionReset()

void configPositionReset ( bool  resetOnFwdLimit,
bool  resetOnRevLimit,
bool  resetOnIndex 
)

Configures the DMC60C to reset the position count when a limit switch is hit.

Parameters
resetOnFwdLimitTrue to reset the position count when fwd limit goes active.
resetOnRevLimitTrue to reset the position count when rev limit goes active.
resetOnIndexTrue to reset the position count when index pin goes active.

◆ configIndexActiveEdge()

void configIndexActiveEdge ( bool  edge)

Configures the index pin on the DMC60C to trigger on rising or falling edge.

Parameters
edgeTrue to set active edge to rising edge, false for falling edge.

◆ SetInverted()

void SetInverted ( bool  isInverted)

Inverts the motor direction.

Parameters
isInvertedIf true, motor will spin in reverse direction.

◆ GetInverted()

bool GetInverted ( ) const

Returns whether or not the motor is inverted.

Returns
True if motor is inverted, false otherwise.