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 16:18:45 2017 +0000
Revision:
98:fc92bb37ee17
Parent:
94:32712e603a5f
Added intersection detection (not working yet)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hazheng 94:32712e603a5f 1 /**
hazheng 94:32712e603a5f 2 * @file SWCommon.h
hazheng 94:32712e603a5f 3 * @brief The header file for Smart Wheels Common functions. Note: The functions in here will be only used in debug purpose, and all of these debug functions will not be included for the release version.
hazheng 94:32712e603a5f 4 * @author Jordan Brack <jabrack@mix.wvu.edu>, Haofan Zheng <hazheng@mix.wvu.edu>
hazheng 94:32712e603a5f 5 *
hazheng 94:32712e603a5f 6 */
hazheng 56:7d3395ae022d 7 #pragma once
hazheng 56:7d3395ae022d 8 #ifndef SW_COMMON_H
hazheng 56:7d3395ae022d 9 #define SW_COMMON_H
hazheng 56:7d3395ae022d 10
hazheng 56:7d3395ae022d 11 #include "ArduUTFT.h"
hazheng 57:0d8a155d511d 12 #include <mbed.h>
hazheng 56:7d3395ae022d 13
hazheng 56:7d3395ae022d 14 #ifdef SW_DEBUG
hazheng 98:fc92bb37ee17 15 #define LOGI(...) char sw_common_buf_v87t790[100];\
hazheng 62:bc5caf59fe39 16 sprintf(sw_common_buf_v87t790, __VA_ARGS__);\
hazheng 62:bc5caf59fe39 17 ardu_utft_print(sw_common_buf_v87t790, 230, 100);
hazheng 56:7d3395ae022d 18
hazheng 94:32712e603a5f 19 #else //SW_DEBUG
hazheng 98:fc92bb37ee17 20 #define LOGI(...)
hazheng 94:32712e603a5f 21
hazheng 94:32712e603a5f 22 #endif //SW_DEBUG
hazheng 56:7d3395ae022d 23
hazheng 94:32712e603a5f 24 #ifdef SW_DEBUGCOUNTER
hazheng 56:7d3395ae022d 25
hazheng 94:32712e603a5f 26 /**
hazheng 94:32712e603a5f 27 * @class DebugCounter
hazheng 94:32712e603a5f 28 * @brief This class will be used as a counter during debugging. This class can be used when estimating the running speed of the system, or some specific function.
hazheng 94:32712e603a5f 29 */
hazheng 57:0d8a155d511d 30 class DebugCounter
hazheng 57:0d8a155d511d 31 {
hazheng 57:0d8a155d511d 32 public:
hazheng 94:32712e603a5f 33 /**
hazheng 94:32712e603a5f 34 * @brief The constructor for the DebugCounter class.
hazheng 94:32712e603a5f 35 * @param maxCount The number of counts that should be accumulated before changing the output pin status.
hazheng 94:32712e603a5f 36 * @param pin The read address for the slave device.
hazheng 94:32712e603a5f 37 */
hazheng 57:0d8a155d511d 38 DebugCounter(uint16_t maxCount, PinName pin) :
hazheng 57:0d8a155d511d 39 m_output(DigitalOut(pin, 0)),
hazheng 57:0d8a155d511d 40 m_maxCount(maxCount),
hazheng 57:0d8a155d511d 41 m_counter(0)
hazheng 57:0d8a155d511d 42 {
hazheng 57:0d8a155d511d 43
hazheng 57:0d8a155d511d 44 }
hazheng 57:0d8a155d511d 45
hazheng 94:32712e603a5f 46 /**
hazheng 94:32712e603a5f 47 * @brief The update function, where the counter gets count. If the number of counts approached the max count, the output pin status will be flipped.
hazheng 94:32712e603a5f 48 */
hazheng 57:0d8a155d511d 49 void Update()
hazheng 57:0d8a155d511d 50 {
hazheng 57:0d8a155d511d 51 ++m_counter;
hazheng 57:0d8a155d511d 52 if(m_counter >= m_maxCount)
hazheng 57:0d8a155d511d 53 {
hazheng 57:0d8a155d511d 54 m_output.write(!(m_output.read()));
hazheng 57:0d8a155d511d 55 m_counter = 0;
hazheng 57:0d8a155d511d 56 }
hazheng 57:0d8a155d511d 57 }
hazheng 57:0d8a155d511d 58
hazheng 57:0d8a155d511d 59
hazheng 57:0d8a155d511d 60 private:
hazheng 94:32712e603a5f 61 DigitalOut m_output; /*!< @brief The output pin. */
hazheng 94:32712e603a5f 62 const uint16_t m_maxCount; /*!< @brief The max count. */
hazheng 94:32712e603a5f 63 uint16_t m_counter; /*!< @brief The counter. */
hazheng 57:0d8a155d511d 64
hazheng 57:0d8a155d511d 65 };
hazheng 94:32712e603a5f 66 #endif //SW_DEBUGCOUNTER
hazheng 57:0d8a155d511d 67
hazheng 57:0d8a155d511d 68
hazheng 56:7d3395ae022d 69 #endif //SW_COMMON_H