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: TSI USBDevice mbed-dev
Fork of SmartWheels by
Hardwares/Servo.cpp@13:7dcb1642ef99, 2017-02-08 (annotated)
- Committer:
- hazheng
- Date:
- Wed Feb 08 23:47:02 2017 +0000
- Revision:
- 13:7dcb1642ef99
- Parent:
- 11:676ea42afd56
- Child:
- 14:88302da8bff0
- Child:
- 16:66c7a09e71ee
Finished reading SCCB from camera.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Bobymicjohn | 11:676ea42afd56 | 1 | #include "Servo.h" |
| Bobymicjohn | 11:676ea42afd56 | 2 | |
| Bobymicjohn | 11:676ea42afd56 | 3 | #include "Core.h" |
| Bobymicjohn | 11:676ea42afd56 | 4 | #include "PinAssignment.h" |
| Bobymicjohn | 11:676ea42afd56 | 5 | #include "SWUSBServer.h" |
| Bobymicjohn | 11:676ea42afd56 | 6 | |
| Bobymicjohn | 11:676ea42afd56 | 7 | #include "mbed.h" |
| Bobymicjohn | 11:676ea42afd56 | 8 | |
| Bobymicjohn | 11:676ea42afd56 | 9 | |
| Bobymicjohn | 11:676ea42afd56 | 10 | Servo::Servo(SW::Core& core) : |
| Bobymicjohn | 11:676ea42afd56 | 11 | m_core(core), |
| hazheng | 13:7dcb1642ef99 | 12 | m_pwm(PwmOut(PIN_SC_SERVO)) |
| Bobymicjohn | 11:676ea42afd56 | 13 | |
| Bobymicjohn | 11:676ea42afd56 | 14 | { |
| Bobymicjohn | 11:676ea42afd56 | 15 | m_pulseWidth = 0.0015; |
| Bobymicjohn | 11:676ea42afd56 | 16 | m_pwm.period(0.020); |
| Bobymicjohn | 11:676ea42afd56 | 17 | m_pwm.pulsewidth(m_pulseWidth); |
| Bobymicjohn | 11:676ea42afd56 | 18 | } |
| Bobymicjohn | 11:676ea42afd56 | 19 | |
| Bobymicjohn | 11:676ea42afd56 | 20 | |
| Bobymicjohn | 11:676ea42afd56 | 21 | void Servo::Update(float deltaTime) |
| Bobymicjohn | 11:676ea42afd56 | 22 | { |
| Bobymicjohn | 11:676ea42afd56 | 23 | |
| Bobymicjohn | 11:676ea42afd56 | 24 | } |
| Bobymicjohn | 11:676ea42afd56 | 25 | |
| Bobymicjohn | 11:676ea42afd56 | 26 | void Servo::setAngle(float angle) |
| Bobymicjohn | 11:676ea42afd56 | 27 | { |
| Bobymicjohn | 11:676ea42afd56 | 28 | if(angle > SERVO_RT * SERVO_MAX_ANGLE) |
| Bobymicjohn | 11:676ea42afd56 | 29 | angle = SERVO_RT * SERVO_MAX_ANGLE; |
| Bobymicjohn | 11:676ea42afd56 | 30 | else if(angle < SERVO_LF * SERVO_MAX_ANGLE) |
| Bobymicjohn | 11:676ea42afd56 | 31 | angle = SERVO_LF * SERVO_MAX_ANGLE; |
| Bobymicjohn | 11:676ea42afd56 | 32 | |
| Bobymicjohn | 11:676ea42afd56 | 33 | m_pulseWidth = (0.0015 + (0.00001667 * angle)); |
| Bobymicjohn | 11:676ea42afd56 | 34 | char buf[10]; |
| Bobymicjohn | 11:676ea42afd56 | 35 | sprintf(buf, "%f", m_pulseWidth); |
| Bobymicjohn | 11:676ea42afd56 | 36 | m_core.GetUSBServer().PushUnreliableMsg('D', buf); |
| Bobymicjohn | 11:676ea42afd56 | 37 | m_pwm.pulsewidth(m_pulseWidth); |
| Bobymicjohn | 11:676ea42afd56 | 38 | } |
| Bobymicjohn | 11:676ea42afd56 | 39 | |
| Bobymicjohn | 11:676ea42afd56 | 40 | /* |
| Bobymicjohn | 11:676ea42afd56 | 41 | void Servo::turnRight(float angle) |
| Bobymicjohn | 11:676ea42afd56 | 42 | { |
| Bobymicjohn | 11:676ea42afd56 | 43 | if(angle > 21) |
| Bobymicjohn | 11:676ea42afd56 | 44 | angle = 21; |
| Bobymicjohn | 11:676ea42afd56 | 45 | |
| Bobymicjohn | 11:676ea42afd56 | 46 | m_pulseWidth = (0.0015 + (0.000017 * angle)); |
| Bobymicjohn | 11:676ea42afd56 | 47 | m_pwm.pulsewidth(m_pulseWidth); |
| Bobymicjohn | 11:676ea42afd56 | 48 | } |
| Bobymicjohn | 11:676ea42afd56 | 49 | |
| Bobymicjohn | 11:676ea42afd56 | 50 | void Servo::turnLeft(float angle) |
| Bobymicjohn | 11:676ea42afd56 | 51 | { |
| Bobymicjohn | 11:676ea42afd56 | 52 | if(angle > 21) |
| Bobymicjohn | 11:676ea42afd56 | 53 | angle = 21; |
| Bobymicjohn | 11:676ea42afd56 | 54 | |
| Bobymicjohn | 11:676ea42afd56 | 55 | m_pulseWidth = (0.0015 - (0.00017 * angle)); |
| Bobymicjohn | 11:676ea42afd56 | 56 | m_pwm.pulsewidth(m_pulseWidth); |
| Bobymicjohn | 11:676ea42afd56 | 57 | } |
| Bobymicjohn | 11:676ea42afd56 | 58 | */ |
