_resources2018_Botball_WorkshopSlides-v2018 01_第1页
_resources2018_Botball_WorkshopSlides-v2018 01_第2页
_resources2018_Botball_WorkshopSlides-v2018 01_第3页
_resources2018_Botball_WorkshopSlides-v2018 01_第4页
_resources2018_Botball_WorkshopSlides-v2018 01_第5页
已阅读5页,还剩407页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

BeforewegetstartedSignin,andcollectyourmaterialsandelectronics.KIPRstaffmaycomearoundandinstallfilesasneeded.ChargeyourWallabybatteries-WHITEtoWHITE(refertonextslide)Openthe“2018PartsList”folder,whichcontainsfilesthatlistallofyourBotballrobotkitcomponents.Pleasegothroughthelistsandverifythatyouhavereceivedeverything.BuildtheDemoBot.,WelcometoBotball2018!,Raiseyourhandifyouneedhelporhavequestions.,KIPRRoboticsController-Wallaby,Forchargingthecontrollersbattery,useonlythepowersupplywhichcamewithyourcontroller.Itispossibletodamagethebatterybyusingthewrongchargerorexcessivedischarge!Thestandardpowerpackisalithiumiron(LiFe)battery,asaferalternativetolithiumpolymerbatteries.Thesafetyrulesapplicableforrecharginganybatterystillapply:DoNOTleavethebatteryunattendedwhilecharging.Chargeinacool,openareaawayfromflammablematerials.,ChargingtheControllersBattery,KRCWallabyControllerGuide,2ServoMotorPorts(Port#0developtheskills,character,andaspirationsofstudents;andcontributetotheenrichmentofourschoolsystems,communities,andthenation.,Thankyouforparticipating!Wecouldntdoitwithoutyou!,Introductions:workshopstaffandvolunteersFood:lunchisonyourownWorkshopschedule:2days,Housekeeping,Day1,Day2,BotballGameReviewMotorPositionCounterMeasuringDistanceColorCameraMovingtheiRobotCreate:Part1MovingtheiRobotCreate:Part2iRobotCreateSensorsLogicalOperatorsResourcesandSupport,WorkshopSchedule,BotballOverviewGettingstartedwiththeKIPRSoftwareSuiteExplainingthe“Hello,World!”CProgramDesigningYourOwnProgramMovingtheDemoBotwithMotorsFunwithFunctionsMovingtheDemoBotServosRepetition,Repetition:CountingMakingSmarterRobotswithSensorsRepetition,Repetition:ReactingMakingaChoiceLine-followingHomework,Thankstoournationalsponsors!,Thankstoourregionalsponsors!,Thankstoourregionalhosts!,BotballOverview,Whatandwhen?GCERandECERPreviewofthisyearsgameHomeworkfortonight,ProducedbytheKISSInstituteforPracticalRobotics(KIPR),anon-profitorganizationbasedinNorman,OK.Engagesmiddleandhighschoolagedstudentsinateam-orientedroboticscompetitionbasedonnationaleducationstandards.Bydesigning,building,programming,anddocumentingrobots,studentsusescience,technology,engineering,math,andwritingskillsinahands-onprojectthatreinforcestheirlearning.,WhatisBotball?,WhenisBotball?,Recruitteams.Fundraise.Applyforscholarships.,FALL,Jan.Mar.,79Weeks,Mar.Jun.,July,Prof.Dev.workshops.,Design,build,e.g.,:8888NotethatUSBcableIPaddressis:8888Theuserinterfaceforthepackagewillnowcomeupinyourbrowser.,LoadingtheStartingWebPage(USB),ConnecttheWallabytoyourBrowserdeviceviaWi-FiThisisgreatathomeorSchoolNotrecommendedatLargeWorkshopsoranyTournamentTurnontheWallabywiththeblackswitchonthesideUsetheinfo(Wallaby#andPassWord)intheaboutpagetoconnectviaWi-Fi,ConnecttheWallabytoyourcomputer,SmartPhoneorTabletAtSchool,Connection,WhenyouareconnectedtoyourWallaby,yourdevicemaygivevariouserrors;“nointernetconnection”or“connectedwithlimited.”,InthebottomrightcorneroftheKIPRIDEthereisaniconthatshowsifyouarestillconnectedtotheWallaby.,connected,NOTconnected,LaunchawebbrowsersuchasChromeorFirefoxandpowerupyourWallaby.NotethatInternetExplorerwillnotwork.ConnecttotheWallabyviaWi-Fi.CopythisIPaddressintoyourbrowsersaddressbarfollowedby“:”andportnumber8888;e.g.,:8888Theuserinterfaceforthepackagewillnowcomeupinyourbrowser.Youmayuseacomputer,tabletorevenasmartphonethroughWi-Fi.,LoadingtheStartingWebPage(Wi-Fi),Tomakeiteasierforyoutolearnanduseaprogramminglanguage,KIPRprovidesaweb-basedSoftwareSuitewhichwillallowyoutowriteandcompilesourcecodeusingtheCprogramminglanguage.ThedevelopmentpackagewillworkwithalmostanywebbrowserexceptInternetExplorer.,HowcanIwriteandcompilemyownsourcecode?,ClickontheKISSIDEbutton.NOTE:Thebuttonsmightbeindifferentlocationsdependingondevicetype.,Creatingyourfirstproject,Addanewuserfolderbyclickingthe+signintheProjectExplorer.Nameyournewuserfolderbythestudentsnametohelporganization.Allofyourdifferentprojectswillgointothisuserfolder.,Creatingyourfirstuserfolder,StudentName,ClickCreatetocomplete.,Creatingyourfirstproject,GobacktoProjectExplorerandselecttheUserNameyoucreatedfromthedropdown.Thisisthefolderyoucreated.Click+AddProject.Youareaddingaprojecttoyourfolder.,GiveyourprojectadescriptivenameNote:youwillhavealotofstudentsprojects,soconsiderusingtheirfirstnamefollowedbythenameoftheactivity.GiveadescriptiveSourceFileNameaswell.TheSourceFileneedstoendwitha.cThenpresstheCreatebutton.,Nameyourproject,ClicktheCompilebuttonforyourprojectand,ifsuccessful,clickRunsoyoucanrunyourprojecttoseeifitworks.NOTE:Whenyoucompile,yourprojectisautomaticallysaved.,CompileandThenRunYourProject,Note:oneproject=oneprogram.Clickthe+AddProjectbuttonorclicktheMenubuttontoreturntothestartingmenu.Proceedasbefore.TheProjectExplorerpanelwillshowyoualloftheuserfolderprojectsandactivelyeditedfiles.,Startinganotherproject,Explainingthe“Hello,World!”CProgram,ProgramflowandthemainfunctionProgrammingstatementsandfunctionsComments,“Hello,World!”,Note:Wewillusethistemplateeverytime;wewilldeletelineswedontwant,andwewilladdlinesthatwedowant.,Programflowandlinenumbers,Computersreadaprogramjustlikeyoureadabooktheyreadeachlinestartingatthetopandgotothebottom.Computersreadincrediblyquicklyapproximately800-millionlinespersecond!,Sourcecode,ThisisthesourcecodeforourfirstCprogram.Letslookateachpartofthesourcecode.,Themainfunction,/CreatedonThuJanuary52018intmain()printf(Hello,World!n);return0;,Thisisthemain()function.Whenyourunyourprogram,themainfunctionisexecuted.ACprogrammusthaveexactlyonemain()function.,Afunctiondefinesalistofactionstotake.Afunctionislikearecipeforbakingacake.Whenyoucall(use)thefunction,theprogramfollowstheinstructionsandbakesthecake.,Blockofcode,/CreatedonThuJanuary52018intmain()printf(Hello,World!n);return0;,Begin,End,Thisisablockofcode.Ablockofcodeshouldalwaysbeprecededbyablockheader,whichisthelinejustabovethe.,Ablockisdefinedbetweenabeginningcurlybraceandanendingcurlybrace.,Thelistofactionsthatthefunctiontakesisdefinedinsideablockofcode.,BlockHeader,Programmingstatements,/CreatedonThuJanuary52018intmain()printf(Hello,World!n);return0;,Insidetheblockofcode(betweentheandbraces),wewritelinesofcodecalledprogrammingstatements.Eachprogrammingstatementisanactiontobeexecutedbythecomputer(orrobot)intheorderthatitislisted.Therecanbeanynumberofprogrammingstatementswithinablockofcode.,Statement#1Statement#2,Endingaprogrammingstatement,/CreatedonThuJanuary52018intmain()printf(Hello,World!n);return0;,Eachprogrammingstatementendswithasemicolon;(unlessitisfollowedbyanewblockofcode).,ThisissimilartoanEnglishsentence,whichendswithaperiod.IfanEnglishstatementismissingaperiod,thenitisarun-onsentence.,Endingthemainfunction,/CreatedonThuJanuary52018intmain()printf(Hello,World!n);return0;,Themainfunctionendswithareturnstatement,whichisaresponseoranswertothecomputer(orrobot).Inthiscase,the“answer”backtothecomputeris0.,Thereturnstatementisthelastlinebeforethebrace.,Comments,/CreatedonThuJanuary52018intmain()printf(Hello,World!n);return0;,Thegreentextatthetopoftheprogramiscalleda“comment”.,Commentsarehelpfulnotesthatcanbereadbyyouoryourteamtheyareignored(notread)bythecomputer!,/Commentingfortheflowofcode,TheKISSIDEhighlightspartsofaprogramtomakeiteasiertoread.(Bydefault,theKISSIDEcolorsyourcodeandaddslinenumbers.)IncludesinpurpleCommentsingreenTextstringsappearinredKeywordsappearinblue,Textcolorhighlighting,Description:WriteaprogramfortheKIPRWallabythatprintsyourname.Solution:,Printyourname,DesigningYourOwnProgram,BreakingdownataskPseudocode,flowcharts,andcommentswait_for_millisecondsfunctionDebuggingyourprogram,Breakdowntheobjectives(complextasks)intosmallerobjectives(simplesubtasks).Breakdownthesmallertasksintoevensmallertasks.Continuethisprocessuntileachsubtaskcanbeaccomplishedbyalistofindividualprogrammingstatements.Forexample,thelargertaskmightbetomakeaPBfromoneofyourprogramsandcompileit.,DebuggingErrors,DebuggingErrors,line#:col#(theerrorisonorbeforetheline#6),“expected;”(semicolon),Whenthereisanerror,youcanignorethefirsterrorline(“Infunctionmain”)andreadthenexttoseewhatthefirsterroris.Ifyouhavealotoferrors,startfixingthemfromthetopgoingdown.Fixoneortwoandrecompile.,DebuggingErrors,MovingtheDemoBotwithMotors,Plugginginmotors(portsanddirection)motorfunctions,Toprogramyourrobottomove,youneedtoknowwhichmotorportsyourmotorsarepluggedinto.Computerscientistsstartcountingat0,sothemotorportsarenumbered0,1,2,and3.,Checkyourrobotsmotorports,Wallabymotorports,Motorshaveredwireandablackwirewithatwo-prongplug.TheWallabyhas4motorportsnumbered0otherwise,yourrobotwillgoincircles!Motorshaveredwireandablackwirewithatwo-prongplug.Thereisnoleftsideorrightside.Youcanplugtheseintwodifferentways:Onedirectionisclockwise,andtheotherdirectioniscounterclockwise.Theredandblackwireshelpdeterminemotordirection.,Motordirection,Thereisaneasywaytocheckthis!Manuallyrotatethetire,andyouwillseeanLEDlightupbythemotorport(theport#islabeledontheboard).IftheLEDisgreen,itisgoingforward(+).IftheLEDisred,itisgoingreverse().Usethistricktochecktheport#sanddirectionofyourmotors.Ifoneisredandtheotherisgreen,turnonemotorplug180andplugitbackin.Thelightsshouldbothbegreeniftherobotismovingforward.,Motorportanddirectioncheck,UsetheMotorWidget,Thereareseveralfunctionsformotors.Wewillbeginwithmotor.motor(0,100);/Turnsonmotorport#0at100%power./Selectanypowerbetween-100%and100%.msleep(#milliseconds);/Waitforthespecifiedamountoftime.ao();/Turnoffallofthemotors.,Commonmotorfunctions,Motorport#(between0and3),Apositivenumbershoulddrivethemotorforward;ifnot,rotatethemotorplug180.Anegativenumbershoulddrivethemotorreverse.Iftwodrivemotorsarepluggedininoppositedirectionsfromeachother,thentherobotwillgoinacircle.,Usingmotorandao,intmain()motor(0,100);motor(3,100);msleep(2500);ao();return0;,Untilyouarefamiliarwiththefunctionsthatyouwillbeusing,usethischeatsheetasaneasyreference.Copyingandpastingyourowncodeisalsoveryhelpful.,KIPRWallabyfunctionscheatsheet,printf(textn);/Printsthespecifiedtexttothescreenmsleep(#milliseconds);/Anothernameforwait_for_milliseconds(identical)motor(port#,%velocity);/Turnsonmotorwithport#atspecified%velocitymotor_power(port#,%power);/Turnsonmotorwithspecifiedport#atspecified%powermav(port#,velocity);/Movemotoratspecifiedvelocity(#tickspersecond)mrp(port#,velocity,position);/Movemotortospecifiedrelativeposition(in#ticks)ao();/Alloff;turnsallmotorportsoffenable_servos();/Turnsonservoportsdisable_servos();/Turnsoffservoportsset_servo_position(port#,position);/Movesservoinspecifiedport#tospecifiedpositionwait_for_light(port#);/Waitsforlightinspecifiedport#beforenextlinewait_for_touch(port#);/Waitsfortouchinspecifiedport#beforenextlineanalog(port#)/Getasensorreadingfromaspecifiedanalogport#digital(port#)/Getasensorreadingfromaspecifieddigitalport#shut_down_in(timeinseconds);/Shutsdownallmotorsafterspecified#ofseconds,AccesstheWallabydocumentationbyselectingtheHelpbuttonintheKISSIDE,WallabyLibraryDocumentation,Description:WriteaprogramfortheKIPRWallabythatdrivestheDemoBotforwardat80%powerfortwoseconds,andthenstops.Analysis:Whatistheprogramsupposedtodo?PseudocodeCommentsDriveforwardat80%./1.Driveforwardat80%.Waitfor2seconds./2.Waitfor2seconds.Stopmotors./3.Stopmotors.Endtheprogram./4.Endtheprogram.,MovingtheDemoBot,Solution:Createanewproject,createanewfile,andenteryourpseudocode(ascomments)andsourcecodeinthemainfunction.Note:remembertogiveyourprojectandfiledescriptive,uniquenames!Execution:CompileandrunyourprogramontheKIPRWallaby.,MovingtheDemoBot,Reflection:Whatdidyounoticeafteryourantheprogram?DidtheDemoBotmoveforward?Positive(+)numbersshouldmovethemotorsinaclockwisedirection(forward);ifnot,rotatethemotorplug180whereitplugsintotheWallaby.Ifyourrobotmovesinacircle,onemotoriseithernotmoving(isitpluggedin?)ortheyaremovinginoppositedirections(rotatethemotorplug180).DidtheDemoBotdrivestraight?Howcouldyouadjustthecodetomaketherobotdrivestraight?Howcanyoumaketherobotdrivebackwards?Howcanyoumaketherobotturnleftorright?,MovingtheDemoBot,Rememberyour#line:positivenumbers(+)goforwardandnegativenumbers()goinreverse.Drivingstraight:itissurprisinglydifficulttodriveinastraightlineProblem:Motorsarenotexactlythesame.Problem:Thetiresmightnotbealignedperfectly.Problem:Onetirehasmoreresistance.Solution:Youcanadjustthisbyslowingdownorspeedingupthemotors.Makingturns:Solution:Haveonewheelgofasterorslowerthantheother.Solution:Haveonewheelmovewhiletheotheroneisstopped.Solution:Haveonewheelmoveforwardandtheotherwheelmoveinreverse(frictionislessofafactorwhenbothwheelsaremoving).,Robotdrivinghints,Andmany,manyotherreasons,Youhaveapapercopyofthisactivityinyourregistrationpacket.StartwithDemoBotcompletelywithinthestartingboxonmatA.Moveastackof4pomsthatstartsoncircle2or4intotheappropriategarage.(green,orange,thenblue)Thepomsmustcometorestcompletelywithinthecoloredgarage.Therobotscannotpushthepomsoverthesolidlinesthatboundthegarages.Advanceextension:removethetoppomfromthestackormakesurethatitisnottouchingthesurfaceofthegarageinwhichtheotherpomsarelocated.,Activity1(connectionstothegame),AvariableisanamedcontainerthatstoresatypeofvalueAvariablehasthefollowingthreecomponents:thetypeofdataitstores(holds),thename,andthevalue.Thinkofavariablelikeacupwithyournameonit,Variables,intmy_cup;my_cup=3;,a,b,c,Useintasyourdatatypeifyouwanttostorewholenumbers(integers),EachvariableisgivenauniquenamesowecanidentifyitVariablenamescanbealmostanythingyouwouldlike.Variablenamescancontainletters,numbers,andunderscores(“_”).Variablenamescannotbeginwithanumber.AnExample:intmy_variable;/variabledeclarationmy_variable=0;/variable“initialization”,Variablenames,Youcansetthevaluetoanyintegeryouchoose.,Variables,MovingtheDemoBotServos,Plugginginservos(ports)enable_servosanddisable_servosfunctionsset_servo_positionfunction,Aservomotor(orservoforshort)isamotorthatrotatestoaspecifiedpositionbetween0and180.Servosaregreatforraisinganarmorclosingaclawtograbsomething.Servomotorslookverysimilartonon-servomotors,buttherearedifferencesAservohasthreewires(orange,red,andbrown)andablackplasticplug.Anon-servomotorhastwograywiresandatwo-prongplug.,Servos,KIPRRoboticsControllerservoports,TheKIPRRoboticsControllerhas4servoportsnumbered0(left)/Activate(turnon)allservoports.set_servo_position(2,925);/Rotateservoonport#2toposition925.disable_servos();/De-activate(turnoff)allservoports.Remember:theuseablerangeofpositionsisfrom150to1900.Thedefaultpositionwhenservosareenabledis1024(centered),whichmeansthatallservoswillautomaticallymovetothispositionwhenenable_servosiscalled.Youcan“preset”aservopositionbycallingset_servo_positionbeforecallingenable_servos.Thiswillmaketheservomovetothispositionratherthancenter.,Servofunctions,Usingservofunctions,intmain()enable_servos();msleep(1000);set_servo_position(2,925);msleep(1000);set_servo_position(2,675);msleep(1000);disable_servos();return0;,Usingservofunctions,intmain()set_servo_position(2,1500);enable_servos();msleep(1000);set_servo_position(2,925);msleep(1000);set_servo_position(2,675);msleep(1000);disable_servos();return0;,Whathappenswhenwesettheservopositionbeforeenable_servos?,Description:WriteafunctionfortheKIPRWallabythatwavestheDemoBotservoarmupanddown.Remembertoenabletheservosatthebeginningofyourprogram,anddisabletheservosattheendofyourprogram!Warning:ThearmmountedonyourDemoBotpreventstheservofromfreelyrotatingtoallpossiblepositions(itwillrunintotheKIPRWallabycontrollerorthechassisoftherobot)!Donotkeeptryingtomoveaservotoapositionitcannotreach,asthiscanburnouttheservoandalsoconsumealotofpowerfromyourrobot.UsetheServoscreentodeterminethelimitsoftheDemoBotarm,writethesenumbersdown,andthenusethesenumbersinyourcode.,Wavetheservoarm,Description:WriteaprogramfortheKIPRWallabythatwavestheDemoBotservoarmupanddown.Writeafunctionthatdoesonewave.CallitfromyourmainfunctionAnalysis:Whatistheprogramsupposedtodo?PseudocodeCommentsEnableservos./1.Enableservos.MoveservotoYOURlimit./2.MoveservotoYOURlimit.Waitfor3seconds./3.Waitfor3seconds.MoveservotoYOURotherlimit./4.MoveservotoYOURotherlimit.Waitfor3seconds./5.Waitfor3seconds.Disableservos./6.Disableservos.Endtheprogram./6.Endtheprogram.,Wavetheservoarm,Analysis:,Wavetheservoarm,Lunch!,StartwithyourDemoBotatleastpartiallywithinthestartingbox.Seeextensionformorepracticalapplication.Usingaservocontrolledclawmovelargeyellowcube(s)fromtheorangegarageintothebluegarage.TherobotcannottouchthesolidlinesofanyofthegaragesRefertoyourhandoutforextensionactivities,Activity2(connectionstothegame),Description:WriteaprogramfortheKIPRWallabythatdrivestheDemoBotalongapathintheshapeofasquare.Startwithhavingtherobotmakea90turn.Thenaddinforwardmovementstohavetherobotdrivealongasquarepath.Rememberthedirectionyourrobotistaking.,Drawasquare,Analysis:Whatistheprogramsupposedtodo?PseudocodeCommentsDriveforward./1.Driveforward.Turnright90./2.Turnright90-degrees.Driveforward./3.Driveforward.Turnright90./4.Turnright90-degrees.Driveforward./5.Driveforward.Turnright90./6.Turnright90-degrees.Driveforward./7.Driveforward.Turnright90./8.Turnright90-degrees.Stopmotors./9.Stopmotors.Endtheprogram./10.Endtheprogram.,Drawasquare,intmain()/1.Driveforward.motor(0,100);motor(3,100);msleep(4000);/2.Turnright90-degrees.motor(0,100);motor(3,-100);msleep(1500);/3.Driveforward.motor(0,100);motor(3,100);msleep(4000);/4.Turnright90-degrees.motor(0,100);motor(3,-100);msleep(1500);/5.Driveforward.motor(0,100);motor(3,100);msleep(4000);/6.Turnright90-degrees.motor(0,100);motor(3,-100);msleep(1500);/7.Driveforward.motor(0,100);motor(3,100);msleep(4000);/8.Turnright90-degrees.motor(0,100);motor(3,-100);msleep(1500);ao();/9.Stopmotors.return0;/10.Endtheprogram./endmain,Solution:Hereissomecodethatusesthemotor()andmsleep()functionstodrivetherobotinasquare.Note:thisisjustoneofmanysolutions.,Drawasquare,FunwithFunctions,WritingyourownfunctionsFunctionprototypes,definitions,andcalls,intmain()/1.Driveforward.motor(0,100);mot

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论