Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed QEI biquadFilter
Diff: arm.cpp
- Revision:
- 12:8295c02d740f
- Parent:
- 7:a80cb6b06320
- Child:
- 18:1c9dc6caab9d
--- a/arm.cpp Wed Nov 02 16:29:13 2016 +0000 +++ b/arm.cpp Thu Nov 03 13:08:44 2016 +0000 @@ -6,10 +6,13 @@ */ // Create an arm -Arm::Arm(float initialLength, PinName motorPWM, PinName motorDir, PinName encoderPin1, PinName encoderPin2): motorControl(motorPWM), - motorDirection(motorDir), - qei(encoderPin1, encoderPin2, NC, pulsesPerRevolution) { +Arm::Arm(float initialLength, float maxVelocity, PinName motorPWM, PinName motorDir, PinName encoderPin1, PinName encoderPin2) +: motorControl(motorPWM) +, motorDirection(motorDir) +, qei(encoderPin1, encoderPin2, NC, pulsesPerRevolution) +{ length = initialLength; + maxAllowedVelocity = maxVelocity; velocity = 0; encoderVelocity = 0; motorDirection = clockwise; @@ -36,11 +39,11 @@ // Counterclockwise rotation if (referenceVelocity < 0) { motorDirection = counterClockwise; - velocity = (referenceVelocity < -1 * maxVelocity)? -1 * maxVelocity:referenceVelocity; + velocity = (referenceVelocity < -1 * maxAllowedVelocity)? -1 * maxAllowedVelocity:referenceVelocity; // Clockwise rotation } else { motorDirection = clockwise; - velocity = (referenceVelocity > maxVelocity)? maxVelocity:referenceVelocity; + velocity = (referenceVelocity > maxAllowedVelocity)? maxAllowedVelocity:referenceVelocity; } // Output to motor setMotor(velocity/motorGain);