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 21:04:10 2017 +0000
Revision:
100:ffbeefc9e218
Parent:
86:51048c1f132f
Better version of Intersection detection.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hazheng 86:51048c1f132f 1 /**
hazheng 86:51048c1f132f 2 * @file RunningState.h
hazheng 86:51048c1f132f 3 * @brief The header file for the RunningState class.
hazheng 86:51048c1f132f 4 * @author Jordan Brack <jabrack@mix.wvu.edu>, Haofan Zheng <hazheng@mix.wvu.edu>
hazheng 86:51048c1f132f 5 *
hazheng 86:51048c1f132f 6 */
hazheng 80:c85cb93713b3 7 #pragma once
hazheng 80:c85cb93713b3 8 #ifndef RUNNING_STATE_H
hazheng 80:c85cb93713b3 9 #define RUNNING_STATE_H
hazheng 80:c85cb93713b3 10
hazheng 80:c85cb93713b3 11 #include <mbed.h>
hazheng 80:c85cb93713b3 12 #include "States.h"
hazheng 80:c85cb93713b3 13
hazheng 86:51048c1f132f 14 /**
hazheng 86:51048c1f132f 15 * @class RunningState
hazheng 86:51048c1f132f 16 * @brief The class for running state. It is a child class of the States class.
hazheng 86:51048c1f132f 17 *
hazheng 86:51048c1f132f 18 */
hazheng 80:c85cb93713b3 19 class RunningState : public States
hazheng 80:c85cb93713b3 20 {
hazheng 80:c85cb93713b3 21 public:
hazheng 86:51048c1f132f 22 /**
hazheng 86:51048c1f132f 23 * @brief This is the constructor for the RunningState class
hazheng 86:51048c1f132f 24 *
hazheng 86:51048c1f132f 25 */
hazheng 80:c85cb93713b3 26 RunningState();
hazheng 86:51048c1f132f 27 /**
hazheng 86:51048c1f132f 28 * @brief This is the destructor for the RunningState class
hazheng 86:51048c1f132f 29 *
hazheng 86:51048c1f132f 30 */
hazheng 80:c85cb93713b3 31 ~RunningState();
hazheng 80:c85cb93713b3 32
hazheng 86:51048c1f132f 33 /**
hazheng 86:51048c1f132f 34 * @brief Draw the user interface. This function is called only once, whenever the running state becomes the current state.
hazheng 86:51048c1f132f 35 *
hazheng 86:51048c1f132f 36 */
hazheng 80:c85cb93713b3 37 virtual void DrawUserInterface();
hazheng 80:c85cb93713b3 38
hazheng 86:51048c1f132f 39 /**
hazheng 86:51048c1f132f 40 * @brief This functino will be called during every tick, only if the running state is the current state. The image processing, path selection, and driving decision will run from here.
hazheng 86:51048c1f132f 41 * @param deltaTime The time interval between last tick and current tick.
hazheng 86:51048c1f132f 42 *
hazheng 86:51048c1f132f 43 */
hazheng 80:c85cb93713b3 44 virtual void Update(float deltaTime);
hazheng 80:c85cb93713b3 45
hazheng 86:51048c1f132f 46 /**
hazheng 86:51048c1f132f 47 * @brief Return wether or not the running state has a position callback function for the touch screen.
hazheng 86:51048c1f132f 48 * @return 0 - not. Because the running state does not have a position callback function for the touch screen.
hazheng 86:51048c1f132f 49 *
hazheng 86:51048c1f132f 50 */
hazheng 80:c85cb93713b3 51 virtual uint8_t HasTouchPosFunction() const;
hazheng 80:c85cb93713b3 52
hazheng 86:51048c1f132f 53 /**
hazheng 86:51048c1f132f 54 * @brief Return wether or not the running state has a interrupt callback function for the touch screen.
hazheng 86:51048c1f132f 55 * @return 1 - yes. Because the running state does have a interrupt callback function for the touch screen.
hazheng 86:51048c1f132f 56 *
hazheng 86:51048c1f132f 57 */
hazheng 80:c85cb93713b3 58 virtual uint8_t HasTouchIrqFunction() const;
hazheng 80:c85cb93713b3 59
hazheng 86:51048c1f132f 60 /**
hazheng 86:51048c1f132f 61 * @brief The interrupt callback function for the touch screen.
hazheng 86:51048c1f132f 62 *
hazheng 86:51048c1f132f 63 */
hazheng 80:c85cb93713b3 64 virtual void TouchIrqCallback();
hazheng 80:c85cb93713b3 65
hazheng 80:c85cb93713b3 66 private:
hazheng 80:c85cb93713b3 67
hazheng 86:51048c1f132f 68 float m_speedRatio; /*!< @brief The percentage of the speed(power) that the motor driver need to maintain during a curve. */
hazheng 86:51048c1f132f 69 float m_lastAngle; /*!< @brief The final calculated turn angle from last tick. */
hazheng 86:51048c1f132f 70 float m_lastAngleAbs; /*!< @brief The final calculated turn angle from last tick, in absolute value. */
hazheng 86:51048c1f132f 71 float m_cornerRatio; /*!< @brief The percentage of the speed(power) that the motor driver need to maintain when enter/exit a curve. */
hazheng 86:51048c1f132f 72 //uint8_t m_lastLineFound; /*!< @brief */
hazheng 86:51048c1f132f 73 volatile uint8_t m_shouldTerminate; /*!< @brief Did running state received a pendding Terminating command? */
hazheng 80:c85cb93713b3 74
hazheng 86:51048c1f132f 75 /**
hazheng 86:51048c1f132f 76 * @brief The terminating process. Called when it is necessary to terminate the runnning state. And it will switch to the standby state.
hazheng 86:51048c1f132f 77 *
hazheng 86:51048c1f132f 78 */
hazheng 80:c85cb93713b3 79 void TerminateProcess();
hazheng 80:c85cb93713b3 80 };
hazheng 80:c85cb93713b3 81
hazheng 80:c85cb93713b3 82 #endif //RUNNING_STATE_H