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:
Wed Apr 12 22:16:40 2017 +0000
Revision:
65:295c222fdf88
Parent:
54:f1f5648dfacf
More Adjustment.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hazheng 65:295c222fdf88 1 #if 0
hazheng 65:295c222fdf88 2
Bobymicjohn 15:eb6a274b3dfb 3 #include "WheelEncoder.h"
Bobymicjohn 15:eb6a274b3dfb 4 #include "Core.h"
Bobymicjohn 15:eb6a274b3dfb 5 #include "SWUSBServer.h"
Bobymicjohn 15:eb6a274b3dfb 6
Bobymicjohn 15:eb6a274b3dfb 7 #include "PinAssignment.h"
Bobymicjohn 15:eb6a274b3dfb 8 #include "SWUSBServer.h"
Bobymicjohn 15:eb6a274b3dfb 9
Bobymicjohn 15:eb6a274b3dfb 10 #include "mbed.h"
Bobymicjohn 15:eb6a274b3dfb 11
Bobymicjohn 15:eb6a274b3dfb 12
Bobymicjohn 15:eb6a274b3dfb 13 WheelEncoder::WheelEncoder(SW::Core& core) :
Bobymicjohn 15:eb6a274b3dfb 14 m_core(core),
Bobymicjohn 15:eb6a274b3dfb 15 m_intRL(InterruptIn(PIN_WE_RL)),
Bobymicjohn 21:60377d6f1cc2 16 m_intRR(InterruptIn(PIN_WE_RR)),
Bobymicjohn 21:60377d6f1cc2 17 m_rrDuration(1.0f),
Bobymicjohn 21:60377d6f1cc2 18 m_rlDuration(1.0f)
Bobymicjohn 15:eb6a274b3dfb 19 {
Bobymicjohn 15:eb6a274b3dfb 20 m_rrightTimer.start();
Bobymicjohn 15:eb6a274b3dfb 21 m_rleftTimer.start();
Bobymicjohn 15:eb6a274b3dfb 22 m_intRL.rise(callback(this, &WheelEncoder::pulseInRLeft));
Bobymicjohn 15:eb6a274b3dfb 23 m_intRR.rise(callback(this, &WheelEncoder::pulseInRRight));
Bobymicjohn 15:eb6a274b3dfb 24
Bobymicjohn 15:eb6a274b3dfb 25 }
Bobymicjohn 15:eb6a274b3dfb 26
Bobymicjohn 15:eb6a274b3dfb 27
Bobymicjohn 15:eb6a274b3dfb 28 void WheelEncoder::Update(float deltaTime)
Bobymicjohn 15:eb6a274b3dfb 29 {
Bobymicjohn 54:f1f5648dfacf 30 //int rrHz = 1 / m_rrDuration;
Bobymicjohn 54:f1f5648dfacf 31 //int rlHz = 1 / m_rlDuration;
Bobymicjohn 15:eb6a274b3dfb 32
Bobymicjohn 54:f1f5648dfacf 33 ///char buf[5];
Bobymicjohn 54:f1f5648dfacf 34 //sprintf(buf, "RR: %d", rrHz);
Bobymicjohn 54:f1f5648dfacf 35 ///m_core.GetUSBServer().PushUnreliableMsg('D', buf);
Bobymicjohn 54:f1f5648dfacf 36 //sprintf(buf, "RL: %d", rlHz);
Bobymicjohn 54:f1f5648dfacf 37 //m_core.GetUSBServer().PushUnreliableMsg('D', buf);
Bobymicjohn 15:eb6a274b3dfb 38 }
Bobymicjohn 15:eb6a274b3dfb 39
Bobymicjohn 15:eb6a274b3dfb 40 void WheelEncoder::pulseInRRight()
Bobymicjohn 15:eb6a274b3dfb 41 {
Bobymicjohn 15:eb6a274b3dfb 42 m_rrDuration = m_rrightTimer.read();
Bobymicjohn 15:eb6a274b3dfb 43 m_rrightTimer.stop();
Bobymicjohn 15:eb6a274b3dfb 44 m_rrightTimer.reset();
Bobymicjohn 15:eb6a274b3dfb 45 m_rrightTimer.start();
Bobymicjohn 15:eb6a274b3dfb 46 }
Bobymicjohn 15:eb6a274b3dfb 47
Bobymicjohn 15:eb6a274b3dfb 48 void WheelEncoder::pulseInRLeft()
Bobymicjohn 15:eb6a274b3dfb 49 {
Bobymicjohn 15:eb6a274b3dfb 50 m_rlDuration = m_rleftTimer.read();
Bobymicjohn 15:eb6a274b3dfb 51 m_rleftTimer.stop();
Bobymicjohn 15:eb6a274b3dfb 52 m_rleftTimer.reset();
Bobymicjohn 15:eb6a274b3dfb 53 m_rleftTimer.start();
Bobymicjohn 15:eb6a274b3dfb 54 }
Bobymicjohn 15:eb6a274b3dfb 55
hazheng 65:295c222fdf88 56 #endif //if 0