official library and example code for tracking X and Y positions on the dump truck

Dependencies:   QEI mbed

Dependents:   DUMP_TRUCK_TEST_V1 DUMP_TRUCK_SPR2017

Committer:
simplyellow
Date:
Tue Feb 14 21:04:20 2017 +0000
Revision:
5:757a984ac553
Parent:
0:8038ea3ee241
Child:
6:50f337affc44
added doxygen tags

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simplyellow 5:757a984ac553 1 /**
simplyellow 5:757a984ac553 2 * @file Tracker.h
simplyellow 5:757a984ac553 3 *
simplyellow 5:757a984ac553 4 * @brief Tracker class implements API for sensing the position of the
simplyellow 5:757a984ac553 5 * dump truck.
simplyellow 5:757a984ac553 6 *
simplyellow 5:757a984ac553 7 * @author Terrabots Team
simplyellow 5:757a984ac553 8 *
simplyellow 5:757a984ac553 9 */
simplyellow 5:757a984ac553 10
simplyellow 0:8038ea3ee241 11 #ifndef TRACKER_H
simplyellow 0:8038ea3ee241 12 #define TRACKER_H
simplyellow 0:8038ea3ee241 13
simplyellow 0:8038ea3ee241 14 #include "mbed.h"
simplyellow 0:8038ea3ee241 15 #include "QEI.h"
simplyellow 0:8038ea3ee241 16
simplyellow 5:757a984ac553 17 /**
simplyellow 5:757a984ac553 18 * @class Tracker
simplyellow 5:757a984ac553 19 *
simplyellow 5:757a984ac553 20 * @brief Interface for tracking the position of a Dump Truck configured
simplyellow 5:757a984ac553 21 * "robot."
simplyellow 5:757a984ac553 22 */
simplyellow 5:757a984ac553 23
simplyellow 0:8038ea3ee241 24 #define STRAIGHT 0
simplyellow 0:8038ea3ee241 25 #define CCW 1
simplyellow 0:8038ea3ee241 26 #define CW 2
simplyellow 0:8038ea3ee241 27 #define PI 3.14159265
simplyellow 0:8038ea3ee241 28
simplyellow 0:8038ea3ee241 29 class Tracker {
simplyellow 0:8038ea3ee241 30 public:
simplyellow 5:757a984ac553 31 /**
simplyellow 5:757a984ac553 32 * Constructor for the Tracker object.
simplyellow 5:757a984ac553 33 *
simplyellow 5:757a984ac553 34 * @param[in] _chA The interrupt pin used for channel A
simplyellow 5:757a984ac553 35 * @param[in] _chB The interrupt pin used for channel B
simplyellow 5:757a984ac553 36 * @param[in] _pot The AnalogIn pin used for the potentiometer
simplyellow 5:757a984ac553 37 */
simplyellow 0:8038ea3ee241 38 Tracker(PinName _chA, PinName _chB, PinName _pot);
simplyellow 5:757a984ac553 39 /**
simplyellow 5:757a984ac553 40 * Set initial position and distance traveled to 0.
simplyellow 5:757a984ac553 41 */
simplyellow 0:8038ea3ee241 42 void clear();
simplyellow 5:757a984ac553 43 /**
simplyellow 5:757a984ac553 44 * Set a reference "zero angle" for the potentiometer and wait five
simplyellow 5:757a984ac553 45 * seconds for the user to set a turning angle.
simplyellow 5:757a984ac553 46 */
simplyellow 0:8038ea3ee241 47 void potSetup();
simplyellow 5:757a984ac553 48 /**
simplyellow 5:757a984ac553 49 * Set a direction, either clockwise or counterclockwise, for the
simplyellow 5:757a984ac553 50 * dump truck, based on the turning angle.
simplyellow 5:757a984ac553 51 */
simplyellow 0:8038ea3ee241 52 void setDirection();
simplyellow 5:757a984ac553 53 /**
simplyellow 5:757a984ac553 54 * Check if the dump truck has moved before starting position-tracking
simplyellow 5:757a984ac553 55 * calculations.
simplyellow 5:757a984ac553 56 */
simplyellow 0:8038ea3ee241 57 void checkToStart();
simplyellow 5:757a984ac553 58 /**
simplyellow 5:757a984ac553 59 * Calculate the x and y position of the dump truck based on sensor
simplyellow 5:757a984ac553 60 * measurements.
simplyellow 5:757a984ac553 61 */
simplyellow 0:8038ea3ee241 62 void calcDisplacement();
simplyellow 0:8038ea3ee241 63 private:
simplyellow 0:8038ea3ee241 64 QEI *wheel;
simplyellow 0:8038ea3ee241 65 PinName chA;
simplyellow 0:8038ea3ee241 66 PinName chB;
simplyellow 0:8038ea3ee241 67 AnalogIn pot;
simplyellow 0:8038ea3ee241 68 float pulseCount;
simplyellow 0:8038ea3ee241 69 float encoding;
simplyellow 0:8038ea3ee241 70 float circumference;
simplyellow 0:8038ea3ee241 71 float constant;
simplyellow 0:8038ea3ee241 72
simplyellow 0:8038ea3ee241 73 float distance;
simplyellow 0:8038ea3ee241 74
simplyellow 0:8038ea3ee241 75 float x;
simplyellow 0:8038ea3ee241 76 float y;
simplyellow 0:8038ea3ee241 77
simplyellow 0:8038ea3ee241 78 float value;
simplyellow 0:8038ea3ee241 79 float turnAngle;
simplyellow 0:8038ea3ee241 80 float zeroAngle;
simplyellow 0:8038ea3ee241 81
simplyellow 0:8038ea3ee241 82 int dir;
simplyellow 0:8038ea3ee241 83
simplyellow 0:8038ea3ee241 84 float df;
simplyellow 0:8038ea3ee241 85 float db;
simplyellow 0:8038ea3ee241 86 float W;
simplyellow 0:8038ea3ee241 87 float R;
simplyellow 0:8038ea3ee241 88 float dispAngle;
simplyellow 0:8038ea3ee241 89
simplyellow 0:8038ea3ee241 90 };
simplyellow 0:8038ea3ee241 91 #endif