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 Mar 30 22:34:20 2017 +0000
Revision:
46:a5eb9bd3bb55
Parent:
45:501b7909139a
Child:
87:15fcf7891bf9
Changed more code into pure C style. Finished driving complete circle! Both screen and camera works fine!

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