61#define motor ConnectorM0
68#define SerialPort ConnectorUsb
77 Connector::CPM_MODE_STEP_AND_DIR);
80 motor.HlfbMode(MotorDriver::HLFB_MODE_HAS_BIPOLAR_PWM);
82 motor.HlfbCarrier(MotorDriver::HLFB_CARRIER_482_HZ);
87 motor.AccelMax(100000);
91 SerialPort.Mode(Connector::USB_CDC);
92 SerialPort.Speed(baudRate);
93 uint32_t timeout = 5000;
95 SerialPort.PortOpen();
96 while (!SerialPort &&
Milliseconds() - startTime < timeout) {
101 motor.EnableRequest(
true);
102 SerialPort.SendLine(
"Motor Enabled");
105 if (motor.StatusReg().bit.AlertsPresent) {
107 SerialPort.SendLine(
"Motor status: 'In Alert'. Move Canceled.");
115 SerialPort.SendLine(
"Moving toward hardstop... Waiting for HLFB");
116 motor.MoveVelocity(5000);
119 motor.MoveVelocity(1000);
122 if (motor.StatusReg().bit.AlertsPresent) {
124 SerialPort.SendLine(
"Motor alert occurred during motion. Homing canceled.");
135 while (motor.HlfbState() != MotorDriver::HLFB_ASSERTED) {
136 if (motor.StatusReg().bit.AlertsPresent) {
138 SerialPort.SendLine(
"Motor alert detected. Homing canceled.");
147 motor.MoveStopAbrupt();
156 SerialPort.SendLine(
"Moving away from hardstop... Waiting for HLFB");
157 while (motor.HlfbState() != MotorDriver::HLFB_ASSERTED) {
162 if (motor.StatusReg().bit.AlertsPresent) {
164 SerialPort.SendLine(
"Motor alert occurred during offset move. Homing canceled.");
170 SerialPort.SendLine(
"Homing Complete. Motor Ready.");
174 motor.PositionRefSet(0);
void Delay_ms(uint32_t ms)
Blocks operations for ms milliseconds.
Definition SysTiming.h:287
uint32_t Milliseconds(void)
Number of milliseconds since the ClearCore was initialized.
bool MotorInputClocking(MotorClockRates newRate)
Sets the output step rate for the motor step generators.
bool MotorModeSet(MotorPair motorPair, Connector::ConnectorModes newMode)
Sets the operational mode for the specified MotorDriver connectors.