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:
hazheng
Date:
Thu Apr 20 21:04:10 2017 +0000
Revision:
100:ffbeefc9e218
Parent:
87:15fcf7891bf9
Better version of Intersection detection.

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 "PinAssignment.h"
hazheng 46:a5eb9bd3bb55 4 #include "GlobalVariable.h"
Bobymicjohn 11:676ea42afd56 5
Bobymicjohn 11:676ea42afd56 6 #include "mbed.h"
Bobymicjohn 11:676ea42afd56 7
hazheng 45:501b7909139a 8 #ifdef __cplusplus
hazheng 45:501b7909139a 9 extern "C" {
hazheng 45:501b7909139a 10 #endif
Bobymicjohn 11:676ea42afd56 11
hazheng 45:501b7909139a 12 static float servo_pulseWidth = 0.0015;
hazheng 45:501b7909139a 13 static PwmOut servo_pwm(PIN_SC_SERVO);
hazheng 45:501b7909139a 14
hazheng 45:501b7909139a 15 void servo_init()
hazheng 45:501b7909139a 16 {
hazheng 45:501b7909139a 17 servo_pwm.period(0.020);
hazheng 45:501b7909139a 18 servo_pwm.pulsewidth(servo_pulseWidth);
hazheng 45:501b7909139a 19 }
hazheng 45:501b7909139a 20
hazheng 45:501b7909139a 21 void servo_set_angle(float angle)
hazheng 45:501b7909139a 22 {
hazheng 45:501b7909139a 23 if(angle > SERVO_RT * SERVO_MAX_ANGLE)
hazheng 45:501b7909139a 24 angle = SERVO_RT * SERVO_MAX_ANGLE;
hazheng 45:501b7909139a 25 else if(angle < SERVO_LF * SERVO_MAX_ANGLE)
hazheng 45:501b7909139a 26 angle = SERVO_LF * SERVO_MAX_ANGLE;
hazheng 45:501b7909139a 27
hazheng 45:501b7909139a 28 servo_pulseWidth = (0.0015 + (0.00001667 * angle));
hazheng 45:501b7909139a 29 servo_pwm.pulsewidth(servo_pulseWidth);
hazheng 46:a5eb9bd3bb55 30 //servo_pwm = (servo_pulseWidth / 0.020);
hazheng 46:a5eb9bd3bb55 31
hazheng 46:a5eb9bd3bb55 32 //char buf[20];
hazheng 46:a5eb9bd3bb55 33 //sprintf(buf, "Serv %f", (float)servo_pwm);
hazheng 46:a5eb9bd3bb55 34 //g_core.GetUSBServer().PushUnreliableMsg('D', buf);
hazheng 45:501b7909139a 35 }
hazheng 45:501b7909139a 36
hazheng 45:501b7909139a 37 #ifdef __cplusplus
hazheng 45:501b7909139a 38 }
hazheng 45:501b7909139a 39 #endif