56bool followPosition =
false;
59int32_t velocityLimit = 100000;
60int32_t accelerationLimit = 1000000;
63bool swapDirection =
false;
66bool indexInverted =
false;
70 uint32_t timeout = 5000;
73 while (!ConnectorUsb &&
Milliseconds() - startTime < timeout) {
87 MotorMgr.
MotorModeSet(MotorManager::MOTOR_ALL, Connector::CPM_MODE_STEP_AND_DIR);
90 ConnectorM0.
HlfbMode(MotorDriver::HLFB_MODE_HAS_BIPOLAR_PWM);
92 ConnectorM0.
HlfbCarrier(MotorDriver::HLFB_CARRIER_482_HZ);
95 ConnectorM0.
VelMax(velocityLimit);
96 ConnectorM0.
AccelMax(accelerationLimit);
100 ConnectorUsb.
SendLine(
"Motor Enabled");
103 ConnectorUsb.
SendLine(
"Waiting for HLFB...");
104 while (ConnectorM0.
HlfbState() != MotorDriver::HLFB_ASSERTED) {
107 ConnectorUsb.
SendLine(
"Motor Ready");
110 int32_t position = 0;
111 int32_t velocity = 0;
112 int32_t indexPosition = 0;
113 int32_t lastIndexPosition = 0;
114 bool quadratureError =
false;
121 while (!quadratureError) {
129 if (followPosition) {
130 snprintf(info, 100,
"Encoder position: %ld counts", position);
133 snprintf(info, 100,
"Encoder velocity: %ld counts/sec", velocity);
139 if (indexPosition != lastIndexPosition) {
140 snprintf(info, 100,
"Detected index at position: %ld",
145 lastIndexPosition = indexPosition;
149 ConnectorUsb.
SendLine(
"Motor status: 'In Alert'. Move Canceled.");
153 if (followPosition) {
155 ConnectorM0.
Move(position, MotorDriver::MOVE_TARGET_ABSOLUTE);
166 ConnectorUsb.
SendLine(
"Quadrature error detected. Stopping motion...");
uint32_t Milliseconds(void)
Number of milliseconds since the ClearCore was initialized.
bool SendLine()
Send carriage return and newline characters.
Definition ISerial.h:162
void HlfbMode(HlfbModes newMode)
Sets operational mode of the HLFB to match up with the HLFB configuration of a ClearPathâ„¢ motor.
Definition MotorDriver.h:709
bool EnableRequest()
Accessor for the enable request state of the motor.
Definition MotorDriver.h:544
virtual bool MoveVelocity(int32_t velocity) override
Issues a velocity move at the specified velocity.
volatile const HlfbStates & HlfbState()
Return the latest HLFB state information.
Definition MotorDriver.h:672
bool HlfbCarrier(HlfbCarrierFrequency freq)
Set the HLFB carrier frequency signal.
Definition MotorDriver.h:773
volatile const StatusRegMotor & StatusReg()
Accessor for the current Motor Status Register.
Definition MotorDriver.h:835
virtual bool Move(int32_t dist, MoveTarget moveTarget=MOVE_TARGET_REL_END_POSN) override
Issues a positional move for the specified distance.
bool MotorModeSet(MotorPair motorPair, Connector::ConnectorModes newMode)
Sets the operational mode for the specified MotorDriver connectors.
void AccelMax(uint32_t accelMax)
Sets the maximum acceleration in step pulses per second^2.
void VelMax(uint32_t velMax)
Sets the maximum velocity for position moves, in step pulses per second.
struct ClearCore::MotorDriver::StatusRegMotor::@2 bit
uint32_t AlertsPresent
Definition MotorDriver.h:301