Copy_Assignment3
Dependencies: mbed MCP23017 WattBob_TextLCD mbed-rtos
include/my_structures.h@0:8940db3353d7, 2018-03-28 (annotated)
- Committer:
- aoc2
- Date:
- Wed Mar 28 18:51:55 2018 +0000
- Revision:
- 0:8940db3353d7
Copy of Assig 3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aoc2 | 0:8940db3353d7 | 1 | #pragma once |
aoc2 | 0:8940db3353d7 | 2 | |
aoc2 | 0:8940db3353d7 | 3 | /******************************************************************************* |
aoc2 | 0:8940db3353d7 | 4 | * CUSTOM PARAMETERS DECLARATION |
aoc2 | 0:8940db3353d7 | 5 | ******************************************************************************/ |
aoc2 | 0:8940db3353d7 | 6 | #ifndef CONSTANTS_OF_CAR |
aoc2 | 0:8940db3353d7 | 7 | #define MAX_SPEED 230 // km/h |
aoc2 | 0:8940db3353d7 | 8 | |
aoc2 | 0:8940db3353d7 | 9 | #define SIZE_SPEED_VECTOR 10 |
aoc2 | 0:8940db3353d7 | 10 | #define SIZE_AVG_SPEED 3 |
aoc2 | 0:8940db3353d7 | 11 | |
aoc2 | 0:8940db3353d7 | 12 | #define ON 1 |
aoc2 | 0:8940db3353d7 | 13 | #define OFF 0 |
aoc2 | 0:8940db3353d7 | 14 | |
aoc2 | 0:8940db3353d7 | 15 | #endif /*! CONSTANTS_OF_CAR */ |
aoc2 | 0:8940db3353d7 | 16 | |
aoc2 | 0:8940db3353d7 | 17 | |
aoc2 | 0:8940db3353d7 | 18 | /******************************************************************************* |
aoc2 | 0:8940db3353d7 | 19 | * STRUCTURES DECLARATION |
aoc2 | 0:8940db3353d7 | 20 | ******************************************************************************/ |
aoc2 | 0:8940db3353d7 | 21 | #ifndef __MY__STRUCTURES_H__ |
aoc2 | 0:8940db3353d7 | 22 | #define __MY__STRUCTURES_H__ |
aoc2 | 0:8940db3353d7 | 23 | |
aoc2 | 0:8940db3353d7 | 24 | #include <vector> |
aoc2 | 0:8940db3353d7 | 25 | #include "mbed.h" |
aoc2 | 0:8940db3353d7 | 26 | #include "rtos.h" |
aoc2 | 0:8940db3353d7 | 27 | #include "MCP23017.h" |
aoc2 | 0:8940db3353d7 | 28 | #include "WattBob_TextLCD.h" |
aoc2 | 0:8940db3353d7 | 29 | |
aoc2 | 0:8940db3353d7 | 30 | |
aoc2 | 0:8940db3353d7 | 31 | /** This structure is used to store the RAW engine values |
aoc2 | 0:8940db3353d7 | 32 | * |
aoc2 | 0:8940db3353d7 | 33 | * @param: engineState [bool] |
aoc2 | 0:8940db3353d7 | 34 | * State on the engine, on or off |
aoc2 | 0:8940db3353d7 | 35 | * @param: acceleratorValue [float] |
aoc2 | 0:8940db3353d7 | 36 | * Last value got by TASK 1. From 0 to 1, % of acceleration |
aoc2 | 0:8940db3353d7 | 37 | * @param: brakeValue [float] |
aoc2 | 0:8940db3353d7 | 38 | * Last value got by TASK 1. From 0 to 1, % of brake |
aoc2 | 0:8940db3353d7 | 39 | */ |
aoc2 | 0:8940db3353d7 | 40 | struct engineRAWValues{ |
aoc2 | 0:8940db3353d7 | 41 | bool engineState; |
aoc2 | 0:8940db3353d7 | 42 | float acceleratorValue; |
aoc2 | 0:8940db3353d7 | 43 | float brakeValue; |
aoc2 | 0:8940db3353d7 | 44 | }; |
aoc2 | 0:8940db3353d7 | 45 | |
aoc2 | 0:8940db3353d7 | 46 | /** This structure is used to store the speed and travelled distance of the car |
aoc2 | 0:8940db3353d7 | 47 | * |
aoc2 | 0:8940db3353d7 | 48 | * @param: *p_speedVector [std::vector<float>] |
aoc2 | 0:8940db3353d7 | 49 | * Vector used to store the last speed values computed by the simulator |
aoc2 | 0:8940db3353d7 | 50 | * Speed is in m/s. |
aoc2 | 0:8940db3353d7 | 51 | * @param: sizeOfAvg [int] |
aoc2 | 0:8940db3353d7 | 52 | * Size of the averaging filter used to compute the displayed speed |
aoc2 | 0:8940db3353d7 | 53 | * value. The average is computed by taking the last sizeOfAvg values |
aoc2 | 0:8940db3353d7 | 54 | * of the vector p_speedVector. |
aoc2 | 0:8940db3353d7 | 55 | * @param: averageSpeed [float] |
aoc2 | 0:8940db3353d7 | 56 | * Last value computed by task 3. In m/s |
aoc2 | 0:8940db3353d7 | 57 | * @param: distance [float] |
aoc2 | 0:8940db3353d7 | 58 | * Distance travelled by the car, in m. |
aoc2 | 0:8940db3353d7 | 59 | */ |
aoc2 | 0:8940db3353d7 | 60 | struct carStatistics{ |
aoc2 | 0:8940db3353d7 | 61 | // Speed Vector |
aoc2 | 0:8940db3353d7 | 62 | std::vector<float> *p_speedVector; |
aoc2 | 0:8940db3353d7 | 63 | int sizeOfAvg; |
aoc2 | 0:8940db3353d7 | 64 | float averageSpeed; |
aoc2 | 0:8940db3353d7 | 65 | // Distance |
aoc2 | 0:8940db3353d7 | 66 | float distance; |
aoc2 | 0:8940db3353d7 | 67 | }; |
aoc2 | 0:8940db3353d7 | 68 | |
aoc2 | 0:8940db3353d7 | 69 | /** This structure is used by the MAIL Queue object to store information to be |
aoc2 | 0:8940db3353d7 | 70 | * sent to the computer. |
aoc2 | 0:8940db3353d7 | 71 | * |
aoc2 | 0:8940db3353d7 | 72 | * @param: avgSpeed [float] |
aoc2 | 0:8940db3353d7 | 73 | * Last value of average speed computed |
aoc2 | 0:8940db3353d7 | 74 | * @param: accelerator [float] |
aoc2 | 0:8940db3353d7 | 75 | * Last RAW value of accelerator. From 0 to 1. |
aoc2 | 0:8940db3353d7 | 76 | * @param: brake [float] |
aoc2 | 0:8940db3353d7 | 77 | * Last RAW value of brake. From 0 to 1. |
aoc2 | 0:8940db3353d7 | 78 | */ |
aoc2 | 0:8940db3353d7 | 79 | struct mailStruct{ |
aoc2 | 0:8940db3353d7 | 80 | float avgSpeed; |
aoc2 | 0:8940db3353d7 | 81 | float accelerator; |
aoc2 | 0:8940db3353d7 | 82 | float brake; |
aoc2 | 0:8940db3353d7 | 83 | }; |
aoc2 | 0:8940db3353d7 | 84 | |
aoc2 | 0:8940db3353d7 | 85 | |
aoc2 | 0:8940db3353d7 | 86 | /** This structure is the main structure used by the program in order not to |
aoc2 | 0:8940db3353d7 | 87 | * use global variables. It is given as argument to every function used |
aoc2 | 0:8940db3353d7 | 88 | * in the different RTOSTimer. |
aoc2 | 0:8940db3353d7 | 89 | * |
aoc2 | 0:8940db3353d7 | 90 | * @param: System Inputs [AnalogIn/DigitalIn] |
aoc2 | 0:8940db3353d7 | 91 | * Set of system inputs used by the system for the assignment. |
aoc2 | 0:8940db3353d7 | 92 | * @param: System Outpus [AnalogOut/DigitalOut] |
aoc2 | 0:8940db3353d7 | 93 | * Set of system outputs used by the system for the assignment. |
aoc2 | 0:8940db3353d7 | 94 | * |
aoc2 | 0:8940db3353d7 | 95 | * @param: Structures [engineRAWValues/carStatistics] |
aoc2 | 0:8940db3353d7 | 96 | * Two smaller structures used to organized values used by the |
aoc2 | 0:8940db3353d7 | 97 | * different tasks of the assigment. |
aoc2 | 0:8940db3353d7 | 98 | * |
aoc2 | 0:8940db3353d7 | 99 | * @param: *p_mailQueue |
aoc2 | 0:8940db3353d7 | 100 | * Mail Queue object, from "rtos.h". It uses a mailStruct structure |
aoc2 | 0:8940db3353d7 | 101 | * to store information. |
aoc2 | 0:8940db3353d7 | 102 | * @param: nbElementInQueue [int] |
aoc2 | 0:8940db3353d7 | 103 | * Number of element in the queue. Necessary in order to dump the mail |
aoc2 | 0:8940db3353d7 | 104 | * by another task and because there is no method to get the number |
aoc2 | 0:8940db3353d7 | 105 | * of element stored in the mail queue. |
aoc2 | 0:8940db3353d7 | 106 | * |
aoc2 | 0:8940db3353d7 | 107 | * @param: Mutex [Mutex] |
aoc2 | 0:8940db3353d7 | 108 | * Set of three mutex to protect the access of the engineRAWValues |
aoc2 | 0:8940db3353d7 | 109 | * and carStatistics structures, as well as the mail queue object. |
aoc2 | 0:8940db3353d7 | 110 | * |
aoc2 | 0:8940db3353d7 | 111 | * @param: *p_PC [Serial] |
aoc2 | 0:8940db3353d7 | 112 | * Serial connection to the PC |
aoc2 | 0:8940db3353d7 | 113 | * |
aoc2 | 0:8940db3353d7 | 114 | * @param: Screen Variables [MCP23017/WattBob_TextLCD] |
aoc2 | 0:8940db3353d7 | 115 | * Used to access the screen of the MBED shield. |
aoc2 | 0:8940db3353d7 | 116 | */ |
aoc2 | 0:8940db3353d7 | 117 | struct carStructure{ |
aoc2 | 0:8940db3353d7 | 118 | // System Inputs |
aoc2 | 0:8940db3353d7 | 119 | AnalogIn *p_accelerator; |
aoc2 | 0:8940db3353d7 | 120 | AnalogIn *p_brake; |
aoc2 | 0:8940db3353d7 | 121 | DigitalIn *p_engineSwitch; |
aoc2 | 0:8940db3353d7 | 122 | DigitalIn *p_sideLightSwitch; |
aoc2 | 0:8940db3353d7 | 123 | DigitalIn *p_leftSwitch; |
aoc2 | 0:8940db3353d7 | 124 | DigitalIn *p_rightSwitch; |
aoc2 | 0:8940db3353d7 | 125 | |
aoc2 | 0:8940db3353d7 | 126 | // System Outputs |
aoc2 | 0:8940db3353d7 | 127 | DigitalOut *p_sideLightIndicator; |
aoc2 | 0:8940db3353d7 | 128 | PwmOut *p_leftLight; |
aoc2 | 0:8940db3353d7 | 129 | PwmOut *p_rightLight; |
aoc2 | 0:8940db3353d7 | 130 | DigitalOut *p_engineLight; |
aoc2 | 0:8940db3353d7 | 131 | DigitalOut *p_overspeedLight; |
aoc2 | 0:8940db3353d7 | 132 | DigitalOut *p_brakeLight; |
aoc2 | 0:8940db3353d7 | 133 | |
aoc2 | 0:8940db3353d7 | 134 | // RAW Values Structure; |
aoc2 | 0:8940db3353d7 | 135 | engineRAWValues *p_rawValues; |
aoc2 | 0:8940db3353d7 | 136 | |
aoc2 | 0:8940db3353d7 | 137 | // Car Statistics |
aoc2 | 0:8940db3353d7 | 138 | carStatistics *p_carStats; |
aoc2 | 0:8940db3353d7 | 139 | |
aoc2 | 0:8940db3353d7 | 140 | // Mail Structure |
aoc2 | 0:8940db3353d7 | 141 | Mail<mailStruct,100> *p_mailQueue; |
aoc2 | 0:8940db3353d7 | 142 | int nbElementInQueue; |
aoc2 | 0:8940db3353d7 | 143 | |
aoc2 | 0:8940db3353d7 | 144 | // Mutex |
aoc2 | 0:8940db3353d7 | 145 | Mutex *p_rawMutex; |
aoc2 | 0:8940db3353d7 | 146 | Mutex *p_statMutex; |
aoc2 | 0:8940db3353d7 | 147 | Mutex *p_mailMutex; |
aoc2 | 0:8940db3353d7 | 148 | |
aoc2 | 0:8940db3353d7 | 149 | // PC Serial Connection |
aoc2 | 0:8940db3353d7 | 150 | Serial *p_PC; |
aoc2 | 0:8940db3353d7 | 151 | |
aoc2 | 0:8940db3353d7 | 152 | // Screen variables |
aoc2 | 0:8940db3353d7 | 153 | MCP23017 *p_par_port; |
aoc2 | 0:8940db3353d7 | 154 | WattBob_TextLCD *p_lcd; |
aoc2 | 0:8940db3353d7 | 155 | }; |
aoc2 | 0:8940db3353d7 | 156 | |
aoc2 | 0:8940db3353d7 | 157 | /** Initialize a 'engineRAWValues' structure to zero. |
aoc2 | 0:8940db3353d7 | 158 | * |
aoc2 | 0:8940db3353d7 | 159 | * @param: &structVal [engineRAWValues] |
aoc2 | 0:8940db3353d7 | 160 | * Reference to a structure to set all of its values to 0. |
aoc2 | 0:8940db3353d7 | 161 | */ |
aoc2 | 0:8940db3353d7 | 162 | void initRAWValuesStruct(engineRAWValues &structVal); |
aoc2 | 0:8940db3353d7 | 163 | |
aoc2 | 0:8940db3353d7 | 164 | |
aoc2 | 0:8940db3353d7 | 165 | /** Initialize a 'carStatistics' structure to zero and add the given pointer |
aoc2 | 0:8940db3353d7 | 166 | * to a vector to it |
aoc2 | 0:8940db3353d7 | 167 | * |
aoc2 | 0:8940db3353d7 | 168 | * @param: &structStat [carStatistics] |
aoc2 | 0:8940db3353d7 | 169 | * Reference to a structure whose values are set to 0 |
aoc2 | 0:8940db3353d7 | 170 | * @param: *speedVec [std::vector] |
aoc2 | 0:8940db3353d7 | 171 | * Pointer to a vector which is linked to the structure. |
aoc2 | 0:8940db3353d7 | 172 | * Vector used to store the different speed value |
aoc2 | 0:8940db3353d7 | 173 | */ |
aoc2 | 0:8940db3353d7 | 174 | void initCarStatisticsStruct(carStatistics &structStat, |
aoc2 | 0:8940db3353d7 | 175 | std::vector<float> *speedVec |
aoc2 | 0:8940db3353d7 | 176 | ); |
aoc2 | 0:8940db3353d7 | 177 | |
aoc2 | 0:8940db3353d7 | 178 | /** Initialize a 'mailStruct' structure to zero. |
aoc2 | 0:8940db3353d7 | 179 | * |
aoc2 | 0:8940db3353d7 | 180 | * @param: &structMail [mailStruct] |
aoc2 | 0:8940db3353d7 | 181 | * Reference to a structure to set all of its values to 0. |
aoc2 | 0:8940db3353d7 | 182 | */ |
aoc2 | 0:8940db3353d7 | 183 | void initMailStructure(mailStruct &structMail); |
aoc2 | 0:8940db3353d7 | 184 | |
aoc2 | 0:8940db3353d7 | 185 | #endif /*! __MY__STRUCTURES_H__ */ |