Hw5 3223 SP17

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

HomeworkAssignment#5

Course:COP3223CIntrotoProgrammingwithC
Semester:Spring2017
CreditValue:4%ofFinalGrade
DueDate:April5,2017

SequenceofEventsRecorder
Description:Unexpecteddestructivefailuresofexpensiveequipmentcanbeveryfrustratingto
designers and maintenance personnel because they dont often have enough information to
allow them to determine what caused the failure. Because failures are almost always
unexpected,andtypicallyresultincompletelossofthedevice,doingaportmortemanalysisis
oftendifficult,leavingthemtodonomorethanavisualinspectionofthecorpse.Examples
ofthesearethedatablackboxesinallcommercialaircraftthatrecordthelastseveralminutes
ofthecriticalvariablesoftheaircraftsoperationjustbeforetheaccident.Therefore,infailure
analysis,itisquiteusefultoknowwhatthevaluesofcriticalparameterswerejustpriortothe
catastrophicfailure.Thisisthepurposeofasequenceofeventsrecorder.
Sequenceofeventsrecordersaredesignedtocapturethelastfewseconds,minutes,orhours
oftheoperationofthedeviceofinterest.Theyaregenerallylocatedexternallytothedeviceto
avoid them being destroyed along with the device. Of course, this is not possible for aircraft
black boxes, so they make them almost indestructible instead. Byrecording only the last few
seconds/minutes/hoursof operation,thememoryrequirementscanbemanagedratherwell,
especiallywhenmanyvariablesaretobeloggedand/ortheyaretobesampledataveryhigh
rate of frequency. These recorders, therefore, will overwrite old data with new data, always
havinginmemorythecriticallastseveralseconds,minutes,orhoursofthedevicesoperation
beforethefailure.
You work for a company that manufactures antilock braking systems for disk brakes for the
majorautomobilemanufacturers.Recently,therehavebeenseveralincidentsinwhichtheanti
lockingmechanismhasfailed,resultinginaccidentsonwetroads.Whilenoonehasyetbeen
injured,yourcompanytakestheseincidentsseriouslyandwantstoresolveanyissuesbefore
anyonedoesgethurt.Nobodyknowsexactlyhowthesedeviceshavemisoperated,butseveral
ofthedriversinvolvedinsuchaccidentshavereportedthatthenormalclackclackclackingof
theABSbrakeswasreplacedbyabingbingbing,atamuchslowerfrequency.Theengineers
arebaffledastowhatmighthavecausedthat,buttheydoknowitisntnormal.
So, you have been assigned to design a sequenceofevents recorder to capture the last 10
secondsofoperationofthecar.Thereareseveralsequenceofeventsrecordersonthemarket,
butnonearespeciallysuitedtoyourhighfrequencyapplication.So,youhavetowritethecode
yourself.Yourprogramistoacquirethevaluesofseveralvariablesduringonetime(calleda
sliceofdata)andsavethemtocirculararrayofstructuresthatsavesthelast10secondsofdata
acquired.Thesamplingfrequencyhasbeenspecifiedbythedesignengineerstobe10Hertz
(10dataslicespersecond),asautoaccidentsonlytakeafewsecondstohappen.

The system should repeatedly acquire the values of the following variables during the
operation:
1) Brakefluidpressuretothebrakeunit:between20and30PSI.
2) Electricalpowertothebrakingunit:between10and100watts.
3) Driverbrakepressure(appliedbythedriver):between30and40PSI.
4) Pressureappliedtothedisk:10to15PSI.
5) Timeinseconds.
Specifically, your assignment is to design and write a program that captures the timetagged
data slices of the variables above and saves them to a circular array of structures. Use a
sampling frequency of 10 Hertz. Circular arrays overwrite the oldest slice of data with the
newest, thereby keeping the last several slices leading up to the accident, which is what you
want to do. When an accident occurs (or the car is turned off), the program writes the last
several slices of data to an external file. Because youll only be testing the system for the
purposesofthisassignment,youcancreatethevaluesusingarandomnumbergenerator.Save
these values to an array of structures that contain a member for each one of the stored
variables,plusonemoreforthetime.Thetimecanbeassumedtobesequential,startingfrom
0andgoinguntilthecaristurnedoffnormallythroughtheoperationofthekeyoritcrashes.
The array is to contain the last 10 seconds worth of data (100 data slices). Then, write a
second program (separate from the one above) that reads the external file and prints it to
screen.Theoutputtoscreenshouldlooksomethinglikethis:

Time Brakefluid Pressure Driverbrake ElectricalPowerto


(secs) pressure ondisks pressure unit
.1 25 15 32 70
.2 20 10 33 72
.3 21 11 32 71
.4 23 10 30 75
.5 24 12 33 78
.6 21 10 36 70
.7 23 12 34 75
.8 22 11 38 78
.9 25 13 35 73
1.0 24 15 32 72
1.1 23 12 31 80
1.2 25 16 33 73
1.3 27 17 36 69

Where it prints the entire 10 second run of the values of each of the variables, at each 0.1
second.


Notes
1. Youmustusethefollowingelementsintheprogram:
a. Astructstructure
b. Anarrayofsize100.
c. Arandomnumbergenerator(rand())
d. Atleasttwouserdefinedfunctions
e. Thetypedefdataspecifierforthestructure.
2. Putthedataacquisitionprocessinaforloopwithexactly1177cycles.Assumethat
when it ends, the car crashed or the driver got to his/her destination and turned the
engineoff.Usethatasthesignaltowritethecollecteddatatothefile.
3. Useintegersforthevaluesofthevariables,eventhoughfloatingpointvalueswouldbe
muchmorerealisticinthisapplication.Itsmucheasierthangeneratingfloatingpoint
numbers.
4. Recordthetimeinintervalsof0.1seconds.
5. Commentyourfileadequately.Indentandspaceadequately.

You might also like