您好,欢迎来到爱玩科技网。
搜索
您的当前位置:首页A Definition of Abstraction

A Definition of Abstraction

来源:爱玩科技网
Pyro:APython-basedVersatileProgrammingEnvironmentfor

TeachingRobotics

DouglasBlankComputerScienceBrynMawrCollegeBrynMawr,PA19010dblank@cs.brynmawr.edu

DeepakKumarComputerScienceBrynMawrCollegeBrynMawr,PA19010dkumar@cs.brynmawr.eduHollyYancoComputerScienceUniv.ofMass.LowellLowell,MA01854holly@cs.uml.eduSeptember29,2004

LisaMeedenComputerScienceSwarthmoreCollegeSwarthmore,PA19081meeden@cs.swarthmore.edu

Abstract

InthispaperwedescribeaprogrammingframeworkcalledPyrowhichprovidesasetofabstractionsthatallowsstudentstowriteplatform-independentrobotprograms.Thisprojectisuniquebecauseofitsfocusonthepedagogicalimplicationsofteachingmobileroboticsviaatop-downapproach.Wedescribethebackgroundoftheproject,novelabstractionscreated,itslibraryofobjects,andthemanylearningmodulesthathavebeencreatedfromwhichcurriculafordifferenttypesofcoursescanbedrawn.Finally,weexplorePyrofromthestudents’perspectiveinacasestudy.

1Introduction

Notthatlongago,roboticswasafieldofstudyrelegatedtowell-fundedengineeringuniversitiesthatbuilttheirownrobots.Startinginthemid1990’s,simple,inexpensiverobots(suchastheHandyboardandLEGOMindstorms)wereintroducedandtheiruseproliferatedintheclassroom,first,incollegesandlaterevenin

1

middleschools.Currently,sophisticatedrobotswithcameras,advancedsensors,andmotors(suchasSony’srobotdog,Aibo,andActivMedia’sPioneer)arebecomingfinanciallyaccessibletoundergraduatecomputerscience,andevensomecoursesinpsychology.

Althoughsophisticatedroboticplatformsarenowaffordable,alargeissuestillremains:howdoyouteachstudentstousesuchrobots?Unfortunately,eachrobothasitsownapplicationprogramminginterface(API),and,evenworse,eachspecifictypeofsensormayhaveitsownAPI.Thissituationisperhapssimilartotheoneintheearlydaysofdigitalcomputerswheneverycomputerhadadifferentarchitecture,adifferentassemblylanguage,andevenadifferentwayofstoringthemostbasickindsofinformation.

ThePyroprojectwasdesignedtoanswerthequestionofhowtoprogramsophisticatedrobotsbyservingasahigh-levelprogrammingparadigmforawidevarietyofrobotsandsensors.Pyro,whichstandsforPythonRobotics,isaPython-basedroboticsprogrammingenvironmentthatenablesstudentsandresearcherstoexploretopicsinrobotics.ProgrammingrobotbehaviorsinPyroisakintoprogramminginahigh-levelgeneral-purposeprogramminglanguageinthatPyroprovidesabstractionsforlow-levelrobotspecificfeaturesmuchliketheabstractionsprovidedinhigh-levellanguages.Consequently,robotcontrolprogramswrittenforasmallrobot(suchasK-Team’shockeypuck-sized,infrared-basedKheperarobot[7])canbeused,withoutanymodifications,tocontrolamuchlargerrobot(suchasActivMedia’shuman-scale,laser-basedPeopleBot[1]).Thisrepresentsanadvanceoverpreviousrobotprogrammingmethodologiesinwhichrobotprogramswerewrittenforspecificmotorcontrollers,sensors,communicationsprotocolsandotherlow-levelfeatures.

Programmingrobotbehaviorsiscarriedoutusingtheprogramminglanguage,Python,whichenablesseveraladditionalpedagogicalbenefits.Wehavedevelopedanextensivesetofrobotprogrammingmodules,modelingtechniques,andlearningmaterialsthatcanbeusedingraduateandundergraduatecurriculainvariousways.InthefollowingsectionswepresentanoverviewoftheabstractionsincorporatedintoPyro

2

thathavemadeitpossibletomakerobotprogramsportableacrossplatforms.NextweexploreseveralexamplesthatillustratetheeaseofuseofPyroindifferentmodelingsituations.Finally,weexaminetheroleofPyroincomputersciencecurriculabypresentingadetailedcasestudyofitsuseinanartificialintelligencecourse.

2OverviewofPyro

TheneedforaprojectlikePyrogrewoutofourdesiretoteachmobileroboticsinacoherent,abstract,robot-independentmanner.Forexample,wewishedtostartwithsimple“directcontrol”programsrunningonsimplerobotsandincrementallytakestudentsonatourofothercontrolparadigmsrunningonincreasinglysophisticatedrobots.Therearemanyexcellent,freelyavailable,real-worldcontrolsystemswhichonecandownload,programandrun.Forexample,CarnegieMellonhasmadetheirRobotNavigationToolkit(a.k.a.CARMEN)availableasopensource[8],andActivMedia’sARIAisalsofreelyavailable[1].However,allsuchprogramsthatweencounteredsufferedfromthreeseparateproblems.

Mostexistingrobotcontrolprogramsaredesignedtorunonasingletypeofrobot.Atbest,someoftherobotcontrolsystemswefoundranonafewtypesofrobots,buteventhenthetypeshadtobeofsimilarsize,shape,andabilities.Second,wewantedthecontrolsystemtobesomethingthatcouldbestudied,andchanged,bythestudents.Alloftheexistingsystemsweencounteredweredesignedtobeasefficientaspossible,andwerethereforefilledwithoptimizationswhichobfuscatedtheiroveralldesigntothestudent.Inaddition,wewereunabletofindasystemforwhichwecouldeasilyseparatethe“controller”fromtherestofthesystem.Forexample,acontrolsystembasedonoccupancygridsmightbeintimatelytiedtoaparticulartypeofrobotandlaserscanner.

Itwasnottoosurprisingthatwecouldnotfindasystemthatdidnothavetheseproblems;mostoftheseprojectswereresearchexplorationsofaparticularparadigmrunningonaparticularrobot.However,evenif

3

wecouldhavefoundaseriesofprogramstorunonourrobots,wewouldnothavebeenabletoincrementallymakesmallchangestothecontrollertotakeusfromoneparadigmtoanother,norwouldwehavebeenabletomixpartsofoneparadigmwithpartsofanother.However,thereweretwoprojectsthatdidmetsomeofourrequirements.

ThefirstoftheseisTeamBots[2].TeamBotsiswritteninJava,and,therefore,isobject-orientedwiththepossibilityofmanyappropriateabstractionsforteaching.TeamBotswasdesignedsuchthatthehardwareinterfacesandcontrollersareindependentofoneanother.Thus,onecanwriteacontrolprogramwithoutworryingaboutlow-leveldetailsoftheparticularrobotthatitiscontrolling.AtthetimeTeamBotswaswritten(1997–2000)theideaofusingJavatocontrolmobileroboticswasquiterevolutionary.However,theTeamBotauthorsarguedthat“thebenefitsofJava(correctness,easeofuse,rapiddevelopment)faroutweighthenegligibleruntimeoverhead”[?].Weverymuchagreewiththisphilosophy.Infact,wewantedtotakethephilosophyof“ease-of-useoverruntimeconsiderations”evenfurther.AlthoughJavaisarguablyeasiertousethan,say,CorC++,itstillhasalargeconceptualoverhead.

TheotherprojectthatmetsomeofourrequirementswasthePlayer/Stageproject[4]whichwasfirstreleasedin2001.Player/Stageisactuallythreeseparateprojects:Player,whichisanevolvingsetofclient/serverprotocolsforcommunicatingwithrobotsandsimulators;Stage,a“low-fidelity”,2-Dmulti-robotsimulator;andGazebo,a“high-fidelity”,3-Dsimulator.BecausethePlayer/Stageauthorshavetheirsoftwarerunningonsomanydifferentkindsofrobots,theyhavedevelopedmanyusefulrobotandsen-sorabstractions.WhereasTeamBotsonlysupportedtwodifferentkindsofrobots(Probotic’sCyeandthenowdefunctNomadicTechnologiesNomad150),Player/Stagesupportsliterallydozensofrobots:fromK-Team’sKheperatoSegway’sRMP(acustomizedversionoftheirHumanTransport).However,allofPlayer/StageiswrittenintheClanguageandisdesignedtooperateasefficientlyaspossible.Althoughsuchefficiencyisrequiredbymanycontrolsystems,suchoptimizedcodeoftenobfuscatesthehigh-leveldesign

4

concepts.Asmentioned,wewereverywillingtotradeease-of-use(andease-of-understanding)forruntimeefficiency.Player/Stagewasnotdesignedtobeusedbynoviceprogrammers.

Intheend,wedecidedtobuildourowncontrolsystem.WecreatedaprototypeusingtheextensiblemodelinglanguageXMLincombinationwithC++[3].Basically,thecodelookedlikeHTMLwithC++codebetweenthetags.AlthoughthissystemhadsomenicequalitiesderivedfromitsXMLroots,itturnedouttohaveallthecomplexitiesofXMLandC++combined,andwasthereforedifficultforstudentstolearnanddebug.Forexample,evensyntaxerrorscouldbehardtotrackdownbecausethereweretwolevelsofparsing(oneattheXMLlevel,andanotherattheC++level).Inaddition,likemanyoftheotheravailablecontrolsystems,webecameboggeddowninlow-levelinterfaceissuesandneverreachedthepointofimplementingmorethanonecontrolparadigm.

Havinglearnedfromthisprototype,wedecidedtotryagain,butthistimethecompletefocuswasontheusabilityfromthestudentperspective.WefoundthatthelanguagePythonmetmanyofourgoals.Tooursurprise,wealsofoundthatPythonhadrecentlybeenusedforsolvingreal-worldcomplexprogrammingproblems.Forexample,[11]foundinsomespecificsearchingandstring-processingteststhatPythonwasbetterthanJavaintermsofrun-timeandmemoryconsumption,andnotmuchworsethanCorC++insomesituations.Inthisincarnation,wesetoutwiththefollowinggoals:•beeasyforbeginningstudentstouse

•provideamodernobject-orientedprogrammingparadigm•runonseveralrobotplatformsandsimulators

•allowtheexactsameprogramtocontroldifferentkindsofrobots

•allowexplorationofmanydifferentrobotcontrolparadigmsandmethodologies

5

print’Helloworld!’defhelloWorld():

print’Helloworld!’helloWorld()

=>Helloworld!

=>Helloworld!

classHelloWorld:

defgreet(self):

print’Helloworld!’

obj=HelloWorld()obj.greet()=>Helloworld!

Figure1:Pythonscalesuppedagogically.Threedifferentparadigmsforgreetingtheworld:direct,func-tional,andobject-oriented.

•scaleupconceptuallybyremainingusefulasusersgainexpertise•beextendible

•allowforcreationofmodern-lookingvisualizations•beavailablefreelyforstudy,use,andfurtherdevelopment

Pythonisanideallanguageforimplementingthesegoals.Infact,Pythonitselfisdrivenbysimilarideals.Forexample,Pythonsupportsmanydifferentprogrammingparadigmswithoutmakingstringcom-mitmentstoany.AlthoughonecanwritecompletePythonprogramswithoutevendefiningafunction,onecanalsousefunctionsasfirst-classobjects.Astheusergrowsinsophistication,socanthelanguage.Figure1showsthreeparadigmsforprinting“Helloworld!”:asimple,directmethod;amethodusingfunctions;andanobject-orientedmethod.Onecanseethatmorecomplexparadigmsbuildonsyntaxandconceptsfromsimplerparadigms.Java,ontheotherhand,doesnotallowstudentstostartwithsimpleexpressionsandstatementsandslowlyincreaseconceptsandsyntax,butratherforcestheusertoembracethefullobject-orientedmethodologyfromsquareone.

6

Figure2:PyroArchitecture

PyroiscomposedofasetofPythonclassesthatencapsulateslower-leveldetails.Figure2providesaschematicofthePyroarchitecture.Userswriterobotcontrolprogramsusingasingleapplicationprogram-minginterface(API).TheAPIisimplementedasanobject-orientedhierarchythatprovidesanabstractionlayerontopofallthevendor-suppliedrobot-specificAPI’s.Forexample,inFigure2,alltherobot-specificAPI’shavebeenabstractedintotheclasspyro.robot.Inaddition,otherabstractionsandservicesareavailableinthePyroLibrary.Thelibrarieshelpsimplifyrobot-specificfeaturesandprovideinsulationfromthelowestleveldetailsofthehardwareorsimulationenvironments.

Currently,PyrosupportsK-Team’sKheperas,ActivMedia’sPioneer-classrobots(includingPeopleBotandAmigoBotrobots),Player/Stage-basedrobots(includingEvolution’sER1andmanyothers),theHandy-board,RWI’sMobility-basedB21R,andsimulatorsforallofthese.Currently,manyotherrobotsarealsobeingportedtoPyro,includingSony’sAibo,K-Team’sinexpensiveHemisson,andtheRobocupSoccerServerSimulator.

7

Auser’scontrolprogramforarobotiscalledabrain.EachbrainiswrittenbyextendingthelibraryclassessimilartothewayaJavaprogrammerwritesJavaprograms.Thisallowsarobotprogrammertoconcentratemainlyonthebehavior-leveldetailsoftherobot.SincethecontrolprogramiswritteninPython,thestandardPythonLibraryisalsoavailableforuse.Also,becausethebrainbaseclassisalsoPythoncode,newcontrolparadigmscanbeeasilyaddedandstudied.Beforewegoanyfurther,wewouldliketopresentasimpleexampleofarobotcontrolprogram.

2.1AFirstLook

InthissectionwepresentasimpleobstacleavoidancebehaviortodemonstratetheunifiedframeworkthatPyroprovidesforusingthesamecontrolprogramacrossmanydifferentrobotplatforms.Thistypeofsimplecontrollerisanexampleof“direct”(or“stateless”)control.Directcontrolisnormallythefirstcontrolmethodintroducedtostudentslearningrobotics.Inthissimpleformofcontrol,sensorvaluesareusedtodirectlyaffectmotoroutputs.ThetopfivelinesofFigure3showpseudocodethatrepresentsaverysimplealgorithmforavoidingobstacles.

TheprogramshowninthelowerportionofFigure3implementsthepseudocodealgorithmusingtheabstractionsinthelibraries.Theprogram,writteninanobject-orientedstyle,createsaclasscalledAvoidwhichinheritsfromaPyroclasscalledBrain(Figure3,line2).EveryPyrobrainisexpectedtohaveastep(line3)methodwhichisexecutedoneverycontrolcyclewhichoccurabout10timesasecond.Thebrainshownwillcausetherobottocontinuallywanderandavoidobstaclesuntiltheprogramisterminated.

ItisnotimportanttounderstandallthedetailsofPyroimplementation,butthereadershouldnoticethattheentirecontrolprogramisindependentofthekindofrobotandthekindofrangesensorbeingused.TheprogramwillavoidobstacleswhentheyarewithinthesafeDistanceof1robotunit(discussedbelow)oftherobot’sfrontleftorfrontrightrangesensors(lines6and9,respectively),regardlessofthekindof

8

#####1234567101112131415

ifapproachinganobstacleontheleftside

turnright

elseifapproachinganobstacleontherightside

turnleftelsegoforward

frompyro.brainimportBrainclassAvoid(Brain):

defstep(self):

safeDistance=1#inRobotUnits

#ifapproachinganobstacleontheleftside,turnright

ifmin(self.get(’robot/range/front-left/value’))self.robot.move(0,-0.3)

#elseifapproachinganobstacleontherightside,turnleft

elifmin(self.get(’robot/range/front-right/value’))self.robot.move(0,0.3)#elsegoforwardelse:

robot.move(0.5,0)

defINIT(engine):

returnAvoid(’Avoid’,engine)

Figure3:Anobstacleavoidanceprogram,inpseudocodeandinPyro

robot.Lines14and15showthedetailsofPyro’sautomaticinitializationmechanism.Suchlineswillbeleftoutinsubsequentexamples.

3ADesignandDevelopmentPerspective

MostofthePyroframeworkiswritteninPython.Asonecansee,Pythonisaneasy-to-readscriptinglanguagethatlooksverysimilartopseudocode.ItalsointegrateseasilywithCandC++codewhichmakesitpossibletoquicklyincorporateexistingcode.TheC/C++interfacealsofacilitatestheinclusionofveryexpensiveroutines(likevisionprograms)atlowerlevelsforfasterruntimeefficiency.Also,weareableto“wrap”programswritteninCandC++(suchasPlayer/Stage)sothattheyareinstantly,andnatively,availableinPython.

9

OneofthekeyideasunderlyingthedesignofPyroisthesetofabstractionsthatmakethewritingofbasicrobotbehaviorsindependentofthetype,size,weight,andshapeofarobot.Considerwritingarobotcontrollerforobstacleavoidancethatwouldworkona24-inchdiameter,50-poundPioneer3robotaswellasona2.5-inchdiameter,3-ounceKhepera.Thefollowingkeyabstractionswereessentialinachievingourdesigngoals:

RangeSensors:Regardlessofthekindofhardwareused(IR,sonar,laser)sensorsarecategorizedasrange

sensors.Sensorsthatproviderangeinformationcanthusbeabstractedandusedinacontrolprogram.RobotUnits:Distanceinformationprovidedbyrangesensorsvariesdependingonthekindofsensors

used.Somesensorsprovidespecificrangeinformation,likedistancetoanobstacleinmetersormillimeters.Otherssimplyprovideanumericvaluewherelargervaluescorrespondtoopenspaceandsmallervaluesimplynearbyobstacles.Inourabstractions,inadditiontothedefaultunitsprovidedbythesensors,wehaveintroducedanewmeasure,arobotunit:1robotunitisequivalenttothediameteroftherobotbeingcontrolled.

SensorGroups:Robotmorphologies(shapes)varyfromrobottorobot.Thisalsoaffectsthewaysensors,

especiallyrangesensors,areplacedonarobot’sbody.Additionally,thenumberandpositionsofsensorspresentalsovariesfromplatformtoplatform.Forexample,aPioneer3has16sonarrangesensorswhileaKheperahas8IRrangesensors.Inordertorelieveaprogrammerfromtheburdenofkeepingtrackofthenumberandpositionsofsensors(andtheiruniquenumberingscheme),wehavecreatedsensorgroups:front,left,front-left,etc.Thus,aprogrammercansimplyqueryarobottoreportitsfront-leftsensorsinrobotunits.Thevaluesreportedwillworkeffectivelyonanyrobot,ofanysize,withanykindofrangesensorgivenappropriatecoverage,yetwillbescaledtothespecificrobotbeingused.

10

MotionControl:Regardlessofthekindofdrivemechanismavailableonarobot,fromaprogrammer’s

perspective,arobotshouldbeabletomoveforward,backward,turn,and/orperformacombinationofthesemotions(likemovingforwardwhileturningleft).Wehavecreatedtwomotioncontrolabstrac-tions:move(translate,rotate)andmotors(leftpower,rightpower).Theformerabstractsmovementsintermsofturningandforward/backwardchanges.Thelaterabstractsmovementsintermsofapplypowertotheleftandrightsides.Thisisdesignedtoworkevenwhenarobothasadifferentwheelorganization(suchasmulti-wheel,omni-directionalabilities)orfourlegs(aswithAibo).Asinthecaseofrangesensorabstractions,thevaluesgiventothesecommandsareindependentofthespecificvaluesexpectedbytheactualmotordrivers.Aprogrammeronlyspecifiesvaluesinarange-1.0..1.0(seeexamplesbelow).

Devices:Theabstractionspresentedaboveprovideabasic,yetimportantfunctionality.Werecognizethat

therecanbeseveralotherdevicesthatcanbepresentonarobot:agripper,acamera,etc.Wehavedevisedadeviceabstractiontoaccommodateanynewhardwareoradhocprogramsthatmaybeusedinrobotcontrol.Forexample,acameracanbeaccessedbyadevicethatenablesaccesstothefeaturesofthecamera.Further,studentscanexplorevisionprocessingbydynamicallyandinteractivelyapplyingfilters.Filtersaremodularimage-processingfunctionsthatcanbesequentiallyappliedtocameraimages.Alldevicesareaccessedusingthesameuniforminterfacemetaphor.

Theaboveabstractionsaresimilartotheabstractionsonetakesforgrantedinahigh-levelprogramminglanguage:datatypes,I/O,etc.Theseabstractionshelpsimplifyindividualrobotsintohigher-levelentitiesthatareneededinorderforgenericbehaviorprogramming.

Pyroalsoprovidesfacilitiesforthevisualizationofvariousaspectsofarobotexperiment.UserscaneasilyextendthevisualizationfacilitiesbyprovidingadditionalPythoncodeasneededinaparticularex-

11

Figure4:Dynamic3-DvisualizationofaKheperaanditsinfraredsensors.

periment.Forexample,youcaneasilycreateagraphtoplotsomeaspectofabrain,orsensor,withjustafewlinesofcode.Inaddition,Pyrocan,throughPython’sOpenGLinterface,generatereal-time3Dviews.Figure4showsavisualizationofaKheperarobotanditsinfraredreadings.InkeepingwiththespiritofthePyroproject,wecreatedanabstractAPIsothat3DshapescanbedrawninthiswindowwithoutknowinganythingaboutOpenGL.

ThePythonlanguagehasgeneratedmuchinterestinrecentyearsasavehicleforteachingintroductoryprogramming,object-orientedprogramming,andothertopicsincomputerscience.Forexample,PeterNorvighasrecentlybegunportingtheexamplecodefromRussellandNorvig’s“ArtificialIntelligence:AModernApproach”[12]intoPython.ThiswillnodoubtbolsterPython’suseinAI.BecausePyroisimplementedinPython,everythingthatappliestoPythonalsoappliestoPyro,bothgoodandbad.Pythonappearstobealanguagethatinexperiencedundergraduatescanpickupquickly.Thelanguageisobject-orientedwithoutanylimitationsonmultiple-inheritance,andmostobjectsarefirst-class.However,because

12

Updates/second

+10,000

BarebrainwithOpenGL

+200

FuzzylogicwithOpenGL

lessthan1

frompyro.brainimportBrainfromrandomimportrandomclassWander(Brain):

defstep(self):

safeDistance=0.85#inRobotUnits

l=min(self.get(’robot/range/front-left/value’))r=min(self.get(’robot/range/front-right/value’))f=min(self.get(’robot/range/front/value’))if(fif(random()<0.5):

self.robot.move(0,-random())else:

self.robot.move(0,random())

elif(lself.robot.move(0,-random())elif(rself.robot.move(0,random())

else:#nothingblocked,gostraight

self.robot.move(0.2,0)

Figure5:Awanderprogram

havemodulesforevolutionarysystems,includingthegeneticalgorithm,andgeneticprogramming.Thevisionmodulesprovidealibraryofthemostcommonlyusedfiltersandvisionalgorithmsenablingstudentstoconcentrateontheusesofvisioninrobotcontrol.Theentirelibraryisopensource,welldocumented,andcanbeusedbystudentstolearnabouttheimplementationsofallthemodulesthemselves.Wehavealsoprovidedtutorialleveleducationalmaterialsforallthesemodules.ThisenablesinstructorstotailortheuseofPyroformanydifferentcurricularsituations.Astheprojectmovesbeyondtheinitialproductionphase,weexpecttoaddmanymoremodules.Withincreaseduseinthecommunitywealsoexpectcontributedmodulestobeaddedtothelibrary.Intheremainderofthissection,weprovideafewmoreexamplesofrobotcontrolwrittenusingtheavailablelibraries.AllexamplesareactualworkingPyroprograms.

Asmentioned,wehavedesignedthehighestlevelrobotclasstomakeabstractionssuchthatprograms,whenwrittenappropriately,canrununchangedonavarietyofplatforms.Forexample,considerthePyro

14

codeinFigure5.ThisshortprogramdefinesabraincalledWanderthatenablesarobottomoveaboutwith-outbumpingintoobjects.Theprogramrunsonthesuitcase-sizedPioneerand,withoutanymodifications,onthehockeypuck-sizedKhepera.Asmentioned,therearetwomechanismsthatallowthisportability.First,allunitsreturnedfromanyrangesensorsare,bydefault,giveninrobotunits.Forexample,1Kheperaunitisequaltoabout60mm,while1Pioneerunitisequaltoabout2feet.Secondly,wetrytoavoidre-ferringtospecifickindsorpositionsofsensors.Forexample,intheaboveexample,werefertothedefaultrangesensorvaluesbynamessuchasfront-left.OnthePioneerthiscouldbemeasuredbythreesonarsensors,whileontheKheperaitcouldbemeasuredbyasingleinfraredsensor.Althoughthesemechanismshavetheirlimitations,manyroboticsproblemscanbehandledinthismanner.

ContrastthewanderprogramwiththeprograminFigure6whichtrainsanartificialneuralnetworktoavoidobstacles.Again,thecodeisquiteshort(about30lines)butincludeseverythingnecessarytoexploreanexampleofon-lineANNlearningonarobot.Thegoalofthisbrainistoteachaneuralnetworktogoforwardwhenitisnotclosetoanyobstacles,buttostopandturnawayfromobstaclesthatarewithinonerobotunit.Thenetworktakesthecurrentrangevaluesasinputsandproducestranslateandrotatemovementsasoutputs.Withlearningturnedon,thenetworklearnstodowhattheteacherfunctiontellsittodo.Turnofflearningaftertrainingandthenetworkshouldapproximate(andgeneralize)theteacher’srules.

EveryPyrobrainmayincludetheoptionalsetupmethodforinitialization;itisonlycalledoncewhenthebrainisinstantiated.IntheNNBrain,thesetupmethodisusedtocreateaninstanceoftheNetworkclasswhichisathree-layerfeedforwardnetworkwherethesizeoftheinputlayerisequaltothenumberofrangesensorsonthecurrentrobotbeingcontrolled.Eachtimethebrain’sstepmethodiscalled,therobot’srangesensorsarecheckedandtargetvaluesfortranslateandrotatearedetermined.Thentherangevaluesarenormalizedusingthescalemethodtopreparethemasinputsfortheneuralnetwork.Next,thenetwork’sstepmethodiscalledtopropagatethegiveninputsthroughthenetwork,back-propagatethe

15

frompyro.brainimportBrainfrompyro.brain.conximport*classNNBrain(Brain):

defsetup(self):

self.net=Network()

self.net.addThreeLayers(self.get(’robot/range/count’),2,2)self.maxvalue=self.get(’robot/range/maxvalue’)defscale(self,val):

return(val/self.maxvalue)defteacher(self):

safeDistance=1.0

ifmin(self.get(’robot/range/front/value’))trans=0.0

elifmin(self.get(’robot/range/back/value’))trans=1.0else:

trans=1.0

ifmin(self.get(’robot/range/left/value’))rotate=0.0

elifmin(self.get(’robot/range/right/value’))rotate=1.0else:

rotate=0.5

returntrans,rotatedefstep(self):

ins=map(self.scale,self.get(’robot/range/all/value’))targets=self.teacher()

self.net.step(input=ins,output=targets)

trans=(self.net[’output’].activation[0]-.5)*2.0rotate=(self.net[’output’].activation[1]-.5)*2.0robot.move(trans,rotate)

Figure6:Aneuralnetworkcontroller

16

frompyro.geometryimport*

frompyro.brain.behaviors.fsmimportState,FSMBrainclassedge(State):

defonActivate(self):

self.startX=self.get(’robot/x’)self.startY=self.get(’robot/y’)defupdate(self):

x=self.get(’robot/x’)y=self.get(’robot/y’)

dist=distance(self.startX,self.startY,x,y)ifdist>1.0:

self.goto(’turn’)else:

self.robot.move(.3,0)

classturn(State):

defonActivate(self):

self.th=self.get(’robot/th’)defupdate(self):

th=self.get(’robot/th’)

ifangleAdd(th,-self.th)>90:

self.goto(’edge’)else:

self.robot.move(0,.2)

defINIT(engine):

brain=FSMBrain(engine)

brain.add(edge(1))#1meansinitiallyactivebrain.add(turn())returnbrain

Figure7:Afinitestatemachinecontroller

errorbasedonthegiventargets,andupdatetheweights.Finallythenetwork’soutputsareusedtomovetherobot.Inthiswaytherobotislearningonlinetoperformobstacleavoidance.

Thenextexample,showninFigure7,usesafinitestatemachinetocontrolarobot.AFSMbrainisassumedtoconsistofasetofstates.EachstatehasanonActivatemethodthatiscalledwhenthestatebecomesactiveandanupdatemethodthatiscalledoneachbrainstep.Astatecanrelinquishcontrolbyusingthegotomethodtoactivateanewstate.Theprogrammer’sjobistodefineanappropriatesetofstatestosolveagivenproblem.

17

Inthisexample,thegoalistocontroltherobotsothatitcontinuallymovesinasquare.Inthiscase,twostateshavebeendefined:onetocontroltherobotwhileittraversestheedgeofthesquareandasecondtocontroltherobotwhileitturns.Initiallytheedgestateisactivated.Intheedgestate,thestartingpositionoftherobotissavedandcomparedtothecurrentposition.Oncetherobothastraveledthelengthofonerobotunit,theedgestateactivatestheturnstate.Intheturnstate,thestartingheadingoftherobotissavedandcomparedtothecurrentheading.Oncetherobothasturnedninetydegrees,theturnstatere-activatestheedgestate.Byrepeatingthissequenceofstates,therobotwilltravelinthedesiredsquaremotion.

ThissectionhasprovidedasampleofthevarietyofrobotcontrolprogramsthatcanbeexploredfromwithinPyro.ThenextsectionoutlineswaysPyrocanbeincorporatedintoexistingcoursesinthecurriculum.

5IntheCurriculum

BecausePyroallowsstudentstoimmediatelyfocusonthemostabstract,top-downissuesinautonomouscontrol,wehavebeenabletoincorporatePyrointoavarietyofcourses.Manyofthesecourseshavebeentaughttostudentswithlittletonobackgroundinprogramming.PyrohasbeenincorporatedintheundergraduatecurriculumatBrynMawrCollege,SwarthmoreCollege,andtheUniversityofMassachusettsLowell(UML).Additionally,ithasbeenusedatatleasttenotherinstitutions.AtUML,ithasalsobeenusedinthegraduatelevelcourses.Specifically,Pyrohasbeenincorporatedintothefollowingcourses:IntroductiontoArtificialIntelligence:Astandardelectivecourseinthecomputersciencecurriculum.

ThiscoursehasbeenofferedatSwarthmoreCollegeandBrynMawrCollege.

CognitiveScience:Anelectiveincomputerscienceandpsychology.ThiscourseisofferedatBrynMawr

College.

Emergence:Anelectivecoursethatstudiesemergentcomputationandemergentphenomena.Additional

18

Pythoncodehasbeendevelopedtoexplorerelatedtopics,suchasbirdflockingbehavior,andcellularautomata.ThiscourseisofferedatBrynMawrCollege.

Androids:Design&Practice:Anupper-levelelectiveonrecentadvancesinrobotics.Thiscourseisof-feredatBrynMawrCollege.

DevelopmentalRobotics:Anotherupper-levelelectiveonrecentadvancesinrobotics.Thiscoursehas

beenofferedatBrynMawrCollegeandSwarthmoreCollege.

RoboticsII:ThisisasecondundergraduatecourseinRoboticsattheUniversityofMassachusettsLowell

(UML).

MobileRobotics:Thisisagraduate-levelcourseofferedatUML.

SeniorTheses:StudentsatseveralinstitutionshaveusedPyroasapartoftheircapstoneprojects.SummerResearch:StudentsatseveralinstitutionshaveusedPyroasapartoftheirsummerresearch

projectsattheundergraduateandgraduate-level.Additionally,somehighschoolstudentshavealsousedPyrointheirsummerresearchprojects.

Itisclearthatwhereverinthecurriculumroboticsisused,Pyrocanbeusedasalaboratoryenvironment.Inalloftheaboveinstances,studentswroteseveralrobotcontrolprogramsforrealandsimulatedrobots.Inmostofthesecases,studentslearnedPyroandrobotprogrammingbyfollowingthetutorialmaterialswehavecreated.However,thekindsofexercisesvarieddependingonthecourseanditsfocus.

Thestudentprojectsfromthesecoursesspanalargerangeofcomplexity.Forexample,inthecognitivesciencecourse,manystudentshadneverwrittenaprogrambefore.However,theywereeasilyabletotakesimplereactivebrains,suchasthoseshownabove,tweakthem,andaskobserverstheirimpressionoftherobot’sbehavior.Ontheotherhand,advancedcomputersciencestudentsintheDevelopmentalRobotics

19

courseswereabletoperformresearch-levelprojectsratherquickly.Forexample,studentswereabletowritePyroprogramstoco-evolvepredator-preycontrollersinamatterofdays.Otherexamplesincluded:

•Lasertag:Agroupofstudentsdesignedhardwaretosendandreceiveinfraredsignals,thenwrotesoftwaretomakethegame-playingrobotslocateandtargeteachother.

•Addingsensorstoaresearchplatform:Astudentdesignedacircuitboardtoallowadditionalsensorstobeaddedtoaresearchrobotusingaserialportontherobot.Thestudentalsowrotecontrolcodefortherobot.Thisprojectwasusedinthelasertagprojectabove.

•RobotSlalom:Severalteamsofstudentsdesignedprogramsthatusedcomputervisiontofindgatesinaslalomcoursethatrandownahallway(andaroundcorners).

•PickUptheTrash:Severalteamsofstudentsdesignedprogramsusingcomputervisiontofindtrash(styrofoamcups)andrecycling(sodacans)anddeliverthefounditemstotheappropriatebins(trashcanorrecyclingbin).

•RobotTourGuide:AgroupofundergraduatestudentscreatedarobotthatgivestoursoftheParkScienceBuildingatBrynMawrCollege.

ThelastprojectlistedabovewasdonebythreeundergraduatestudentsandwaspartiallyfundedbyagranttothemfromtheComputingResearchAssociation’sCREWprogram[10].Ineachoftheaboveinstances,wehavecarriedoutextensiveevaluationsontheimpactofusingPyroineachcourse.Next,wepresentonesuchcasestudy.

20

6CaseStudy:AnArtificialIntelligenceCourse

OnewaytoevaluatewhetherPyroissuccessfulatachievingitsgoalofprovidingundergraduateswithaneffectivetoolforexploringadvancedroboticsistoconsiderhowwellitcanbeintegratedintoanAIcourse.InthissectionwewilllookindetailataparticularAIcourse,andexaminethelevelofsophisticationoftheroboticsprojectsattemptedbythestudents.WewillalsosummarizestudentcommentsonusingPythonandPyro.

AtSwarthmoreCollege,theAIcourseistypicallytaughteveryotheryearandisintendedforComputerSciencemajorswhohavealreadytakenaCS1courseinanimperativelanguageandaCS2courseinanobject-orientedlanguageasprerequisites.TheAIcoursewasupdatedinSpring2004toincorporatePythonandPyrointoeverylabandproject[5].Thisparticularofferingofthecoursehadamachinelearningfocuscoveringgameplaying,neuralnetworks,geneticalgorithms,decisiontrees,reinforcementlearning,androbotics.Studentsmettwiceaweekforlectureanddiscussionandonceaweekforlab.

ThelabsweredesignedtointroducethestudentstothePythonprogramminglanguage,thetoolsavail-ablewithinPyro,andthemachinelearningtopicsbeingcoveredinclass.Mostlabswererelativelyshortinduration,typicallylastingonlyaweek.Theprojectsweredesignedtoallowthestudentstoexploreamachinelearningtopicinmuchmoredepthandlastedtwotothreeweeks.Forthefirsttwoprojects,thestu-dentsweregivenatleastonedefaultoptionthattheycouldimplement,butwerealsoencouragedtodeveloptheirownideasintoaproject.Forthefinalproject,thestudentswereexpectedtogeneratetheirownprojectproposal.Allstudent-generatedproposalsrequiredpre-approvalbytheinstructortoensurethattheywerefeasible.Eachprojectculminatedinafourtosixpagepaperdescribingthemachinelearningproblem,theexperimentaldesign,andtheresults.

Theclassincludedsixlabsandthreeprojects.Forthelargerlabsandprojects,thestudentswereallowed

21

toworkinteamsoftwoorthree.Thefirstprojectinvolvedapplyinganeuralnetworktoaproblem.Thedefaultoptionwastouseadatabaseoffacialimages,describedbyMitchellinChapter4ofhismachinelearningtextbook[6],tolearnfeaturessuchasposeorexpression.Thesecondprojectinvolvedapplyingageneticalgorithmtoaproblem.ThedefaultoptionwastotrytofindsolutionstothetravelingsalesmanproblemforparticularcountriesintheworldortoattemptoneofthecontestssponsoredbyCongressonEvolutionaryComputation[9]whichincludedgrowingvirtualplants,predictingbinaryseries,andcreatingart.ThefinalprojectinvolvedrobotlearningonasimulatedPioneer-stylerobotwithsonarsensors,blobvision,andagripper.

Forthefinalprojectonrobotlearning,themajorityofthestudentsintheclasschoseataskinwhichtherobotwouldbecontrolledbyaneuralnetworkandtheweightsofthenetworkwouldbeevolvedbyageneticalgorithm.Inordertoimplementthislearningmethod,thestudentshadtodothefollowing:•Designalearningenvironmentandtaskfortherobot.

•SubclassPyro’sBrainclasstocreateaneuralnetworkbrainbasedonPyro’sNetworkclasswithtaskappropriateinputvaluesderivedfromsensorsandoutputvaluestocommandthemotors.

•SubclassPyro’sGAclasstocreateataskappropriatefitnessfunctionandstoppingcriteriafortheevolutionaryprocess.Includecommandstosavethebestneuralnetworkweightsfoundsofar.•Createatestingprogramtoinstantiateaneuralnetworkfromafileofsavedweightsandthenevaluatetheevolvedbehavior.

Themostambitiousrobotlearningprojectfromtheclassinvolvedathreewaygameoftaginwhicheachrobothadauniquecolor:theredrobotwaschasingthebluerobot,thebluerobotwaschasingthegreenrobot,andthegreenrobotwaschasingtheredrobot.Theneuralnetworkbrainforeachrobothadthesame

22

structure,buttheweightswereevolvedinaseparatespeciesofthegeneticalgorithm.Thereasonforthiswastoalloweachrobottodevelopuniquestrategies.

Otherrobotlearningprojectsfromtheclassincludedhavingarobotgathercoloredpucksscatteredrandomlythroughouttheenvironment,havingarobotnavigateaPacMan-inspiredmazewhileavoidingapredatorrobot,andhavingarobottryingtocaptureapuckfromaprotectorrobot.

Pyro’sinfrastructureallowedthestudentstofocusonthemostinterestingaspectsoftheproject,suchastheenvironment,task,networkarchitecture,andfitnessfunction,withouthavingtoworryaboutthedetailsofhowthegeneticalgorithmandneuralnetworkwereimplemented.TheabstractionsprovidedwithinPyroenabledthestudentstoeasilyintegrateaneuralnetworkwithageneticalgorithmandthustodevelopquitesophisticatedrobotlearningprojectsinonlythreeweekstime.

AlthougheightypercentofthestudentsintheclasshadnotusedPythonbeforeandtherewasverylittleformalinstructiongivenintheclassonPython,studentswereenthusiasticaboutthelanguage:

“IthinkthatIknowenoughlanguages(ofawidevariety)thatIwasabletoadapttoPythonevenwithminimalinstruction.”

“IreallylikedPython;it’sacleanandeasyyetpowerfullanguage.”

“Ilikethelanguage.Ithinkitisintuitiveandeasytolearn,andisappropriateforthiscourse.”“IlikePythonverymuchbecauseitlookslikeexecutablepseudocode.”

“IthinkPythonisgreattouseinhigher-levelCSclasseslikethisbecauseitallowsforcodingrelativelycomplexprogramsquickly,comparedtosayC,andIalwaysfindIhavemoretimeforextraexperimentationwhenusingPython.”

Asdemonstratedinthefollowingcomments,studentsalsoappreciatedtheabstractionsprovidedbyPyroandlikedhavingaccesstothesourcecode:

23

“Pyrotookcareofalotoftherepetitive,lessinterestingcodingforus.”

“PyrohadgoodcapabilitiesforprogrammingrealrobotsandimplementedalotoflearningtechniquesthatareusefulinAI.Alsoitwasnicebeingabletoprogramgenericallyforanyrobot.”

“Ilikedthatthedetailswerehidden,butIcouldgoinandchangethingsifneeded.”

“Ifoundthathavingthesourceavailablewasveryhelpfulonanumberofoccasions,especiallysinceit’sinPythonandcanbeunderstoodquickly.”

“Accessiblesource—Imodifiedalotofcomponentsformyexperiments.Thecodewasreason-ablycleanandstraightforwardtoworkwith.”

Asisevidentfromabove,Pyroenablesstudentsatalllevelstodoroboticsprojectsthatwereonlyfeasibleinthepastbyresearchteams.This,webelieve,isoneofthebiggestpay-offsofPyro.Itbringsaspectsofcurrentresearchintothecurriculuminanaccessible,lowcostmanner.

7Conclusions

ThePyroprojectisthelatestincarnationofourattemptstomaketheteachingofautonomousmobilerobotsaccessibletostudentsandteachersalike.Wehavedevelopedavarietyofprograms,examples,andtutorialsforexploringroboticsinatop-downfashion,andwearecontinuingtoaddnewcurricularmodules.Someofthesemodulesarecreatedbystudentsintheclasses,othersbytheauthors,andsomebyfacultyatotherinsti-tutionswhohaveadoptedPyro.Modulescurrentlyunderdevelopmentincludemulti-agentcommunication,reinforcementlearning,logic,planning,andlocalization.

Webelievethatthecurrentstate-of-the-artinrobotprogrammingisanalogoustotheeraofearlydigitalcomputerswheneachmanufacturersupporteddifferentarchitecturesandprogramminglanguages.Regard-24

lessofwhetheracomputerisconnectedtoanink-jetprinteroralaserprinter,acomputertodayiscapableofprintingonanyprinterdevicebecausedevicedriversareintegratedintothesystem.Similarly,weoughttostriveforintegrateddevicesonrobots.Ourattemptsatdiscoveringusefulabstractionsareafirstandpromisingstepinthisdirection.Webelievethatdiscoveriesofgenericrobotabstractionswill,inthelongrun,leadtoamuchmorewidespreaduseofrobotsineducationandwillprovideaccesstorobotstoanevenwiderrangeofstudents.

Ourgoalistoreducethecostoflearningtoprogramrobotsbycreatinguniformconceptualizationsthatareindependentofspecificrobotplatformsandincorporatetheminanalreadyfamiliarprogrammingparadigm.Conceptualizinguniformrobotcapabilitiespresentsthebiggestchallenge:HowcanthesameconceptualizationapplytodifferentrobotswithdifferentcapabilitiesanddifferentprogrammingAPI’s?Ourapproach,whichhasbeensuccessfultodate,hasbeenshowntoworkonseveralrobotplatforms,fromthemost-expensiveresearch-orientedrobot,tothelowest-costLEGO-basedones.Wearestrivingforthe“write-once/run-anywhere”idea:robotprograms,oncewritten,canbeusedtodrivevastlydifferentrobotswithoutmakinganychangesinthecode.Thisapproachleadsthestudentstoconcentratemoreonthemodelingofrobot“brains”byallowingthemtoignoretheintricaciesofspecificrobothardware.Moreimportantly,wehopethatthiswillallowstudentstograduallymovetomoreandmoresophisticatedsensorsandcontrollers.Inourexperience,thismoregeneralizedframeworkhasresultedinabetterintegrationofrobot-basedlaboratoryexercisesintheAIcurriculum.Itisnotonlyaccessibletobeginners,butisalsousableasaresearchenvironmentforourownrobot-basedmodeling.

Acknowledgments

Pyrosourcecode,documentationandtutorialsareavailableatwww.PyroRobotics.org.ThisworkisfundedinpartbyNSFCCLIGrantDUE0231363.

25

References

[1]TeamBots2.0.[2]ActivMedia.

Home

page

for

the

Pioneer

robot

and

the

Aria

simulator

http://www.activrobots.com/,2003.

[3]TuckerBalch.BehavioralDiversityinLearningRobotTeams.PhDthesis,GeorgiaInstituteofTech-nology,1998.

[4]D.S.Blank,J.H.Hudson,B.C.Mashburn,andE.A.Roberts.TheXRCLProject:TheUniversity

ofArkansas’EntryintotheAAAI1999MobileRobotCompetition.Technicalreport,UniversityofArkansas,1999.

[5]BrianGerkey,RichardVaughan,andAndrewHoward.ThePlayer/Stageproject:Toolsformulti-robot

anddistributedsensorsystems.InProceedingsofthe11thInternationalConferenceonAdvancedRobotics,pages317–323,Coimbra,Portugal,June2003.

[6]LisaMeeden.CS63ArtificialIntelligence,Spring2004,SwarthmoreCollege.WorldWideWeb,URL

ishttp://www.cs.swarthmore.edu/∼meeden/cs63/s04/cs63.html.[7]TomM.Mitchell.MachineLearning.McGraw-Hill,Boston,MA,1997.

[8]R.Mondada,E.Franzi,andP.Ienne.Mobilerobotminiturization:Atoolforinvestigationincontrol

algorithms.InProceedingsoftheThridInternationalSymposiumonExperimentalRobots,Kytoto,Japan,1993.

[9]MichaelMontemerlo,NicholasRoy,andSebastianThrun.CARMEN:CarnegieMellonRobotNavi-gationToolkit.WorldWideWeb,URLishttp://www-2.cs.cmu.edu/∼carmen/.

26

[10]CongressonEvolutionaryComputation.CEC2004contests.WorldWideWeb,URLishttp://

www.cec2004.org/contests.htm.

[11]CommitteeontheStatusofWomeninComputingResearch.FinalReportsfromtheParticipantsofthe

CREWProgram.WorldWideWeb,URLishttp://www.cra.org/Activities/craw/creu/crewReports/2004.php.[12]LutzPrechelt.

AnempiricalcomparisonofC,C++,Java,Perl,Python,Rexx,andTclfora

search/string-processingprogram.Technicalreport,UniversitatKarlsruhe,FakultatfurInformatik,Germany,2000.

[13]StuartRussellandPeterNorvig.ArtificialIntelligence:AModernApproach.PrenticeHall,Englewood

Cliffs,NJ,1995.

27

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- aiwanbo.com 版权所有 赣ICP备2024042808号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务