SmartWheels self-driving race car. Designed for NXP Cup. Uses FRDM-KL25Z, area-scan camera, and simple image processing to detect and navigate any NXP spec track.
Dependencies: TSI USBDevice mbed-dev
Fork of SmartWheels by
Hardwares/Servo.cpp@11:676ea42afd56, 2017-02-07 (annotated)
- Committer:
- Bobymicjohn
- Date:
- Tue Feb 07 21:58:20 2017 +0000
- Revision:
- 11:676ea42afd56
- Child:
- 13:7dcb1642ef99
Finished Core, and Servo classes.
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), |
Bobymicjohn | 11:676ea42afd56 | 12 | m_pwm(PwmOut(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 | */ |