Microchip_Examples/ClearPathModeExamples/ClearPath-MC_Series/FollowDigitalPosition/FollowDigitalPosition.cpp
bool CommandPosition(int32_t commandedPosition) {
    if (abs(commandedPosition) > abs(positionMaxPWM) ||
        abs(commandedPosition) < abs(positionZeroPWM)) {
        SerialPort.SendLine("Move rejected, invalid position requested");
        return false;
    }
    SerialPort.Send("Moving to position: ");
    SerialPort.SendLine(commandedPosition);

    // Find the scaling factor of our position range mapped to the PWM duty
    // cycle range (255 is the max duty cycle).
    double scaleFactor = 255 / abs(positionMaxPWM - positionZeroPWM);

    // Scale the position command to our duty cycle range.
    uint8_t dutyRequest = abs(commandedPosition - positionZeroPWM) * scaleFactor;

    // Command the move.
    motor.MotorInBDuty(dutyRequest);

    // Waits for HLFB to assert (signaling the move has successfully completed)
    SerialPort.SendLine("Moving... Waiting for HLFB");

    // Delay to give HLFB time to change according to the new command
    Delay_ms(2);

    while (motor.HlfbState() != MotorDriver::HLFB_ASSERTED) {
        continue;
    }

    SerialPort.SendLine("Move Done");
    return true;
}
/*------------------------------------------------------------------------------
 * CommandPosition
 *
 *    Move to position number commandedPosition (counts in MSP)
 *    Prints the move status to the USB serial port
 *    Returns when HLFB asserts (indicating the motor has reached the commanded
 *    position)
 *
 * Parameters:
 *    int commandedPosition  - The position, in counts, to command
 *
 * Returns: True/False depending on whether the position was successfully
 * commanded.
 */
CommandPosition
Move to position number commandedPosition (counts in MSP)
Prints the move status to the USB serial port
Returns when HLFB asserts (indicating the motor has reached the commanded
position)

int commandedPosition  - The position, in counts, to command

True/False depending on whether the position was successfully
commanded.
CommandPosition Move to position number commandedPosition ( counts in MSP ) Prints the move status to the USB serial port Returns when HLFB asserts ( indicating the motor has reached the commanded position ) int commandedPosition - The position in counts to command True / False depending on whether the position was successfully commanded .
bool CommandPosition(int32_t commandedPosition) {
    if (abs(commandedPosition) > abs(positionMaxPWM) ||
        abs(commandedPosition) < abs(positionZeroPWM)) {
        SerialPort.SendLine("Move rejected, invalid position requested");
        return false;
    }
    SerialPort.Send("Moving to position: ");
    SerialPort.SendLine(commandedPosition);
    double scaleFactor = 255 / abs(positionMaxPWM - positionZeroPWM);
    uint8_t dutyRequest = abs(commandedPosition - positionZeroPWM) * scaleFactor;
    motor.MotorInBDuty(dutyRequest);
    SerialPort.SendLine("Moving... Waiting for HLFB");
    Delay_ms(2);
    while (motor.HlfbState() != MotorDriver::HLFB_ASSERTED) {
        continue;
    }
    SerialPort.SendLine("Move Done");
    return true;
}
bool CommandPosition ( int32_t commandedPosition ) { if ( abs ( commandedPosition ) > abs ( positionMaxPWM ) || abs ( commandedPosition ) < abs ( positionZeroPWM ) ) { SerialPort . SendLine ( " " ) ; return false ; } SerialPort . Send ( " " ) ; SerialPort . SendLine ( commandedPosition ) ; double scaleFactor = 255 / abs ( positionMaxPWM - positionZeroPWM ) ; uint8_t dutyRequest = abs ( commandedPosition - positionZeroPWM ) * scaleFactor ; motor . MotorInBDuty ( dutyRequest ) ; SerialPort . SendLine ( " " ) ; Delay_ms ( 2 ) ; while ( motor . HlfbState ( ) != MotorDriver :: HLFB_ASSERTED ) { continue ; } SerialPort . SendLine ( " " ) ; return true ; }
CommandPosition
    Move to position number commandedPosition (counts in MSP)
    Prints the move status to the USB serial port
    Returns when HLFB asserts (indicating the motor has reached the commanded
    position)
CommandPosition Move to position number commandedPosition ( counts in MSP ) Prints the move status to the USB serial port Returns when HLFB asserts ( indicating the motor has reached the commanded position )
// Find the scaling factor of our position range mapped to the PWM duty // cycle range (255 is the max duty cycle). // Scale the position command to our duty cycle range. // Command the move. // Waits for HLFB to assert (signaling the move has successfully completed) // Delay to give HLFB time to change according to the new command