engineering design: design and control of a simple robot · engineering design: design and control...
TRANSCRIPT
![Page 1: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/1.jpg)
1
EngineeringDesign:
DesignandControlofASimpleRobot
ByRobyVelez
Advisor:ErikCheever
Abstract:Thispaperdetailsmyseniordesignproject.Itgoesthroughtheprocessofthecreationofa
simple,crawlingrobot.Itdescribesdifferentcontrolalgorithmsusedtomaketherobotcrawl.Oneofthecontrolalgorithmslookedatwaslearningwithartificialneuralnetworks(ANN)andgeneticalgorithms(GA).TheANNandGAproducedcontrollerswhichreliedoncouplingbetweensensorsand
servosandoscillatorstoproducerobustandfastcrawling.
![Page 2: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/2.jpg)
2
1.Introduction.......................................................................................................................................3
2.Hardware ............................................................................................................................................42.1PCB ................................................................................................................................................................4XBEE.......................................................................................................................................................................................6
2.2Chassis..........................................................................................................................................................7
3.Software ........................................................................................................................................... 103.1Servosandpulses .................................................................................................................................. 103.2Timer1andPWMCompare ............................................................................................................... 113.3HandshakingbetweenPICandMATLAB ....................................................................................... 143.4Simulator.................................................................................................................................................. 16crawlingRobot().............................................................................................................................................................17UpdatingPosition..........................................................................................................................................................17Geometry...........................................................................................................................................................................17SimulatedSensors.........................................................................................................................................................19
4.ControlArchitectures .................................................................................................................. 194.1DirectControl ......................................................................................................................................... 194.2DirectProgramming............................................................................................................................. 204.3Learning.................................................................................................................................................... 21ANN .....................................................................................................................................................................................21GeneticAlgorithms .......................................................................................................................................................21NEAT ...................................................................................................................................................................................22
4.4MATLABimplementationofNEAT................................................................................................... 24Neuralnetworksetup..................................................................................................................................................24Activationfunctions .....................................................................................................................................................25
4.5NEATExperiment .................................................................................................................................. 26PortingtoRobot.............................................................................................................................................................28
5.AnalysisofArtificialNeuralNetworks................................................................................... 285.1LocomotionandPatternofActivation ........................................................................................... 295.2DifferenceBetweenPushersandPullers ...................................................................................... 305.3ANNandOscillators .............................................................................................................................. 315.4ExploringPhaseShifts ......................................................................................................................... 325.5PushersbetterthanPullers ............................................................................................................... 34
6.Conclusion ....................................................................................................................................... 35
References............................................................................................................................................ 35
![Page 3: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/3.jpg)
3
1.Introduction
Mostmobilerobotsarewheeled.Theyareeasytomakeandeasytocontrol.Theonlyissueisthatthesewheeledrobotsliveinaworldinhabitedbywalkingorganisms.Leggedrobotsaremoredifficulttobuildbecauseoflimitationswithactuatorsandpowerdemands.Theyarealsodifficulttoprogrambecause
theyrequirethecoordinationofmultiplelinkages.Butleggedrobotsofferimmensepossibilitiessuchassearchingthroughacollapsedbuildingwithrubbleforvictims,transportingequipmentoverharshterrainforthemilitary,orworkinginahomeenvironmentassistingpeoplewithdisabilities.
Oneissueinroboticsistryingtomakerobotssmartenoughtoadaptandlearninchanging
environmentsaswellasfindsolutiontoproblemsontheirown.Thishascausedmanyroboticisttodrawinspirationfrombiologicalsystemswhichcanfendforthemselvesinsometimesveryharshandchangingenvironments.Twocomputationmodels/algorithmsinspiredbybiologyareartificialneuralnetworks
andgeneticalgorithms.Artificialneuralnetworksaremodeledafterrealneuralnetworks.Theyconsistofacollectionofinterconnectednodeswhereinformationpropagatesthroughtheconnections,isaltered,andthenshootsouttheend.Geneticalgorithmsareawayofusingevolutiontosearchthrough
asolutionspaceforasolutiontoaproblem.Artificialneuralnetworksandgeneticalgorithmsarebothbiologicallyinspiredandincorporateelementsofadaptionandlearning.
ResearchersinSwitzerlandhavebeenlookingatrobotswhichmovenotbyrollingonwheels,butbyflappingtheirfins(2),crawlingonfourlegs(3),orslitheringlikeasnake(1).Theresearchershavebeen
abletoaccomplishthisthroughtheuseofCentralPatternGenerators.CentralPatternGeneratorsaremodeledoffofatypeofneuralnetwork.Theseneuralnetworksproduceoscillatoryoutputgivennoneoscillatoryinput.CentralPatternGeneratorsandoscillatorymotionhasbeenfoundtobeessentialto
locomotion.Whilethisworkisveryinterestingtheresearchesusedmodelsofneuralnetworks,notactualartificialneuralnetworkstocontroltherobots.
ThepurposeofthisprojectistotrytoemulatetheresearchersfromSwitzerlandandusenotamodelof
aneuralnetwork,butanactualartificialneuralnetworktocontrolthelocomotionofarobot.Usingactualartificialneuralnetworkspreventsconstrainingtotheartificialneuralnetworkstoaparticularmethodforsolvingtheproblem.Theartificialneuralnetworkscouldfindoscillatorstosolvethe
locomotionproblemorcomeupwithsomenovelapproach.Forthemostparttherehasn’tbeenmuchworkonusingactualartificialneuralnetworkstocontrollocomotionwhichistime,andmemorydependentproblemwhichdoesn’thaveinstantfeedback.
Artificialneuralnetworksaregenerallyusedtolearnthroughatrainingalgorithmwhichaltersthe
weightstogettheneuralnetworktoproduceacertainoutputforagiveninput.Howeverartificialneuralnetworkscanbeusedtosolveaproblembyevolvingtheirweightsandtopologywithageneticalgorithm.ThiscanbedonewithanalgorithmknownasNeuroEvolutionofAugmentingTopologies
(NEAT)(4).Thisiswhatwillbeusedinthisprojecttosearchforartificialneuralnetworkstosolvethistask.
![Page 4: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/4.jpg)
4
Theevolutionofanartificialneuralnetworkswhichcancontrolacrawlingrobotisthepinnacleofthisproject,buttogetthererequiredmanystepsorstageswhichincludedesignandconstructionofthe
microcontrollerandrobotchassis,creationofthelowlevelservoandcommandprotocols,creationofthehigherlevelcontrolalgorithmswhichincludestheNEATandartificialneuralnetworks,andfinallytheanalysisoftheevolvedneuralnetworks.Thesewillbelaidoutinthefollowsections.
2.HardwareThefirststageofthisprojectconsistedofthecreationoftheactualphysicalrobotandaprotocoltoprogramanddolowlevelcontrol.Thisconsistedofthecreationmicro‐controller,robotchassis,and
commandprotocol.
2.1PCBAprintedcircuitboard(PCB)wasusedtocontroltherobot.AblockdiagramforthePCBisshownbelow.
Figure2.1:BlockDiagramofPrintedCircuitBoard(PCB).
AtthecenterofthePCBisamicrocontroller.Themicrocontrollercanbelookedasaminiature‐
processingunit.Itcanbeprogrammedtodocalculations,readsensorsandactuateservos.ThemicrocontrollerusedwasthePIC16F767.ThePIC16F767isasimple,inexpensivemicrocontrollerchosenbecauseithadthemostPWMcomparepins,whichwouldbeusedtocontrolservos,andhada
lotofdigitalandanaloginputs.LikeacentralprocessingunitinarealcomputeraPICcannotworkonitsown.Itneedsperipherals
suchaspower,debugger,andI/Oconnectionsinordertofunction.ThePCBhadtoprovide5voltsforthePIC,7voltstopowertheservos,and3voltsfortheXBEEmodule.TheXBEEmoduleisanintegratedchipthatwillprovidewirelesscommunicationtothePCB.Itwillbediscussedshortly.The
circuitschematicinFigure2.2showshow7voltswerebroughtintothePCBanddropdownto5voltsand3voltsbyvoltagedividers.
![Page 5: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/5.jpg)
5
Figure2.2:Powerschematic.
BesidesprovidingpowerthePCBalsoprovidedotherperipheralssuchasadebugger(whichisusedtoprogramthePIC)andI/Oconnections.Figure2.2showstheMultisimschematicfortherestofthePCB.
Figure2.3:Circuitschematic.
MostoftheI/Opins,notusedforpower,debugging,orserialcommunicationbetweenthePICandXBEE,areroutedtothebankofheaderslocatedintheupperrightofFigure2.3.TheheaderbanksprovideaccesstotheI/OpinsforthePICandXBEEaswellasaccesstotheground,the5voltpower
supply,and3voltpowersupply.DesigningtheheadersintothePCBlikethisenablesalotofflexibilityforaddingsensors.
![Page 6: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/6.jpg)
6
Infigure2.3,totheleftofthePIC,abankofheadersweremadeforthePWMpinsofthePICandXBEE.Thisiswheretheservoswouldbeconnected.TorightofthePICistheRJ12usedtoconnectand
programthePIC.Adebuggerlikethisisstandardformostmicrocontrollerboards.FinallythePICisconnectedtotheXBEEbywiringtheTXpinofthePICtothedataInpinoftheXBEEandbywiringtheRXpinofthePICtothedataOutpinoftheXBEE.Thesepinsareusedtotransmitserialdatabetween
theXBEEandPIC.Figure2.4showsthecompletedPCBwithallthecomponents.
Figure2.4:CompletedPCB.
XBEETheXBEEmodulescanformverysimple,lowpowernetworksthattransmitserialdata.Theyactlike
wirelesscables.Wirelesscommunicationwithamobilerobotisveryusefulindebuggingandcreatingcontrolarchitecturefairlyquickly.LivecommandscanbesenttotherobotandexecutedinstantaneouslyversuswritingcodetothePIC,compilingit,andthenrunningit.
OneXBEEmodule,calledtheControllerXBEE,wasconnectedtothePICandanothercalledtheBaseXBEE,wasconnectedtoaremotecomputerrunningMATLAB.Thisisseeninfigure2.5.TheController
isaXBEEPROwhiletheBaseisaregularXBEE.ForthemostpartthetwomodulesarethesameexceptthattheXBEEPROis5‐volttolerant.ThiswasessentialsinceitwasreceivingserialdatafromthePICwhichwasrunningoffof5volts.
![Page 7: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/7.jpg)
7
Figure2.5:DiagramshowingthewirelesscommunicationbetweentheremotecomputerandPCB.
Theserialport,ontheremotecomputer,isopenedbyMATLABandserialdata,suchasstrings,canbe
sentthroughtheporttotheBaseXBEEmodule.TheBaseXBEEmodulethentransmitstheserialdataoverawirelesscabletotheControllerXBEEmoduleonthePCB.TheControllerXBEEmodulethentransmitstheserialdataintothePICwherethePICcanreadit.ThePICcanalsotransmitserialdatato
theControllerXBEEwhereitissenttotheBaseXBEE.TheBaseXBEEthensendstheserialdatatothecomputerwhereitisreadwithMATLAB
2.2ChassisSincethepurposeofthisprojectwastoexplorelocomotionwithaleggedrobotaverysimpl,yet
interestingdesignwascreated.Therobotiscomposedofa3degreeoffreedom(DOF)armmountedontoawoodenchassis.Thechassisrestsontwocontactsensorsinthefrontandhastotwocastor‐likewheelsinthebackwhichareodometers.Figure2.6showsaconceptdrawingoftherobot.
Figure2.6:Conceptdrawingofrobot.
![Page 8: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/8.jpg)
8
Acrawlingrobotwasdesignedinsteadofatraditionallywheeledrobotbecauseacrawlingrobotwouldbemoreinterestingtocontrolwiththelearningalgorithminsteadofawheeledrobot.The
designissimpleinthatthereisonlyonelimbandthingslikebalancearen’tissuesastherobotmoves.Butthedesignstillrequiresthecoordinationofmultiplejointstoproducelocomotionsoitretainsthecomplexityoflocomotionandmanipulatorcontrol.
Linkage3measures13centimeterswiththeendaffecter,andlinkage2measure11centimeters.Theendaffecterisahalfinchpieceofpixelglassmadeintoadiscandboltedontotheendoflinkage3.The
plywoodboard,thatthearmismountedonto,isapieceofquarterinchplywood16by18centimeters.Atthefront,underneaththeplywoodisafoamblockwiththedimension13by3by3.Twocontactsensorsareattachedtoeithersidesofthefoamblock.Therobotrestsonthecontact
sensorsnotthefoamblock.Thefoamblockissimplytheretoallowthecontactsensorstobeattachedtothechassis.Finallyastheendofthechassisaretwocontinuouspotentiometerswithwheelsmountedontotheirshafts.Whentherobotrearsupandliftsthechassisoffthegrounditrollson
thesetwowheels.Figure2.7showsanactualimageoftherobot.
Figure2.7:Imageofrobotchassis.
Therobothasthreeservos.Servoonerotatesthearmwithrespecttobase.Figure2.8isadiagram
fromabovethelimitsofservo1’stravel.
Figure2.8:Topviewoftherobotmeanttoshowtherangeofmotionforservo1.
![Page 9: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/9.jpg)
9
Servo2connectslinkage2totheservo1.Servo3connectslinkage2tolinkage3.Figure2.9showsthe
rangeofmotionforservo2andforservo3.
Figure2.9:SideviewoftherobotmeanttoshowtherangeofmotionforServo2and3.
Inordertohavelinkage2and3inalmostthesameplaneServo3isflippedfromServo2.Figure2.10showshowtheServosarecurrentlymounted(left)withthelinkagesinthesameplane,andhowthelinkageslookifServo3wasinthesameorientationasServo2(right).
Figure2.10:Comparisonofthearminaconfigurationwhereitisalignedandwhenitisnotaligned.
ImageontheleftshowstheactualconfigurationofServo3andServo2whichbringsthearmintoalignment,butcausesServo3andServo2tofacedifferentdirection.TheimageontherightshowsapossibleconfigurationofServo3andServo2whichcausesthemtopointinthesamedirection,butthe
armisnotaligned.ThismeansthatifServo2isgivenacommandtorotateclockwise,thatsamecommandwillmakeServo3rotatecounterclockwise.Thisisnotaseriousproblem,butitcomesintoplayduringtheNEATevolutiontests,discussedlater.
![Page 10: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/10.jpg)
10
Therobothassixsensors.Theyarelistedinthetablebelow.
SensorName
Description
3PositionSensors
MadefrommonitoringapinoffoftheServocontrolboard.TheyindicatetheangleofeachServo,butarequitenoisy.Theyrangefromavalueof80to400.
1ForceSensor
Mountedattheendofthearm.TheServosarenotverystrongsothesensorwascalibratedtobeverysensitive,whichresultsitinnotbeingabletodistinguishawiderangeofdifferentforce.Therobotprettymuchknowsifitistouchingthegroundornot.Itiseither1023whenthearmisoffthegroundandaround600whenthearmisonetheground.
1ContactSensor
Twocontactsensorsaremountedoneithersideofthefoamonthebottomofthechassis.Therobotrestsofthem.Theyarewiredtogetherandactasonecontactsensor.Theyreporta1ifoneofthemisreleasedandazerootherwise.
1Odometer Whentherobotrollsforwarditisrollingforwardontwowheelsmountedatthebackofthechassis.Thetwowheelsaremadeupofcontinuouspotentiometerswhichreadachangingvoltageastheyturn.OnlyoneOdometerreadingisread.Thisisusedtomeasurehowfartherobothasmoved.Itreadsavaluefrom0to1023.Ifthepotentiometerswiperreaches1023butcontinuestorollitwillrolloverto0andincrementnormally.Ifthepotentiometerreads0andcontinuestorollbackwardsitwillrolloverto1023andcontinuesdecrementingnormally.
Table2.1:Sensorsoftherobot.
3.SoftwareOncethemicrocontrollerandchassiswerebuiltcodewaswrittenforthePICandMATLABwhichactuatedtheServosandcreatedacommand/communicationprotocolbetweentheremotecomputer
andthePCB.Servosneedaspecificprotocoltoworkproperlyandthecommunication/codingprotocolwilldeterminehoweasyitistowritecontrolalgorithms.
3.1ServosandpulsesServosworkbysendingthempulsewidths.PulsewidthscanbegeneratedbyaPICholdingapinhighfor
asetamountoftimeandthensettingitlow.Thepulsescanbelaunchesatsetperiods.ThisisshowninFigure3.1.
Figure3.1:Illustrationofpulseswidths.Alteredimagetakenfrom.
http://www.servocity.com/html/how_do_servos_work_.html
Forservosthepulseshavetohaveaperiodof20millisecondsandwidthsrangingfrom500microsecondsto2500microseconds.Thewidthofthepulsedeterminesthepositionoftheservo.ThisisshowninFigure3.2.
![Page 11: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/11.jpg)
11
Figure3.2:Imageofhowpulsewidthscorrespondtopositionoftheservos.Imagealteredandtakenfromhttp://www.servocity.com/html/how_do_servos_work_.html
3.2Timer1andPWMCompareInordertoproduceandvarythepulsewidthsTimer1andthePWMcomparefunctionsofthePICare
used.AninternalclockregulatestheoperationofthePIC.Thisinternalclock(Fosc)issimplyaninternal(orforsomePICsexternal)oscillatorthatoscillatesandsendspulsesatcertainfrequencies.Timer1isa16bitcounterwhichincrementsonceeveryfourclockcycles.BecauseTimer1isa16bitnumber,onceit
countsupto65535itrestartsat0andbeginscountingupagain.ThisiscalledanoverflowandisshowninFigure3.3.
Figure3.3:DiagramillustratingthefillingandoverflowingofTimer1.
ThePICcanbemadetolaunchaninterruptwheneverthishappens.Aninterruptisanoperationthat
canbetriggeredbyanumberofthingssuchasaregisteroverflowing,acompareevent,orachangeofanexternalinput.WhenaninterruptistriggeredthePICputswhateveritisdoingonholdanddoeswhatevercodeisassignedtotheinterrupt.
Overflow Reset
![Page 12: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/12.jpg)
12
ThecountofTimer1canbesettosomeInitialCount(IC)afteritoverflows.Timer1willthencountupfromthisInitialCountuntilitreaches65535andoverflowsagain.BecauseTimer1incrementsatafixed
ratethetimebetweenoverflowscanbealteredbythroughtheInitialCountvalue.ThisisillustratedinFigure3.4.
Figure3.4:DiagramwithdescribeshowtheInitialCountcanbecalculatedtoproduceanoverflowafterasetaboutoftime.
WithFoscequalto8MhzandanInitialCountof60535Timer1willoverflowandlaunchaninterrupt
every20ms.TheinterruptwillpullthepinsconnectedtotheServoshigh.Servo3isconnectedtopinc1.Servo2isconnectedtopinc2.Servo1isconnectedtopinb3.
That’sonepartoftheservoactuation.ThesecondusesthePIC’sPWMcomparefunction.ThePIChasthreeinternalvariablescalledCCP_1,CCP_2,andCCP_3.ThePICcanbemadetolaunchinterrupts
wheneveroneofthesevaluesequalsthecurrentvalueofTimer1.TheinterruptswillpullthepinsconnectedtotheServoslow.ThisisshowninFigure3.5.
![Page 13: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/13.jpg)
13
Figure3.5:IllustrationofhowthefillingofTimer1launchestheinterruptsofCCP_1,CCP_2,andCCP_3.
Thewidthofthepulsecanbecalculatedas:
Thepulsewidthdeterminesthepositionoftheservo.TheequationbelowsolvesfortheCCPvalueto
produceacertainpulsewidth.
ThismeanstheServoscanbecontrolledbychangingtheCCPvalues.
InsummarysettingTimer1tosomeInitialCountafteritoverflowsdeterminesthetimeuntilthenext
overflowwhenaninterruptwillbelaunched.Theinterruptwillhappenevery20msandwillpullpinsc1,c2,andb3high.ThecomparefunctionofthePICcanbeusedtolaunchinterruptsandpullthepinsc1,c2,andb3low.ThetimebetweenTimer1settingapinhighandaCCPinterruptsettingitlow
correspondstotheCCPvalue.Thiswillproduceapulseacertainwidthevery20mswhichcanbeusedtocontrolaservo.
![Page 14: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/14.jpg)
14
3.3HandshakingbetweenPICandMATLABThepurposeofequippingthePCBwithawirelessfunctionwastobeabletoactuatetheservosbytypingcommandstringsintoMATLAB’scommandline.MATLABwouldprintthestringstotheserialportwhichwouldthensendthestringtothePCBviathewirelessserialconnection.Thisisincontrastto
writing,compiling,anddebuggingcoderightoffthePIC.Figure3.6showsaflowchartcomparingthetwoprogrammingapproaches.
Figure3.6:FlowchartcomparingwritingcodetothePICversussendingcommandsoverwirelesscable.
SendingcommandfromMATLABclearlylookseasierandfaster.Inordertodothisaprotocolwas
developedsothatthePICwouldunderstandthecommandstringssentbyMATLABandMATLABwouldunderstandthecommandstringssentbythePIC.
MATLABwouldsendstringstothePIC.ThePICwasprogrammedtolookforthe‘#’symboltosignifythebeginningofacommand,parsetheservowordsinblocksoffour,andexecutetheproperactionbased
onthecommandandservowords.Thecommandstringshavetheformof:
# 1 0 0 0 2 0 0 0 3 0 0 0 0 0 2 0
Signifiesthebeginningofa
command
Firstfourdigitsrelatetoservo1.
Secondsetoffourdigitsrelateto
servo2.
Thirdsetoffourdigitsrelateto
servo3.
Teeltherobothowtoexecutethecommand.
Table3.1:Commandstringprotocol.
![Page 15: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/15.jpg)
15
Currently3typesofcommandshavebeendeveloped.
Command Description
0010 AddsthevaluesindicatedforeachservototheCCPvalueassignedtothespecificservosensor.Effectivelymakestheservogotothepositioncorrespondingtothosevalues.
0020 Printthepositionreadingfrompotentiometer.Ignoreservowords.
0030 IncrementthevaluesforCCP_1,CCP_2,andCCP_3bythevaluesineachservoword.Indicateanegativeincrementbyprecedingaservowordwith‘n’.Forexamples‘#0200n500n1000030’meansincrementthefirstservoby100anddecrementthesecondandthirdservoby500and
300respectively.Thelargestnegativecommandisn999.
xxxx Anythingnotthethreecommandsshownabovewillsimplybeignored.
Table3.2:Commandtypeoptions.
ThefollowingcodeopensaserialportandincrementsServo1by500anddecrementsServo2by200.
ThefollowingcoderequeststhePICtotransmitinformationonitssensors.
WhenthePICreceivesa‘0020’commanditqueriesitssensorsandsendsthembacktoMATLABistheformatof:
# 0 2 7 0 0 0 8 0 0 4 0 0 0 9 0 0 0 0 0 1 0 5 4 0 0 0 1 0
BeginningofCommand
PositionofServo1
PositionofServo2
PositionofServo3
ForceSensor
ContactSensor
OdometerReading
MessagefromPIC
Table3.3:FormatforthePICsendingsensorinformationbacktoMATLAB.
Tostreamlinethesendingandreceivingofcommandandmessagestringsafunctioncalled
sendCommandStringwaswritten.Itisdefinedas:
[serialHndl,sensorReadings,message,success]=
sendCommandString(serialHndl,[servoWord1,servoWord2,servoWord3,commandWord]);
>>s=serial(‘COM1’,’BaudRate’,13400);%Openstheserialport
>>fprintf(s,’#0500n20000000030’);
>>fprintf(s,’#0100n20000000020’);
>>reponse=fscanf(s,’%s’,29);
0000000030’);
![Page 16: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/16.jpg)
16
serialHndl Handlefortheserialobject.
sensorReading Arraywiththesensorvalues.Thisarrayisfullofzerosunlessa20commandissent.
Message MessagefromthePIC
Success Flagwhichindicatesifthecommunicationwassuccessful.
servoWord Insteadoftyping‘0020’or‘n200’thevalues20or‐200canbetypedin.
commandWord Insteadoftype‘0020’or‘0010’typing20or10wouldwork.
Table3.4:ParametersforthesendCommandStringfunction.
ThecommunicationbetweenMATLABandthePICisoverawirelesscommunicationandhassomelag.
Onaveragethelagbetweensendingsaya‘0020’andreceivingareplyfromthePICwas0.02seconds.Thiswillcomeintoplayindesigningthesimulator.
3.4SimulatorAsimple2DsimulatorwascreatedinMATLABinanticipationofhavingtorunmultipleevolutionrunswiththerobot.Ascreenshotisshowninfigure3.7.
Figure3.7:Screenshotofthesimulator.
Ideallyevolutionwouldbedoneontheactualrobot,butthisisslow,cancausedamagetotherobot,andrequiressomeonetocontinuouslywatchtherobot.Thesimulatorcreatedisfairlysimple,butfortheamountoftimeitcapturesalloftherelevantaspectsoftherobotneededtoproduceacceptable
evolutionruns
![Page 17: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/17.jpg)
17
crawlingRobot()
ThecornerstoneofthesimulatorisasimulatedrobotobjectcalledcrawlingRobot().Thesimulatedrobothasthesameattributesandphysicalcharacteristicsastherealrobot.Ithasparametersforthecurrentvaluesofallitssensors,currentlocationofitsphysicalbody,andvaluesforinternalvariables
presentintherealrobotsuchastheCCPvalues.
UpdatingPosition
MATLABtalkstothesimulatedrobotthesamewayittalkstotherealrobot.ItusesthesendCommandStringfunction,butpassesinahandletothecrawlingRobotinsteadoftheserialport.Oncethecommandstringsaresenttothesimulatedrobotitupdatesitsservolocations,physical
position,andsensorvalues.WhenthecommandstringisdecipheredtheCCPvaluesofthesimulatedrobotareupdatedaccordingly.TheCCPvaluesrepresentthedesiredlocationoftheServos.ThesimulatedrobotcannotautomaticallysetitsservolocationstotheanglesspecifiedbytheCCPvalues.
Thiswouldmeanthattheservosmovedinstantaneouslytowheretheyweretoldtogo.Theservoshaveamaxangularspeed.Thecurrentlocationoftheservos,whichisencodedina
variablecalledsPos,approachesthedesiredlocationoftheServosataspeedequaltothemaxspeedoftheservos.Theupdatedlocationoftheservosaftereachupdatecycleiscalculatedfromthemax
angularvelocityandtheelapsetimefromthelastupdate.Theelapsedtimebetweenupdatesissetto0.02seconds.ThisdoesnotreflecthowlongtheMATLABcodetakestoupdatethesimulatedrobot.0.02istheaveragelagincommunicationbetweenMATLABandtherealrobot.Becausetheshortest
elapsetimebetweenMATLABqueryingtherealrobotforsensorvaluesorsendingaservocommandis0.02secondsthenthiscanbeusedasthetheoreticalelapsetimebetweenupdatecycles.
GeometryOncethepositionoftheservosisknowntheorientationofallthepointsoftherobotcanbecalculated.Thisisthenusedtodeterminewhatthesensorsvaluesshouldbe,ifacollisionhasoccurred,oriftherobothasmovedany.Thesimulatedrobothastwodifferentstateswhichplotand
updatedifferently.Thesimulatedrobotrestsandcrawlsoveravirtualground.Ifthechassisofthesimulatedrobotison
thegroundandtheendaffecterisn’t,thejointsofthesimulatedrobotarecalculatedbyusingthebackofthechassisasthereferenceandfigure3.8.Inthisreferencetheta1,whichistheanglebetweenthechassisandtheground,is0.
![Page 18: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/18.jpg)
18
Figure3.8:Diagramwhichillustratestheanglesusedtodrawtherobot.Thereferencelocationisthebackofthechassis.
Whentheendaffectertouchesthegrounditispinnedthereandtherobotissaidtobeofftheground.
Inthisstatethegeometryplotsdifferent.Inthisstatethereferencepointistheendaffecterandallthepointsplotinreferencetothat.Thismeansthatthebackpointoftherobotcanmove.Thesimulatedrobotisoutofthisstateifthechassistouchesthegroundagain.Itwillthengobacktousing
thebackoftherobot,whateverlocationitisat,asthereferencelocation.
Figure3.9:Diagramwhichillustratestheanglesusedtodrawtherobot.Thereferencelocationistheend
affectr.
![Page 19: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/19.jpg)
19
SimulatedSensorsOncethegeometryofthesimulatedrobotisknown,afteranupdatecycleiscomplete,thesimulatedsensorscanbeupdated.ThesimulatedrobothasthesamesensorsastherealrobotwhicharelistedinTable2.1.
Theservopositionsensorsarecalculatedafterthefinalpositionofthearmandchassisareknownafter
theupdatecycle.Sincetherealpositionsensorsarenoisey,oncethesensorvalueiscalculatedbasedontheorientationoftheservoGaussiannoisewithastandarddeviationof2isaddedtothevalues.
Whenthesimulatedchassisisonthegroundthecontactsensorreads0.Whenthesimulatedchassisisoffthegroundthecontactsensorreads1.Theforcessensorsattheendofthearmreads400plusarandomnumber~N(0,100)whenitisincontactwiththegroundorchassisandreads990plusarandomnumber~N(0,30)otherwise.Thisagainreflectsthefactthatthereissomenoisewiththeforcesensorreading.Whenthebackofthechassismovesthesimulatortakesthatdisplacementsandcalculateshowmanyturnstheodometerhasmade.Thisisusedtofigureoutwhatthenewodometerreading.Thesimulatedodometerliketherealonerollsoverfrom1023to0.
4.ControlArchitecturesOncetherobotwasfullycompleteddifferentcontrolalgorithmswereexplored.Whilethegoalofthis
projectwastoexploreddifferentlearningalgorithmstwoclassicalcontrolapproacheswerelookedat.LookingatDirectControlandDirectProgramminghelptodebuggingsomeaspectsoftherobotdesignandgainanintuitionabouthowhardtheproblemis.
4.1DirectControlDirectControlreferstorobotsormachinesbeingoperatedbyhumans.TheoperationofconstructionequipmentorunderwaterROV’scanbeseenasthedirectcontrolofrobots.Directcontrolisverysimpletoimplementandwasusedasatestbedtoseeiftherobotcouldactuallycrawl.
ThreepotentiometerswerefedintothePIC.ThepotentiometerscansendacontinuousvoltageintothePICfrom0to5volts.ThePICreadthisvalueinasa10bitnumberandchangesthepulsewidth,
throughtheCCPvalues,foreachservoaccording.0voltscorrespondtoapulsewidthof500microsecondsand5voltscorrespondtoapulsewidthof2500microseconds.Therewasonepotentiometerforeveryservo.
Byturningtheknobsahumanoperatorcanmovethearmoftherobottogetittocrawl.Thiswasnotaneasytaskandtooksometimetolearnhowtocoordinatetheservosandlinkages.Timeseries
imagesoftherobotcrawlingforwardandbackwardareshowninFigure4.1andFigure4.2.CCPvaluesaccordingly.
Figure4.1:Timeseriespicturesoftherobotbeingcontrolledtocrawlforward.
![Page 20: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/20.jpg)
20
Figure4.2:Timeseriespicturesoftherobotbeingcontrolledtocrawlbackwards.
4.2DirectProgrammingUsingthecommandfunctionscreatedinMATLAB,codewaswrittenwhichqueriedthesensorsofthe
robotandactuatedtheservos.Thegoalwastocontroltherobotandhaveitcrawlforward.AflowchartforhowtheprogramworkedisshowninFigure4.3.
Figure4.3:Flowchartshowingtheoperationofthedirectprogrammingcode.
TheflowchartshowninFigure4.3showsaverydeterministalgorithmwhichsimplygoesfromonestatetoanother.Theonlyfeedbackoccursbetweenstates2and3wherelinkage2willrotateCWorCCW
dependingiftherobotisonthegroundornot.Servo3and2arenotwellcoordinatedtooneanother.Theyareactuallycoordinatedtothecontactsensor.Thisapproachproducedacrawlingrobot,butitcrawledfairlyslowly.
![Page 21: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/21.jpg)
21
4.3LearningOnceDirectControlandDirectProgrammingweredonesuccessfullylearningwaslookedat.Inordertoexplorelearningtwotoolsfrommachinelearningwereused,artificialneuralnetworks(ANN),and
geneticalgorithms(GA).TheANNaregoingtobeusedtocontroltherobot.Theyaregoingtomanagetheinteractionbetweentheinputsandoutputs.AGAwillbeusedtotunetheweightsandtopologyoftheANNtodoatask.Forthesesetofexperimentsthetaskistogettherobottomovesomedistance,
eitherforwardsorbackwards.
ANNFigure4.3showsaANNwhichsolvesAND.ThecapabilitiesofthisANNdependontheweightsandtopology.Inordertoproduceacrawlingrobottherightweightsandtopologyneedstobefound.
Figure4.3:Exampleofaartificialneuralnetwork.
GeneticAlgorithmsGeneticalgorithmsaretypeofsearchalgorithminspiredbybiology.Theyarebasedontheideaof
evolution.AgeneticalgorithmwillbeusedtofindtherightweightsandtopologyfortheANN.Foragivenproblem,suchtheonepresentedinFigure4.4,thesolutionsarebrokenintogenotypes.
Figure4.4:Applicationofgeneticalgorithmtoanavigationproblem.
![Page 22: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/22.jpg)
22
Herethegoalisgetthegreenrobotfromthestartlocationtothegoallocation.Thesequenceofstepsittakescanbeencodedintoagenotype.Thesuccessorthefitnessofthisgenotypecanbe
evaluatedbyhowclosethegreenrobotgetstothegoalsquare.Inageneticalgorithmapopulationofrandomgenotypesiscreatedandtheirfitnessisevaluated.The
fitnessfunctionisdifferentforeachtask.Herethefitnessfunctionishowclosethegreenrobotgetstothegoal.Aftereachgenotypeisevaluatedtheoneswiththehighestfitnessareallowedtocrossandproduceoffspringasshowninfigure4.5.Alsothereisachanceformutationoftheoffspring.
Figure4.5:Illustrationofreproductionwithageneticalgorithm.
Ifthisisdonemanytimesovermanygenerationsthefitnessofthepopulationwillslowlyriseuntila
solutionisfoundasshowninFigure4.5.
NEATNEATwhichstandsfortheNeuroEvolutionofAugmentingTopologies,isageneticalgorithmwhich
evolvesneuralnetworks.Theneuralnetworksareencodedusingtheirconnections.Arraysaremadewhichencodethestrengthofeachconnection,thefromandtonodes,itsinnovationnumber,andwhetherornottheconnectionisdisabled.
![Page 23: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/23.jpg)
23
MutationsinNEATaltertheweightsoftheconnectionsaswellasaddmoreconnectionsandnodes.Thisishowthetopologiesoftheneuralnetworksarealtered.Figure4.7illustrateshowconnections
andnodesareaddedtothenetworks.
Figure4.7:DiagramillustratinghowmutationworksinNEAT.TakenfromthepaperonNEAT(4).
Addinganewconnectionisfairlysimple.Thereisnotlimittowhereconnectionscanbeadded.Nodesareaddedwithinconnections.Node6inFigure4.7isaddedinthemiddleoftheconnectionbetween
nodes3and4.Theconnectionanditsweightbetween3and4isreassignedtobebetween3and6andanewconnectionisaddedbetweennodes6and4.
Thealgorithmkeepsarecordofalltheconnectionscreated,andgivesthemanumberbasedontheirorder.Notethattheinnovationnumbersarenottheorderthatconnectionsarecreatedwithinan
individualneuralnetwork.Theyareatheorderconnectionsarecreatedinreferencetotheentireevolutionrun.NEATusestheseinnovationsnumberstolineupthegenotypesoftheneuralnetworksandperformcrossover.Thisisshowninfigure4.8.
Figure4.8:IllustrationsofhowcrossoverworksinNEAT.TakenfromthepaperonNEAT(4).
![Page 24: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/24.jpg)
24
Theinnovationnumbersgiveaframeworkfortakinggeneticinformationfromonepartandmixingitwiththeotherparent.Theconnectionscanbeverycomplexandintricate.Justpickingandswapping
connectionsfromthetwoparentstothemakeachilddoesn’tpreservetheoriginalstructurewhichcontributedtothehighfitnessoftheparents.Usingtheinnovationnumberstoperformcrossoverkeepsthegeneralstructureofeachparent,butallowsamixingofthegeneticinformation.Fromabiological
standpointthisissimilartoonlycrossinggeneswithacommonhistory.Allthegenesassociatedwiththevertebrateofhumansshareasimilarhistorywhileallthegenesassociatedwiththeopposablethumbsofhumansalsoshareacommonhistoryduringevolution.Youwouldwanttocrossthegenesfor
thumbstogetherandthegenesforspinestogether.
4.4MATLABimplementationofNEAT
NEATwasoriginallydevelopedbyKennethStanley.HisimplementationwasoriginallywritteninC++.Ithassincebeenportedtovariouslanguagessuchaspython,Java,andMATLAB.AMATLABimplementationofNEATwasusedforthisproject.ItcanwithasampleexperimentwhichsolvedXOR.
NeuralnetworksetupTheimplementationofXORloadedinputsintotheinputlayeroftheneuralnetworkandwaiteduntil
thevaluesfullypropagatedthroughthenetworkbeforereturningtheoutputs.Itwaiteduntiltheoutputvalueswerestable.Itseemsbiologicallyunrealistictoexpectactivationstoreachtheoutputlayeratthesametimeeventhoughtheytakedifferentlengthsofpathsthroughtheneuralnetwork.Thisalsostops
activationsfromreachingtheoutputwithdifferentdelays.
Thepropagationcodewaschangedtodothefollowing.Eachtimestepthealgorithmgoesthrougheachconnectionandincrementstheactivationofthenodeitisgoingtobytheweightoftheconnectiontimestheactivationofthenodetheconnectioniscomingfrom.Oncealltheconnectionsareallowedto
sendtheirinformationtheoutputisevaluatedandthenextroundofinputsentersthenet.Thecodedoesnotsitthereandwaituntilthevaluesattheoutputnodereachasteadystatebeforeloadinginthenextsetofinputs.
Theneuralnetworksfortheseexperimentshave6inputsnodes,twooutputnodes,andonebias.An
initialneuralnetworkisshowninFigure4.9.Theinputnodesarefullyconnectedtotheoutputnodes.Theconnectionsweightsrangefrom‐1to1.
![Page 25: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/25.jpg)
25
Figure4.9:Initialnetworksetup.
Thesixinputstotheneuralnetwork,fromlefttoright,arethepositionofservo1,2,3.Thereadingfromtheforcesensor,thereadingfromtheodometer,andthecontactsensor.Thetwooutputsgotoservo2andservo3.Thevaluesfromtheoutputnodeswouldbesenttotherobotas‘0030’commands.
ThismeansthatthevalueoutputfromtheneuralnetworkwillincrementordecrementtheCCPvaluesforServos2and3bysomeamount.Thenextsectionontheactivationfunctiongoesintomoredetailonhowtheactivationattheoutputcontrolstheservos.
ActivationfunctionsTheactivationfortheinputnodesinlinearfunctionof1.Thatistheinputvaluesaresimplypassedthe
straighttotheoutput.Beforethesensorsvaluesaresentintotheinputnodestheyarescaledlinearlytobetween0.1and0.9.Forthepositionsensorsthismeanstheyarescalefrom80to400.Fortheforcesensorandodometertheyarescaledfrom0to1023.Andforthecontactsensoritisscaledfrom0to1.
Theactivationofthehiddenandoutputnodesissigmoidfunctioncenteredat0.5.
Figure4.10:Sigmoidfunctionusedastheactivationfunctionofthehiddenandoutputnodes.Imagetakenfrom11http://en.wikipedia.org/wiki/Sigmoid_function
![Page 26: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/26.jpg)
26
Withtheequation
Theinputtoeachnodewasscaledtobebetween‐6and6withtheformula
TheweightCapfortheconnectionsis1becausetheweightscanrangefrom‐1to1.Theactivationfunctionofeachhiddenandoutputnodeisthen
Ifannodefeedingintoanoutputnodeorhiddennodewasfiringatthehighestactivationpossible,whichis1,andtheweightbetweenthatnodeandtheoutputorhiddennodewasatitsmaximumpositivevaluethentheactivationoftheoutputorhiddennodewouldbe1.Ifannodefeedingintoan
outputnodeorhiddennodewasfiringatthelowactivationpossible,whichis0,andtheweightbetweenthatnodeandtheoutputorhiddennodewasatitsmaximumnegativevaluethentheactivationoftheoutputorhiddennodewouldbecloseto0.Allotheractivationsarescaledfromthis.
Theactivationoftheoutputnodesrangesfrom0to1.Aswassaidearlier,theoutputnodeswouldsend
theservowordsforsendinga‘0030’commandtotherobot.Thevalues0and1arescaledlinearlybetween‐999and999beforebeingsenttotherobot.‐999and999arethelargestcommandsthatcanbesenttotherobotwitha‘0030’.Witha‘0030’commandtheoutputnodesareincrementingor
decrementingtheservosbysomevalueeverytimestep.Theyareessentiallysettingthespeedofservo2andServo3.
4.5NEATExperimentTheevolutionexperimentswerenotrunontherealrobot.Thiswouldhavetakenalotoftimeandwouldhaveprobablyresultsintherobotdestroyingitself.Someinitialrunswererunontheactual
physicalrobot.Intheserunstherobotslearnedtohitthemselvestherebyusingtheinertiaoftheimpactandtheirarmtomovebackwards.
Insteadofrunningexperimentsontherealrobotthesimulatordescribedinsection3.4wasused.Thetaskforthisrobotwastomove.Itsfitnesswashowmuchnetdisplacementitgainedin450timesteps.
Thedisplacementismeasuredbythevirtualodometeratthebackofthesimulatedrobot.
Threesetsoffourexperimentswererunwithdifferentmutationrates.MostoftheparametersfromtheXORexperimentswerekept.Theonesalteredatlistedbelow.Theonlydifferencebetweenthethreesetsoffourexperimentsarethemutationrates.
![Page 27: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/27.jpg)
27
ParameterName Value Description
Population_size 30 number_input_nodes 6
number_output_nodes 2
Initial.kill_percentage 0.5Percentageofbottomperformerseliminatedeverygeneration.
selection.pressure 1.95Determinesselectivepressuretowardsmostfitindividualofspecies
mutation.probability_add_node
0.07(Run23‐27)0.03(Run28‐31)0.05(Run31‐35)
mutation.probability_add_connection
0.09(Run23‐27)0.05(Run28‐31)0.07(Run31‐35)
mutation.probability_recurrency 0.05
stagnation.threshold 2500 Thresholdtojudgeifaspeciesisinstagnation.Table4.1:ParametersusedfortheevolutiontrialsthataredifferentfromtheXORsampleexperiment.
Figure4.11showsthemaxfitnessversusgenerationforthethreesetsoffourexperiments.Theyareclearlyverysimilarwhichmeansthatthemutationratesisnotaffectinghowfasttheneuralnetworksarebecomingfit.Atleastnotattheratestested.Thereforefromhereonthethreesetsofdatawillbe
lumpedtogetherandtreatedthesame.
Figure4.11:Fitnessforthedifferentmutationrates.
Theaveragemaxandmeanfitnessareshowninfigure4.12.
![Page 28: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/28.jpg)
28
Figure4.12:Combinedfitnessforallexperiments.
Thefigures4.11and4.12showthattheneuralnetworkswereabletosolvethetaskandevolvecrawling
behavior.Theevolutionrunsarerepeatableandstable.Everyrunproducedresults.
TwodifferenttypesofANNevolved.SomeANNevolvedwhichmadethesimulatedrobotmovebackwards(pushers)andsomeANNevolvedwhichmadethesimulatedrobotmoveforwards(pullers).ForthemostpartmostoftheevolutionrunsproducebackwardorpushingANN.Thedifference
betweenthetwotypesofbehaviorsandwhyonewasmorepreferredthantheotherisdiscussedinthenextsection.
PortingtoRobotSomeofthebestneuralnetworkswereportedontotherealrobot.Quantitativelyit’shardtocomparetheperformanceoftheANNontherealrobotwiththeANNonthesimulatedrobotsothedistance
traveledintherealworldwasn’tcomparedtothedistancetraveledontherealrobot.
QualitativelytheANNworkedbeautifullyontherealrobot.ThepushingandpullingANNmaketherealrobotmoveincrediblefast.ThesesolutionsgoaboutfourtimesasfastastheDirectProgrammingsolution.VideosoftheANNportedtotherealrobotcanbefoundonYouTubebysearchingfor
“crawlingrobot,Lola,NEAT”
5.AnalysisofArtificialNeuralNetworksNEATwassuccessfulatevolvingANNtoproducecrawlingmotion,buthowaretheANNproducingthe
crawlingmotion?HowaretheANNsuccessfullycoordinationthemotionofServo2andServo3?TheanalysisoftheANNrequiredwritingcodewhichplottedtheANNandshowedhowtheinformationwaspropagatingthroughtheANN.Thisanalysisyieldedsomeveryinterestingresultswhichtiebackintothe
earlierdiscussiononlocomotionandoscillators.
![Page 29: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/29.jpg)
29
5.1LocomotionandPatternofActivationAfterthetaskswerecompletedtheartificialneuralnetworkswereanalyzedinordertounderstandhowtheyproducedthecrawlingmotion.Thefollowingimagesshowscreenshotsofthesimulatedrobot
alongsideitsartificialneuralnetwork.Theimagesgostepbystepandshowhowthepatternofactivationofthenodesproduces,inthiscase,pushingmovement.
Figure5.1:SimulatedrobotandANNatt=0.
Att=0bothoutputnodesproducelowactivation.Thisinturnwillcauselinkage3torotatecounter
clockwiseandlinkage2torotateclockwiseasshowninfigure5.1.Thearmwilldoastretchingoutmotionuntilitmakescontactwiththeground.
Figure5.2:SimulatedrobotandANNatt=3.
Att=3thearmmakescontactwiththeground,liftingthechassisofftheground.Thesixthinputnode,
whichcorrespondstothecontactsensorlocatedatthebottomoftherobot,goesfromlowactivation(black)tohighactivation(orange).Astheanimationcontinuestheactivationwillspreadfrominput6tooutput1,tothehiddennode,tooutput2asindicatedbythearrowsinfigure5.2.NEAThas
strengthenedtheseweightsoverthecourseofevolution.
t=0
t=3
![Page 30: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/30.jpg)
30
Figure5.3:SimulatedrobotandANNatt=6.
Att=6theactivationofthetwooutputsisnowhigh.Thiscauseslinkage3torotateclockwiseandlinkage2torotatecounterclockwiseasshowniffigure5.3.Noteittooktwotimestepsfortheactivationfromspreadfromoutput1tooutput2.Thismeansthatlinkage2changeddirections(rotate
counterclockwise)twotimestepsbeforeoutput2.
Figure5.4:SimulatedrobotandANNatt=10.
Att=10thechassismakescontactwiththegroundandinput6getspulledlowasshowninfigure5.4.Theactivationwillnowtravelthroughtheartificialneuralnetworkthesamewayitdidbetweent=3andt=6.Thiswillbringtherobotintoastateseenatt=0,andthemotionwillrepeat.
Thisisanexampleofhowoneoftheartificialneuralnetworkswascontrollingthesimulatedrobotand
makingitpushbackwards.Aftermoreanalysisitwasdiscoveredthatallthepushershadasimilarflowofactivation.
5.2DifferenceBetweenPushersandPullersTheANNanalyzedinsection5.1showsatypicalANNwhichgeneratedpushingmotion.ANNwhichgeneratedpullingmotionalsoevolvedduringtheexperiments.Fundamentallythereisn’tmuch
differencebetweenpushingANNandpullingANN.Figure5.5showsexamplesoftwoANN.OnerepresentsthesimplestpushingANNandonerepresentsthesimplestpullingANN.
t=6
t=10
![Page 31: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/31.jpg)
31
Figure5.5:SimpleillustrationofhowpullingANNdifferedfrompushingANN.TheANNontheleftisapushing
ANN.TheANNontherightisapullingANN.
Asseeninfigure5.5theonlydifferencebetweenpushingANNandpullingANNisthedelayinfiringoutput1andoutput2withrespecttothecontactsensor(input6).ForpushingANNontheleft,output
1willfireonetimedelayafterthecontactsensorfiresandoutput2withfire1plussomedelay,equaltothenumberofhiddennodesbetweenoutput1andoutput2,afterthecontactsensor.ForpullingANNontheright,output2willfireonetimedelayafterthecontactsensorfiresandoutput1withfire1plus
somedelay,equaltothenumberofhiddennodesbetweenoutput2andoutput1,afterthecontact.
5.3ANNandOscillatorsTofurtherelaborateonthedifferencebetweenthepushingandpullingANNandtolinktothediscussionofneuralnetworks,oscillators,andcentralpatterngeneratormentionedintheintroduction,
theactivationofthecontactsensor,output1,andoutput2wasplottedversustimestep.TwoANNandtheplotoftheiractivationsversustimeareshowninfigure5.6andfigure5.7.
Figure5.6:AverysimplepushingANNandaplotofitsactivationversustimesteps.
![Page 32: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/32.jpg)
32
Figure5.7:AverysimplepullingANNandaplotofitsactivationversustimesteps.
ForthepushingANNshowninfigure5.6thedashedline,whichcorrespondstooutput2,firestwotimestepsafterthesolidline,whichcorrespondstothecontactsensor.Thedottedline,whichcorrespondstooutput1,firesonetimestepsafterthesolidline,whichcorrespondstothecontactsensor.Output2
issaidtohaveaphaseshiftoftwowhileoutput1issaidtohaveaphaseshiftofonefromthecontactsensor.
Forthepulling.ForthepullingANNshowninfigure5.7thedashedline,whichcorrespondstooutput2,firesonetimestepsafterthesolidline,whichcorrespondstothecontactsensor.Thedottedline,which
correspondstooutput1,firestwotimestepsafterthesolidline,whichcorrespondstothecontactsensor.Output2issaidtohaveaphaseshiftofonewhileoutput1issaidtohaveaphaseshiftoftwofromthecontactsensor.
ForbothpushingandpullingANNtheoutputnodesareentrainedtothecontactsensor.The
fundamentaldifferencebetweenpullingandpushingANNarethephaseshiftsofoutput1andoutput2withrespecttothecontactsensor.PushingANNseemtohavethephaseshiftofoutput2greaterthanthephaseshiftofoutput1whilepullingANNseemtohavethephaseshiftofoutput1greaterthanthe
phaseshiftofoutput2.
5.4ExploringPhaseShiftsToexplorethisideafurtheraMATLABscriptwaswrittenwhichplantsthesimulatedrobot’sarm,tostarttheoscillation,andthenvariedthephaseshiftsforoutput1and2.Thesimulatedrobotwas
allowedtomovefor450timestepsanditsfitnesswasrecorded.Theresultsforthistestareshownintable5.1.
![Page 33: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/33.jpg)
33
PhaseShiftOutput2 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0Output1
1.0 15.7 109.8 193.8 218.7 238.3 258.2 235.7 254.1 268.8 293.1
2.0 ‐99.5 9.6 112.8 172.6 177.2 227.1 222.7 226.0 245.7 255.83.0 ‐224.7 ‐91.1 11.9 111.5 149.3 177.9 194.8 224.5 223.1 225.14.0 ‐297.0 ‐207.0 ‐58.7 46.2 92.1 152.2 156.8 195.8 201.9 217.45.0 ‐284.2 ‐226.8 ‐161.2 ‐39.5 41.8 105.5 121.3 171.1 184.7 198.16.0 ‐112.4 ‐305.7 ‐227.5 ‐139.5 ‐27.1 30.7 63.6 142.8 160.9 182.07.0 ‐19.2 ‐129.5 ‐286.3 ‐180.5 ‐93.6 ‐27.9 12.9 56.1 131.6 158.58.0 ‐20.1 ‐61.9 ‐159.2 ‐257.4 ‐146.4 ‐79.9 ‐30.8 15.5 85.9 125.29.0 ‐13.8 ‐17.4 ‐63.6 ‐282.1 ‐216.6 ‐158.1 ‐104.1 ‐22.5 37.6 90.9
10.0 ‐15.1 ‐16.3 ‐6.5 ‐125.0 ‐228.6 ‐220.0 ‐151.4 ‐87.8 1.2 32.1Table5.1:Thistableshowsthefitnessvaluesforagivenphaseshiftcombination.
Thehorizontalandverticalaxesontheedgesindicatethephaseshiftordelaybetweeneitheroutput1andthecontactsensororoutput2andthecontactsensor.Thevaluesintheboxesshowthefitness(incentimeters)thatthesimulatedrobotachievedafter450.Thenegativevaluesgrayedoutindicatedthat
thesimulatedrobotmovedbackwards.Table5.1confirmsthepreviousassertionthatpushingANNoccurwhenthephaseshiftofoutput2isgreaterthanthephaseshiftofoutput1.
Table5.1showsthatthechangingofthephaseshiftcangreatlychangethefitness.Thiswasseenin
someoftheevolutiontrialswheretherewerehugespikesoffitness.Figure5.8showsthefitnessversusgenerationofoneoftheevolutionruns.
Figure5.8:Fitnessversusgenerationforexperiment29.Showsthesharpincreasesinfitnessduetoinnovations.
![Page 34: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/34.jpg)
34
Thehugespikeatgeneration50occurredbecausesomeinnovationintheevolution(additionofconnection,node,orchangingofweight)producedanANNwithagoodsetofphaseshifts.Thesame
thinghappensataroundgeneration80.
5.5PushersbetterthanPullersTheadditionofconnections,hiddennodes,andthechangingweightsarerandomeventswhichoccurduringtheevolutionprocess.TherateoftheseeventsarecontrolledbythemutationratessetintheNEATalgorithm.Figure5.9showstwoANNwithsimilarlevelsofcomplexity.Theybothhaveanextra
nodeandtwoextraconnectionsnotfoundintheoriginalANNsetup.
Figure5.9:TwoANNwiththesamelevelofcomplexity.TheoneontheleftispushingANNandtheoneontherightisapullingANN.
TheANNonthelefthasaphaseshiftof[1,3]andbasedonTable5.1wouldhaveafitnessofaround‐224.7.TheANNontherighthasaphaseshiftof[3,1]andafitnessofaround193.8.LookingatTable5.1thistrendisfairlyconsistentwithafewexceptions.ForacertainlevelofcomplexitythepushingANNgo
fasterthanthepullingANN.ThisbecomesobviouswhenlookingatthepatternofactivationsofapushingandpullingANNinfigure5.10.Figure5.10showsthesameoscillatorsinfigure5.6and5.7exceptzoomedout.ItcanbeseenthatthepushingANNundergoesmoreoscillationsorcycles,in100
timesteps,thanthepullingANN.ThismeansthepushingANNgetsmorestrokesinthanthepullingANNwhichiswhytheyareonaveragefasterthanthepullingANN.
Figure5.10:Zoomedoutimagesoftheplotsoftheactivationsshowninfigure5.7and5.8.
![Page 35: Engineering Design: Design and Control of A Simple Robot · Engineering Design: Design and Control ... solution to problems on their own. This has caused many roboticist to draw inspiration](https://reader030.vdocuments.net/reader030/viewer/2022020216/5c5f6cb709d3f20a318b4dc7/html5/thumbnails/35.jpg)
35
ThisisonepossibleexplanationforwhypushingANNaremorecommon,duringtheevolutiontrials,thanpullingANN.Forthesamelevelofcomplexity,thepushingANNareinherentlyfasteranddominate
thepopulationscausingtheextinctionofthepullingANN.
TheincreasednumberofcyclesforapushingANN,whencomparedtoapullingANN,ismostlikelycausedbythegeometryoftherobot.Alterationstotherobot’schassiswerenotexploredinordertotrytoseeifthepullingbehaviorcouldbemadebetterthanthepushingbehavior.
6.ConclusionInthisprojectafairlysimple,yetorthodoxrobotwascreatedquickly.Itprovedtobeveryrobustand
easytoworkwith.Classicengineeringandcomputerscienceapproachestoprogrammingandcontrolwereappliedtotherobotandsatisfactoryresultswereobtained.Controlwaslearningandadaptationusingartificialneuralnetworksandgeneticalgorithmswasthenexploredwithgreatsuccess.This
projectshowedthefeasibilityofamethodlikelearningwithartificialneuralnetworksandgeneticalgorithmstocontrolamobilerobot.
TheANNandGAproducedveryrobustandinterestingsolutionstotheproblem.It’snothardtoimaginetakingtheunderstandinggainedfromtheanalysisoftheANNandreverseengineeringthesolution.
Thatis,takethisideaofthecouplingofinputsandoutputsandoscillatorstohandcodeasolutionwhichwouldworkaswellastheevolvedANN.Theselearningapproacheshaveshownaviablewaytoprogramarobotandlearnnewwaystoconceptualizethecontrolofamobilerobot.
References1.Crespi,A.J.."AmphiBotI:anamphibioussnake‐likerobot."RoboticsandAutonomousSystems
50(2008):163‐175.
2.Crespi,A.J.."Controllingswimmingandcrawlinginafishrobotusingacentralpatterngenerator."AutonomousRobots25(2008):3‐13.
3.Crespi,A.J.."Fromswimmingtowalkingwithasalamanderrobotdrivenbyaspinalcordmodel”SCIENCE315(2007):1416‐1420.
4.Stanley,Kenneth.“Competivecoevolutionthroughevolutionarycomplexification.”JournalofArtifical
IntelligenceResearch,vol21.2004