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 haofan Zheng

Committer:
Bobymicjohn
Date:
Tue Feb 14 19:55:04 2017 +0000
Revision:
20:4cdbd1ae4ead
Parent:
16:66c7a09e71ee
Parent:
14:88302da8bff0
Child:
45:501b7909139a
Merged origin/default to default.

Who changed what in which revision?

UserRevisionLine numberNew 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));
hazheng 16:66c7a09e71ee 34 //char buf[10];
hazheng 16:66c7a09e71ee 35 //sprintf(buf, "%f", m_pulseWidth);
hazheng 16:66c7a09e71ee 36 //m_core.GetUSBServer().PushUnreliableMsg('D', buf);
Bobymicjohn 11:676ea42afd56 37 m_pwm.pulsewidth(m_pulseWidth);
Bobymicjohn 11:676ea42afd56 38 }