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@14:88302da8bff0, 2017-02-09 (annotated)
- Committer:
- Bobymicjohn
- Date:
- Thu Feb 09 20:01:43 2017 +0000
- Revision:
- 14:88302da8bff0
- Parent:
- 13:7dcb1642ef99
- Child:
- 20:4cdbd1ae4ead
Small servo tweaks
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 | } |