• No results found

Inthischaptertherealisationofprojectideasisdescribed.Iincludedinthischapterarean updatedversionofthegenerallightplan,howtheoutputofthesystemwasprogrammed,how bothinput(context)sourceswereprogrammed,and finallyhowthe systemswitchesbetween twoinputs.

6.1Generallightplanthirditeration

Duringtheimplementationofthegenerallightplan, afewmorealterationsweremade.Because theskylightsandwindowblindswereopenedupinsection1,thiswasnow thelightestareaand section3thedarkest.Consequentlythewall-pointedspotlightinsection1shouldbemovedto section3tokeepthebalance.Anotherdecision wasmadetoreplacetheaforementionedspot light,andtheotherwhitespotlightbyRGB spotlights,becausethey couldbeusedmore universallyandwereeasytoimplementintheDMX controlsystem,theone insection3is mountedonarotatingarmtomakeitpossibleto changeitspositionifsodesiredinthefuture. Anotherdecisionwasmadetomovebothmovingheadstotheedgesofsection 1andsection3, duetopracticalreasonsregardingtheflightcageinsection2andtheposition ofthebeamerin section3.Themovingheadswillalsobeused outsideoftheirspecified usecases,becausethe spotlightsonthewallsinsection2andsection3weretoofocussed toilluminateentirewall sections.Anotheruseforthesection3movinghead istoilluminatethe sittingareacreatedfor meetingpurposesinthementionedsection.Thefinalversionofthegenerallightplancanbe seenin​​Figure8.The DMXaddressesin​​Figure7correspondtothefixturelocationsof​​Figure8.

6.2Systemdesign

Discussedinchapter5.1.2andshowninFigure​​ 5​​arehigh-levelpreliminarytakesonsystem design.Eventhough​​Figure5correctlydisplaystherelationsbetweencomponents,many componentswereaddedandrelationscanthusbedescribedonalower,moredetailedlevelas seenin​​Figure9.​​Partsandtheirrelationswillbefurtherclarifiedinthe remainderofthischapter withuseof​​Figure9​​forreference.FurthermoreitisworthmentioningthatAn​​ArduinoMega

microcontroller[15]isthechosenprocessingunit, it’sC/Java- basedprogrammingis

straight-forwardanditiseasilyexpandableon ahardwarelevel.The Arduino,ethernetshield andDMXshieldoperateasonedevicewiththreeprocessingunits,asArduinosandshieldsare stackable,see​​Figure10.Thismeanstheyarethreedevicesthatsharetheir pinsignals,e.g.if theArduinooutputsasignalonpin1,bothshieldsareabletoread thatsignalasinput.

10. Figure:Arduinomegastackedwithtwo shields,imagecourtesyOlegMazurov

6.3ProgrammingDMXoutput

Asdescribedinchapter5.1.1,DMXprotocol operateswithchannels andaddresses,the addresswhichalightfixtureissettouse,isthechannelnumberitwillstarttoreadfromthe DMXstring,continuingtoreadthefollowingchannelsuptotheamountofchannelsthefixture wasset-upfor.AfteroutfittinganArduinowithaDMXshielditwaspossible tousetheDMX Master[19]Arduinolibrarytoindividuallyaddressfixtures andprogramthe lightoutputthrough theArduinocodinginterface.

Figure11showsArduinocodewhichcontainsthemainfunction‘voidloop’,inwhichusecase ‘lecture’iscalledfor.Therearehowevernotone,butfourmentionsof‘lecture’ inthevoidloop function,eachfollowedbyanumber.Thesenumbersrepresentsections1-3 oftheSmartXp andthefourthcoversallmiscellaneouslightfixtures,e.g.theLEDstripsunderthegallery,the LEDstripforthestairs,thehallwayspotlights,etc.

Thereasonthatforeveryusecasetherearedifferentfunctionsforeachof thefoursections,is afuture-proofingmeasurethatallowstwothings.Itkeepsthecode manageable,findinga certainlineofcodeforalightfixtureissimplerwhenitcanbe foundwithinthefunction correspondingtoitssection.Secondly,itallowsformultipleusecases tobeactive

simultaneously,ascenariothatcouldoccurwhentheamountofimplemented contextsourcesis increased.Thelinesofcodeunder‘voidloop’couldbecallingdifferentusecases,forexample:

Voidloop() { Lecture1(); Meeting2(); Supervised3(); Unsupervised4(); }

Inthiscase,thelightsinsection1wouldbe settotheparametersforalecture,thesecond sectionwouldbesetaccordingtotheparametersforameeting,thethirdforasupervised projectandthefourthforanunsupervisedone.

Furthermore,​​Figure11​​showspartofthefunctionfor section1ofthe usecase‘lecture’.There arethreeblocksofconsecutivecode,eachleadbyacommentdescribingitssectionandthe approximatelocationandtypeoffixture,e.g.‘//section 1frontspots’.Afterthisindication,there areseverallinesofcode withtheformatDMXMaster.write(x, y);’.Thisistheformatusedbythe DMXMasterArduinolibrary[19].The‘x’isthechannel,‘y’ isitsvalue.Inthiscasethe‘frontspot’ isa7-channelfixture,hencetherearesevenlines ofcode,onefor eachchannel.Theaddress ofthisfixtureis008,hencethechannelinthefirstDMXMasterlineis8.Notallsevenofits channelsareused,thefirstthreeareforthe red,greenandblue valuesrespectively.Whichis thereasonthoselinesarefollowedbyacomment like‘//R’,whichis anindicationforthe programmerthatthislineisfortheredvalueofthisfixture.

6.4Implementationofschedule

TheArduinoMega,alreadyoutfittedwithaDMXshield,isnowalsooutfittedwithanethernet shield.Thecodeforconnectingtoandparsing thescheduleispartiallybasedonthe

RelaySketchbyM.Bornski[18],whomadeitpossibletouseGoogleCalendartocontrola numberofrelays.

BecausetheSmartXpscheduleasitappearsonUniversityofTwente’swebsite

rooster.utwente.nlisnotdirectlyaccessibleforthirdparties,itwasexported toGoogleCalendar, whichisonlyaccessiblethroughthelinkthatisusedinthesystem’scode.Furthermore,the sourcecodebyM.Bornskiwasalteredsothatit wouldnolongerparsethetitlesofevents,but usetheirdescriptionsinstead.Thiswasnecessarybecausetheeventtype oftheSmartXp scheduleisindicatedinthedescriptionoftheevent,obviouslythismeantthatthekeywordsalso hadtobechangedtotheeventtypesthattheSmartXpscheduleuses,so thatthescriptcould recognizecertainevents.

Parsingthedescriptionposedaninterestingproblem,as theoriginalcodewouldfindacertain wordinthedatareceivedfromGoogleCalendar(Appendix3),forexampleif“TITLE:”was found,thenthelineafterwouldbecheckedfor relevantkeywordsandstop doingsoatline ending.Inthedescriptionhowever,keywordswouldnot necessarilybeonthesameline.The solutionwasiftheinitialiser“DESCRIPTION:”wasfoundtoignoreline endingsandremove spacesfromthestring,sothatitwould searchtheentiredescriptionforkeywords.Furthermore, thecodewasalteredsothatifakeywordwasfound itwouldnolongersend asignaltoarelay, butinsteadusetheDMXMasterlibraryasdescribedabovetoexecutefunctionsoftherelevant usecases.

Anextrausecasewasaddedforthelunchbreak,whichisn’tanevent intheschedule,another methodwasusedforcallingthisusecase.Becausethelunchbreakhappensdailyfrom12:30 until13:45,thistimingwasusedforimplementation. Themethodusedtakesthestring‘now’, whichcontainsthecurrentdateandtime,andcopiesitintotwonewstrings‘lunchtimestart’and ‘lunchtimeend’,afterwhichthesectionofthestringwhichcontainsthetimeofbothisreplaced by‘1230’and‘1345’.Thesethreestringsarethenused tocheckwhetherornotthevalueofthe ‘now’stringisbetweenthestartandendingof lunchtime.Usedinan if-loopthisenablesthe executionofeitherallfunctionsregardingscheduleparsing oritdirectlyexecutesthe‘break’use case,dependingonthetime.

6.5Implementationofuserinput

Inordertoimplementaweb-baseduserinterface,theinput oftheuserhadtobestoredsothat theArduinocouldinterpretit,andamethodof distinguishingwhethertouse thescheduleorthe userinputhadtobedesigned.Theuserinterface ​​Figure12,whichwasdesignedbyHeleen Kok,isawebpagethatoutputstheselectedvaluestoaphpfileper sectionandcolour,see

Appendix4​​foranexample.Thisfileisparsed insimilarfashionas theGoogleCalendaris parsed,savingasectionandacolourvalue.A setofif-loopsmanage thecorrectsectionand colourallocation.

Adistinguishingfactoristhatthereisonlyone usecaseforthe manualoverride,whichuses variablered,greenandbluevaluessetbythe if-loopsasdescribedabove, thiswasadeliberate efforttodecreasethelengthofthecode. Aspreviouslydescribed,normallyusecasefunctions

manualoverride,thelightingfunctionsweredividedin sevensectionssothattrusssections1-3, entrance1,entrance2,stairsandgallerylightingcouldbesetindividually.

Inordertopreventtheprogramfrom constantlyswitchingbetween calendar-basedlightingand userinput,a‘context-aware’buttonwasaddedintheuserinterface,whichoutputsthecolourof lightinthephpfileas‘default’.Furthermore,alllightsareon‘default’by default.Insteadofusing asinglebooleanvaluetosettrueorfalseaccordingtoalightsectionbeingondefaultornot,a chararraywasusedcontainingsevendigits.Thisissothateachofthe sevensectionsthatcan besetthroughtheuserinterfacehavetheirowndefaultorcolourvalueand onlywhenallseven digitsaresetto‘1’theprogramwillgoback tocheckingthecalendarinstead.Inotherwords,a sectionwillremainondefault,evenifanothersection ischangedtoa manualcolourandvice versa,ifnotallsectionsaresettodefaulttheprogramstilldoesn’treturn tousingthescheduled lightingvalues.

12. Figure:Manualoverrideuserinterface

6.6Functionality

Figure13describeshow theArduinoswitchesbetweencheckingthecalendar andcheckingthe userinput.Theflowchartshowsthatwhenthe calendarischecked,avalue‘checkcalendar’is setto‘0000000’.Thisbyteisusedbythe programtokeeptrack ofwhethertheSmartXp’s scheduleshouldbecheckedforusecases,orthesettingsfromthemanualoverrideshouldbe applied.Insteadofabooleanthatcanonlybe trueorfalse,‘checkcalendar’ isabytethat consistsofsevendigits.Eachofthesesevendigitsrepresentsoneofthesectionsofwhich lightscanbeadjustedintheuserinterface.

IntheuserinputphpfilethatisparsedbytheArduino,asectionmaybeset toacolourorto ‘default’.Ifasectionissettodefault,itscorresponding bytevaluewillbesetto‘1’.Forexample ifonlysection3issettodefaultinthemanualoverride,thebyte stringwillbe‘0010000’.

Followingtheflowchart,thecalendarwillbecheckedagainifthe valueof‘checkcalendar’ equals‘1111111’.Thismeansthatifanumberof sections,butnotall sections,aresetto default,thelightsinthosesectionsaresettothe valuesoftheusecaselastobtainedfromthe schedule.Onlyifallsectionsaresettodefault,thevalueof‘checkcalendar’willbe‘1111111’, thecalendarwillbeparsedagainandthevaluesoftheobtainedusecase areappliedtoall sections.Afterthecalendarhasbeenparsed, ‘checkcalendar’willbe re-setto‘0000000’, re-startingthecyclethatchecksmanualoverridedata.

Related documents