DMC60C API
This is the C/C++ API for the DMC60C.
|
Mid level DMC60C Interface. More...
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 |
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.
DMC60C | ( | int | deviceNumber = 0 | ) |
DMC60C | ( | int | deviceNumber = 0 , |
double | wheelDiametermm, | ||
double | gearRatio, | ||
int | encoderTicks | ||
) |
Creates a DMC60C object for use in a closed loop setup.
deviceNumber | The deviceNumber of the DMC60C Motor |
wheelDiametermm | The diameter of the wheel attached to the DMC60C in millimeters. |
gearRatio | The ratio of the gearbox (EX: 12 if using a 12:1 gearbox) |
encoderTicks | The number of pulses per channel per revolution on the quadrature encoder attached to the DMC60C motor. |
int getDeviceNumber | ( | ) | const |
void configWheel | ( | double | wheelDiametermm, |
double | gearRatio, | ||
int | encoderTicks | ||
) |
Reconfigure the wheel attached to the DMC60C.
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.
slot | 0 to configure PID slot 0, 1 to configure slot 1 |
P | value to set P constant to |
I | value to set I constant to |
D | value to set D constant to |
F | value to set F constant to |
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.
slot | PID slot to configure |
rampRate | value to set ramp rate to (0 - 32767). Lower values = slower ramp rate. |
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.
rampRate | value to set ramp rate to (0 - 32767) |
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.
currentAmps | The continuous current limit to set in amps. |
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.
currentAmps | The peak current limit to set in amps. |
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.
durationMs | The peak current duration in milliseconds. |
DMC_Code enableCurrentLimiting | ( | bool | enabled | ) |
Enables or disables current limiting mode.
enabled | If true, enabled current limiting. If false, disables current limiting. |
ControlMode getControlMode | ( | ) |
Returns the currently used control mode.
void driveVoltage | ( | double | percentVoltage | ) |
Drive the motor using open loop voltage mode.
percentVoltage | Percent to set the duty cycle of the motor to (-100.00 to 100.00) |
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().
revolutions | Signed number of revolutions to turn the wheel relative to it's starting position. |
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().
meters | Signed distance to drive relative of the wheel's starting position. |
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.
metersPerSecond | Speed to set the wheel to. |
void driveVoltageCompensation | ( | double | voltage | ) |
Drive the motor using open loop voltage compensation mode. This function applies the specified voltage to the motor.
voltage | Signed 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%). |
void driveCurrent | ( | double | currentAmps | ) |
Drive the motor using closed loop current mode. This mode drives the motor with a specific load current.
currentAmps | The desired current in amps. |
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.
deviceNumbertoFollow | Device number of the master DMC60C controller. |
void setPIDSlot | ( | unsigned int | slot | ) |
Sets the active PID slot.
slot | 0 to use PID slot 0, 1 to use PID slot 1. |
float getP | ( | unsigned int | slot | ) |
Retrieves the P gain value of the specified PID slot from the DMC60C.
slot | Which PID slot to get value from. |
float getI | ( | unsigned int | slot | ) |
Retrieves the I gain value of the specified PID slot from the DMC60C.
slot | Which PID slot to get value from. |
float getD | ( | unsigned int | slot | ) |
Retrieves the D gain value of the specified PID slot from the DMC60C.
slot | Which PID slot to get value from. |
float getF | ( | unsigned int | slot | ) |
Retrieves the F gain value of the specified PID slot from the DMC60C.
slot | Which PID slot to get value from. |
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.
void setLimitSwitches | ( | bool | overrideEnable, |
bool | forwardSwitchEnable, | ||
bool | reverseSwitchEnable | ||
) |
Overrides the limit switch settings to the specified configuration.
overrideEnable | Enables the limit switch override. If disabled, the DMC60C will use the parameters stored in memory. |
forwardSwitchEnable | Enables or disables the forward limit switch when override is enabled. |
reverseSwitchEnable | Enables or disables the reverse limit switch when override is enabled. |
bool getFwdLimitSwitch | ( | ) |
Gets the current state of the forward limit switch pin. This does not require the limit switch to be active.
bool getRevLimitSwitch | ( | ) |
Gets the current state of the reverse limit switch pin. This does not require the limit switch to be active.
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.
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.
LimitSwitch getFwdLimitSwitchStatus | ( | ) |
Returns all information regarding the forward limit switch.
LimitSwitch getRevLimitSwitchStatus | ( | ) |
Returns all information regarding the reverse limit switch.
bool isCurrentLimitActive | ( | ) |
Returns whether or not the current limit is actively throttling the output current.
bool isOverTempFaultActive | ( | ) |
Returns whether or not the over temperature fault is active.
bool isUnderVoltageFaultActive | ( | ) |
Returns whether or not the under voltage fault is active.
bool isGateDriveFaultActive | ( | ) |
Returns whether or not the Gate Driver fault is active.
void setBrakeCoast | ( | bool | overrideEnable, |
bool | brakeEnable | ||
) |
Overrides the brake/coast settings to the specified configuration.
float getBusVoltage | ( | ) |
float getAIN1Voltage | ( | ) |
Reads the voltage applied to the AIN1 pin on the DMC60C.
float getLoadCurrent | ( | ) |
Reads the load current of the DMC60C. This is the current that is running through the motor.
float getAmbientTemp | ( | ) |
DMC_Code zeroEncoderPosition | ( | ) |
Resets the encoder position to 0. This is used in position control mode.
double getRevolutionsTraveled | ( | ) |
Reads the number of revolutions the DMC60C has traveled relative to the encoder's zero position.
double getDistanceTraveled | ( | ) |
Reads the distance the DMC60C has traveled relative to the encoder's zero position.
double getMetersPerSecond | ( | ) |
Reads the current velocity in meters per second.
double getCurrentDutyCycle | ( | ) | const |
Get the duty cycle that is currently applied the the motor.
int getEncoderPositionCount | ( | ) |
Reads the current position count the DMC60C has logged from the encoder.
int getEncoderVelocityCount | ( | ) |
Reads the current velocity count the DMC60C has logged from the encoder in the past 100ms.
bool isEnabled | ( | ) |
Checks to see if the motor is enabled.
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.
isInverted | True to invert, false otherwise. |
void configPositionReset | ( | bool | resetOnFwdLimit, |
bool | resetOnRevLimit, | ||
bool | resetOnIndex | ||
) |
Configures the DMC60C to reset the position count when a limit switch is hit.
resetOnFwdLimit | True to reset the position count when fwd limit goes active. |
resetOnRevLimit | True to reset the position count when rev limit goes active. |
resetOnIndex | True to reset the position count when index pin goes active. |
void configIndexActiveEdge | ( | bool | edge | ) |
Configures the index pin on the DMC60C to trigger on rising or falling edge.
edge | True to set active edge to rising edge, false for falling edge. |
void SetInverted | ( | bool | isInverted | ) |
Inverts the motor direction.
isInverted | If true, motor will spin in reverse direction. |
bool GetInverted | ( | ) | const |
Returns whether or not the motor is inverted.