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

Hardwares/WheelEncoder.cpp

Committer:
Bobymicjohn
Date:
2017-04-06
Revision:
54:f1f5648dfacf
Parent:
21:60377d6f1cc2
Child:
65:295c222fdf88

File content as of revision 54:f1f5648dfacf:

#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_rrDuration(1.0f),
    m_rlDuration(1.0f)
{
    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();
}