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

Revision:
15:eb6a274b3dfb
Child:
21:60377d6f1cc2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Hardwares/WheelEncoder.cpp	Tue Feb 14 19:51:57 2017 +0000
@@ -0,0 +1,52 @@
+#include "WheelEncoder.h"
+#include "Core.h"
+#include "SWUSBServer.h"
+
+#include "PinAssignment.h"
+#include "SWUSBServer.h"
+
+#include "mbed.h"
+
+
+WheelEncoder::WheelEncoder(SW::Core& core) :
+    m_core(core),
+    m_intRL(InterruptIn(PIN_WE_RL)),
+    m_intRR(InterruptIn(PIN_WE_RR))
+{
+    m_rrightTimer.start();
+    m_rleftTimer.start();
+    m_intRL.rise(callback(this, &WheelEncoder::pulseInRLeft));
+    m_intRR.rise(callback(this, &WheelEncoder::pulseInRRight));
+     
+}
+
+
+void WheelEncoder::Update(float deltaTime)
+{
+    int rrHz = 1 / m_rrDuration;
+    int rlHz = 1 / m_rlDuration;
+    
+    char buf[5];
+    sprintf(buf, "RR: %d", rrHz);
+    m_core.GetUSBServer().PushUnreliableMsg('D', buf);
+    sprintf(buf, "RL: %d", rlHz);
+    m_core.GetUSBServer().PushUnreliableMsg('D', buf);
+}
+
+void WheelEncoder::pulseInRRight()
+{
+    m_rrDuration = m_rrightTimer.read();
+    m_rrightTimer.stop();
+    m_rrightTimer.reset();
+    m_rrightTimer.start();
+}
+    
+void WheelEncoder::pulseInRLeft()
+{
+    m_rlDuration = m_rleftTimer.read();
+    m_rleftTimer.stop();
+    m_rleftTimer.reset();
+    m_rleftTimer.start();
+}
+    
+    
\ No newline at end of file