Microchip_Examples/ClearPathModeExamples/ClearPath-MC_Series/FollowDigitalVelocity/FollowDigitalVelocity.cpp
bool CommandVelocity(int32_t commandedVelocity) {
    if (abs(commandedVelocity) > abs(maxSpeed)) {
        SerialPort.SendLine("Move rejected, requested velocity over the limit.");
        return false;
    }

    SerialPort.Send("Commanding velocity: ");
    SerialPort.SendLine(commandedVelocity);

    // Change ClearPath's Input A state to change direction.
    if (commandedVelocity > 0) {
        motor.MotorInAState(false);
    }
    else {
        motor.MotorInAState(true);
    }

    // Delays to send the correct filtered direction.
    Delay_ms(2 + INPUT_A_FILTER);

    // Find the scaling factor of our velocity range mapped to the PWM duty
    // cycle range (255 is the max duty cycle).
    double scaleFactor = 255 / maxSpeed;

    // Scale the velocity command to our duty cycle range.
    uint8_t dutyRequest = abs(commandedVelocity) * scaleFactor;

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

    return true;
}
/*------------------------------------------------------------------------------
 * CommandVelocity
 *
 *    Command the motor to move using a velocity of commandedVelocity
 *    Prints the move status to the USB serial port
 *    Returns when HLFB asserts (indicating the motor has reached the commanded
 *    velocity)
 *
 * Parameters:
 *    int commandedVelocity  - The velocity to command
 *
 * Returns: True/False depending on whether the velocity was successfully
 * commanded.
 */
CommandVelocity
Command the motor to move using a velocity of commandedVelocity
Prints the move status to the USB serial port
Returns when HLFB asserts (indicating the motor has reached the commanded
velocity)

int commandedVelocity  - The velocity to command

True/False depending on whether the velocity was successfully
commanded.
CommandVelocity Command the motor to move using a velocity of commandedVelocity Prints the move status to the USB serial port Returns when HLFB asserts ( indicating the motor has reached the commanded velocity ) int commandedVelocity - The velocity to command True / False depending on whether the velocity was successfully commanded .
bool CommandVelocity(int32_t commandedVelocity) {
    if (abs(commandedVelocity) > abs(maxSpeed)) {
        SerialPort.SendLine("Move rejected, requested velocity over the limit.");
        return false;
    }
    SerialPort.Send("Commanding velocity: ");
    SerialPort.SendLine(commandedVelocity);
    if (commandedVelocity > 0) {
        motor.MotorInAState(false);
    }
    else {
        motor.MotorInAState(true);
    }
    Delay_ms(2 + INPUT_A_FILTER);
    double scaleFactor = 255 / maxSpeed;
    uint8_t dutyRequest = abs(commandedVelocity) * scaleFactor;
    motor.MotorInBDuty(dutyRequest);
    return true;
}
bool CommandVelocity ( int32_t commandedVelocity ) { if ( abs ( commandedVelocity ) > abs ( maxSpeed ) ) { SerialPort . SendLine ( " " ) ; return false ; } SerialPort . Send ( " " ) ; SerialPort . SendLine ( commandedVelocity ) ; if ( commandedVelocity > 0 ) { motor . MotorInAState ( false ) ; } else { motor . MotorInAState ( true ) ; } Delay_ms ( 2 + INPUT_A_FILTER ) ; double scaleFactor = 255 / maxSpeed ; uint8_t dutyRequest = abs ( commandedVelocity ) * scaleFactor ; motor . MotorInBDuty ( dutyRequest ) ; return true ; }
CommandVelocity
    Command the motor to move using a velocity of commandedVelocity
    Prints the move status to the USB serial port
    Returns when HLFB asserts (indicating the motor has reached the commanded
    velocity)
CommandVelocity Command the motor to move using a velocity of commandedVelocity Prints the move status to the USB serial port Returns when HLFB asserts ( indicating the motor has reached the commanded velocity )
// Change ClearPath's Input A state to change direction. // Delays to send the correct filtered direction. // Find the scaling factor of our velocity range mapped to the PWM duty // cycle range (255 is the max duty cycle). // Scale the velocity command to our duty cycle range. // Command the move.