Copy_Assignment3

Dependencies:   mbed MCP23017 WattBob_TextLCD mbed-rtos

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers my_structures.h Source File

my_structures.h

00001 #pragma once
00002 
00003 /*******************************************************************************
00004  *                       CUSTOM PARAMETERS DECLARATION
00005  ******************************************************************************/
00006 #ifndef     CONSTANTS_OF_CAR
00007 #define     MAX_SPEED                  230 // km/h
00008 
00009 #define     SIZE_SPEED_VECTOR           10
00010 #define     SIZE_AVG_SPEED               3
00011 
00012 #define     ON                          1
00013 #define     OFF                         0
00014 
00015 #endif  /*! CONSTANTS_OF_CAR */
00016 
00017 
00018 /*******************************************************************************
00019  *                           STRUCTURES DECLARATION
00020  ******************************************************************************/
00021 #ifndef __MY__STRUCTURES_H__
00022 #define __MY__STRUCTURES_H__
00023 
00024 #include <vector>
00025 #include "mbed.h"
00026 #include "rtos.h"
00027 #include "MCP23017.h"
00028 #include "WattBob_TextLCD.h"
00029 
00030 
00031 /** This structure is used to store the RAW engine values
00032  *  
00033  *  @param: engineState         [bool] 
00034  *          State on the engine, on or off
00035  *  @param: acceleratorValue    [float]
00036  *          Last value got by TASK 1. From 0 to 1, % of acceleration
00037  *  @param: brakeValue          [float]
00038  *          Last value got by TASK 1. From 0 to 1, % of brake
00039  */
00040 struct engineRAWValues{
00041     bool    engineState;
00042     float   acceleratorValue;
00043     float   brakeValue;
00044 };
00045 
00046 /** This structure is used to store the speed and travelled distance of the car
00047  *  
00048  *  @param: *p_speedVector         [std::vector<float>] 
00049  *          Vector used to store the last speed values computed by the simulator
00050  *          Speed is in m/s.
00051  *  @param: sizeOfAvg              [int]
00052  *          Size of the averaging filter used to compute the displayed speed
00053  *          value. The average is computed by taking the last sizeOfAvg values
00054  *          of the vector p_speedVector.
00055  *  @param: averageSpeed           [float]
00056  *          Last value computed by task 3. In m/s
00057  *  @param: distance               [float]
00058  *          Distance travelled by the car, in m.
00059  */
00060 struct carStatistics{
00061     // Speed Vector
00062     std::vector<float> *p_speedVector;
00063     int                 sizeOfAvg;
00064     float               averageSpeed;
00065     // Distance
00066     float               distance;
00067 };
00068 
00069 /** This structure is used by the MAIL Queue object to store information to be
00070  *  sent to the computer.
00071  *
00072  *  @param: avgSpeed        [float]
00073  *          Last value of average speed computed
00074  *  @param: accelerator     [float]
00075  *          Last RAW value of accelerator. From 0 to 1.
00076  *  @param: brake           [float]
00077  *          Last RAW value of brake. From 0 to 1.
00078  */
00079 struct mailStruct{
00080     float avgSpeed;
00081     float accelerator;
00082     float brake;
00083 };
00084 
00085 
00086 /** This structure is the main structure used by the program in order not to
00087  *  use global variables. It is given as argument to every function used
00088  *  in the different RTOSTimer.
00089  *
00090  *  @param: System Inputs           [AnalogIn/DigitalIn]
00091  *          Set of system inputs used by the system for the assignment.
00092  *  @param: System Outpus           [AnalogOut/DigitalOut]
00093  *          Set of system outputs used by the system for the assignment.
00094  * 
00095  *  @param: Structures              [engineRAWValues/carStatistics]
00096  *          Two smaller structures used to organized values used by the
00097  *          different tasks of the assigment.
00098  * 
00099  *  @param: *p_mailQueue
00100  *          Mail Queue object, from "rtos.h". It uses a mailStruct structure
00101  *          to store information.
00102  *  @param: nbElementInQueue        [int]
00103  *          Number of element in the queue. Necessary in order to dump the mail
00104  *          by another task and because there is no method to get the number
00105  *          of element stored in the mail queue.
00106  *
00107  *  @param: Mutex                   [Mutex]
00108  *          Set of three mutex to protect the access of the engineRAWValues
00109  *          and carStatistics structures, as well as the mail queue object.
00110  *
00111  *  @param: *p_PC                   [Serial]
00112  *          Serial connection to the PC
00113  *
00114  *  @param: Screen Variables        [MCP23017/WattBob_TextLCD]
00115  *          Used to access the screen of the MBED shield.
00116  */
00117 struct carStructure{
00118     //  System Inputs 
00119     AnalogIn            *p_accelerator;
00120     AnalogIn            *p_brake;
00121     DigitalIn           *p_engineSwitch;
00122     DigitalIn           *p_sideLightSwitch;
00123     DigitalIn           *p_leftSwitch;
00124     DigitalIn           *p_rightSwitch;
00125     
00126     //  System Outputs
00127     DigitalOut          *p_sideLightIndicator;
00128     PwmOut              *p_leftLight;
00129     PwmOut              *p_rightLight;
00130     DigitalOut          *p_engineLight;
00131     DigitalOut          *p_overspeedLight;
00132     DigitalOut          *p_brakeLight;
00133     
00134     // RAW Values Structure;
00135     engineRAWValues     *p_rawValues;
00136     
00137     // Car Statistics
00138     carStatistics       *p_carStats;
00139     
00140     // Mail Structure
00141     Mail<mailStruct,100> *p_mailQueue;
00142     int                 nbElementInQueue;
00143     
00144     // Mutex
00145     Mutex               *p_rawMutex;
00146     Mutex               *p_statMutex;
00147     Mutex               *p_mailMutex;
00148     
00149     // PC Serial Connection
00150     Serial              *p_PC;
00151     
00152     // Screen variables
00153     MCP23017            *p_par_port;
00154     WattBob_TextLCD     *p_lcd;
00155 };
00156 
00157 /** Initialize a 'engineRAWValues' structure to zero.
00158  * 
00159  *  @param: &structVal [engineRAWValues]
00160  *          Reference to a structure to set all of its values to 0.
00161  */
00162 void initRAWValuesStruct(engineRAWValues &structVal);
00163 
00164 
00165 /** Initialize a 'carStatistics' structure to zero and add the given pointer
00166  *  to a vector to it
00167  *
00168  *  @param: &structStat [carStatistics]
00169  *          Reference to a structure whose values are set to 0
00170  *  @param: *speedVec   [std::vector]
00171  *          Pointer to a vector which is linked to the structure.
00172  *          Vector used to store the different speed value
00173  */
00174 void initCarStatisticsStruct(carStatistics &structStat,
00175                              std::vector<float> *speedVec
00176                             );
00177 
00178 /** Initialize a 'mailStruct' structure to zero.
00179  * 
00180  *  @param: &structMail [mailStruct]
00181  *          Reference to a structure to set all of its values to 0.
00182  */
00183 void initMailStructure(mailStruct &structMail);
00184 
00185 #endif /*! __MY__STRUCTURES_H__ */