hexapod tutorial

12
Hexapod tutorial In this tutorial we will be building a hexapod walking robot. Make sure that you have read the BubbleRob tutorial and the tutorial on importing and preparing rigid bodies before starting with this one. The VREP CAD data, courtesy of Lyall Randell, related to this tutorial ("hexapod.dxf") is located in VREP's installation folder's "cadFiles" folder. A finished model related to this tutorial can be found in VREP's model browser. Click [Menu bar > File > Import > Mesh...] then select the file to import. Also refer to the section on how to import/export shapes. A dialog pops open asking about mesh scaling and mesh orientation. Click Ok. Several shapes were imported and are located in the middle of the scene. The shapes also appear in the scene hierarchy on the left hand side of the main window. Depending on how the original CAD data was exported, the imported CAD data could be at a different scale, different location, or even grouped as a single shape. The assigned color of imported shapes is random. Following figure shows the imported shapes: As you can see, the hexapod robot has 6 identical legs. So instead of preparing each leg individually, we will prepare one leg, and when it is done, just copyandpaste it to the right locations! Select in the scene the shapes to delete (use the ctrlclick and/or the shiftclick for the selection process), then press the deletekey (make sure you kept the leg pointing towards the world xaxis):

Upload: arkadeep-saha

Post on 07-Sep-2015

56 views

Category:

Documents


7 download

DESCRIPTION

VRep Hexpod Tutorial

TRANSCRIPT

  • 7/6/2015 Hexapodtutorial

    http://www.coppeliarobotics.com/helpFiles/en/hexapodTutorial.htm 1/12

    HexapodtutorialInthistutorialwewillbebuildingahexapodwalkingrobot.MakesurethatyouhavereadtheBubbleRobtutorialandthetutorialonimportingandpreparingrigidbodiesbeforestartingwiththisone.TheVREPCADdata,courtesyofLyallRandell,relatedtothistutorial("hexapod.dxf")islocatedinVREP'sinstallationfolder's"cadFiles"folder.AfinishedmodelrelatedtothistutorialcanbefoundinVREP'smodelbrowser.Click[Menubar>File>Import>Mesh...]thenselectthefiletoimport.Alsorefertothesectiononhowtoimport/exportshapes.Adialogpopsopenaskingaboutmeshscalingandmeshorientation.ClickOk.Severalshapeswereimportedandarelocatedinthemiddleofthescene.Theshapesalsoappearinthescenehierarchyonthelefthandsideofthemainwindow.DependingonhowtheoriginalCADdatawasexported,theimportedCADdatacouldbeatadifferentscale,differentlocation,orevengroupedasasingleshape.Theassignedcolorofimportedshapesisrandom.Followingfigureshowstheimportedshapes:

    Asyoucansee,thehexapodrobothas6identicallegs.Soinsteadofpreparingeachlegindividually,wewillprepareoneleg,andwhenitisdone,justcopyandpasteittotherightlocations!Selectinthescenetheshapestodelete(usethectrlclickand/ortheshiftclickfortheselectionprocess),thenpressthedeletekey(makesureyoukeptthelegpointingtowardstheworldxaxis):

  • 7/6/2015 Hexapodtutorial

    http://www.coppeliarobotics.com/helpFiles/en/hexapodTutorial.htm 2/12

    Theimportoperationhasleftuswith3shapesperleg,sowewillneedtosubdividethose3shapesfurther,inordertohaveseparateshapesfortheleglinksandthelegservomotors.Selectthe3shapesthenclick[Menubar>Edit>Grouping/Merging>Divideselectedshapes].Youcanseethatthisoperationhasdividedtheshapeclosesttotherobotbodyinto3subshapes,whereweonlyexpected2subshapes.Tocorrectforthis,selecttheleftandrightlinkelementsasshowninfollowingfigure:

    Whilethetwoshapesarestillselected,click[Menubar>Edit>Grouping/Merging>Mergeselectedshapes]inordertomergethemintoasingleshape.

    Innextstep,wewilladdthejointsrequiredforourlegmechanism.Onewayofdoingthisistoaddthe

  • 7/6/2015 Hexapodtutorial

    http://www.coppeliarobotics.com/helpFiles/en/hexapodTutorial.htm 3/12

    jointsintothescene,thenspecifytheirappropriatepositionandorientation(throughthecoordinateandtransformationdialog).Thisishowevernotpossible,whenyoudon'tknowtheexactjointpositionsasinourcase,andsowewillhavetoextractthemfromtheshapesthatwehave:

    Selectthe3shapesthatrepresenttheservomotors,copythem(ctrlcor[Menubar>Edit>Copyselectedobjects]),thencreateanewscenewith[Menubar>File>Newscene],thenpastetheshapes(ctrlvor[Menubar>Edit>PasteBuffer]).Wearenowinanotherscene(scene2),andwhateverwedoherewillnotaffectouroriginalscene.Nowkeepthe3servomotorsselectedandclick[Menubar>Edit>Grouping/Merging>Mergeselectedshapes]tomergethemasasingleshape.Thenenterthetriangleeditmode.Alltrianglescomposingourshapearenowdisplayedandcanbemanipulated.

    Switchtopage2andmoveyourcameraclosertotheshapewiththefittoviewtoolbarbutton:

    Shiftselectalltrianglescomposingoneoftheservomotors'outputshaftasillustratedinfollowingfigures:

  • 7/6/2015 Hexapodtutorial

    http://www.coppeliarobotics.com/helpFiles/en/hexapodTutorial.htm 4/12

    ThenclicktheExtractshapebuttonintheshapeeditmodedialog.Dothesamewiththetwootherservomotoroutputshafts(forthethirdservomotor,youwillhavetoswitchtopage3tobeabletoshiftselectitsoutputshaft):

  • 7/6/2015 Hexapodtutorial

    http://www.coppeliarobotics.com/helpFiles/en/hexapodTutorial.htm 5/12

    Switchbacktopage1,leavetheeditmode,thendeletetheshaperepresentingthe3servomotors.Nowtheextractedshaftsbecomeclearlyvisible:

    Wecanusetheextractedshapestopreciselypositionourjoints.Click[Menubar>Add>Joint>Revolute]toinsertarevolutejointintothescene.Thedefaultpositionisat(000)anditsdefaultorientationisvertical.Whilethejointisstillselected,ctrlselecttheshaperepresentingtheverticaloutputshaft,thenopenthepositionandtranslationdialogandclicktheApplytoselectionbuttonatthebottomofsection2.

    Thisjustpositionedthejointattheexactsamecoordinatesastheverticaloutputshaft!Nowrepeatthe

  • 7/6/2015 Hexapodtutorial

    http://www.coppeliarobotics.com/helpFiles/en/hexapodTutorial.htm 6/12

    procedurewithtwoadditionaljointsandthetwohorizontalshafts.Alljointsareinpositionnow,however,onlythefirstaddedjointhasthecorrectorientation.Selectthetwolastaddedjoints,thenenter(90,0,0)fortheAlpha,BetaandGammaitemsinsection2oftheorientationandrotationdialog,thenclicktherelatedApplytoselectionbutton.Alljointshavetherightpositionandorientationnow.Selectall3joints,copythemtothebuffer(ctrlc),switchbacktotheinitialscene(scene1),thenpastethebuffer(ctrlv).Thisiswhatyoushouldhave:

    Youcannowadjustthejointsizes(checktheJointlengthandJointdiameteritems)inthejointpropertiesdialog(thatyoucanopenbydoubleclickingajointiconinthescenehierarchy).Additionally,wewantthe2horizontaljointstobelocatedatycoordinate0,andtheverticaljointtobelocatedatazcoordinatesimilartoitsservomotor(usethecoordinateandtransformationdialogfortheseoperations):

  • 7/6/2015 Hexapodtutorial

    http://www.coppeliarobotics.com/helpFiles/en/hexapodTutorial.htm 7/12

    Renameyourjointsto"hexa_joint1","hexa_joint2"and"hexa_joint3"(frombodytofoot).Youcandothisbydoubleclickingthejoint'snamesinthescenehierarchy.Nowlet'ssettheinitialjointvaluessothatwhenthelegishorizontallystretched,alljointvaluesarezero:inthejointdialog,itemPosition,set30and+120for"hexa_joint2"and"hexa_joint3".Noticehowjointsareintorque/forcemode.Inourcasewewanttobeabletocontrolthosejointsininversekinematicsmode,butwealsowanttheinversekinematicsresultstobeappliedasdynamicspositioncontrolvalues.Todothis,wewillsetthejointsininversekinematicsmode(select"jointisininversekinematicsmode"intheJointmodesection).Inadditiontothat,wealsoactivatetheHybridoperationforthatjoint(thistellsVREPthattheinversekinematicscalculationresultswillbeappliedtothejointasdynamictargetvalue).ClickApplytoselectiontoapplythechangesyoujustperformedtotheothertwojointsthatareselected.

    Atthispoint,weshouldpreparethevisualappearanceofourshapes,groupthemifrequired,andpreparecorrespondingpureshapesforthedynamicsimulation.Detailsonhowthisisdonewillnotbeexplainedhere,sincetheprocedureisverysimilartowhatisdoneinthetutorialonimportingandpreparingrigidbodies.Onceyoufinishedthisstep,thisiswhatyoushouldhave(visibleandhiddenparts):

  • 7/6/2015 Hexapodtutorial

    http://www.coppeliarobotics.com/helpFiles/en/hexapodTutorial.htm 8/12

    Theabovesceneis"tutorials\Hexapod\hexapodintermediatestep.ttt".Noticefollowing:

    theobjectshavebeenappropriatelynamed/renamed.thehexapod'sbodyusedfordynamics("hexa_bodyRespondable")wassimplifiedas3cuboids(the

    spaceinbetweenhasbeenfilled).Thetipofthelegisrepresentedasapuresphere,sincepurespheresaremoststable/fastfor

    dynamicsimulations.Themasses,inertiaproperties,etc.havebeensetforbestperformance.Italwaysrequiressome(lots

    of!)testingtofindgood(i.e.stable)parameters.Consecutivelinkelementswon'tcausecollisionresponses(theRespondablemasksintheshape

    dynamicspropertiesdialoghavebeensetaccordingly).

  • 7/6/2015 Hexapodtutorial

    http://www.coppeliarobotics.com/helpFiles/en/hexapodTutorial.htm 9/12

    Next,wewillbelinkingcurrentelementsofthemechanism.Select"hexa_link3Respondable"then"hexa_joint3",andclick[Menubar>Edit>Makelastselectedobjectparent].Dothesamewith"hexa_joint3"and"hexa_link2Respondable","hexa_link2Respondable"and"hexa_joint2","hexa_joint2"and"hexa_link1Respondable","hexa_link1Respondable"and"hexa_joint1",andfinally"hexa_joint1"and"hexapod".Wehaveassembledthefirstleg.Startthesimulationandobservehowrigidobjectsareconstrainedbythejoints.Noticealsothatjointsarenotkeepingafixedposition,butslowlydrifting:thisisbecausewehaven'tyetdefinedaninversekinematicstaskforourkinematicchainrepresentingtheleg.Thisiswhatwewillbedoingnext.

    Addadummyobjectwith[Menubar>Add>Dummy].Renameitto"hexa_footTip".Nowpositionthedummyatthetipoftheleg,wherethelegiscontactingthefloor.Youcanachievethisbyusingtheobjectmanipulationtoolbarbuttons,orbyusingthecoordinateandtransformationdialog.Informercase,itcanbeusefultoadjustthepositionstepbystepbyswitchingtoorthogonalprojectionviewsonpage2,page3,page4,page5orpage6.Oncedone,thedummy'sabsolutepositionshouldbecloseto(0.204,0,0).Next,attachthedummyto"hexa_link3"(dragthedummyonto"hexa_link3"inthescenehierarchy).Thencopyandpaste"hexa_footTip"andrenamethecopyto"hexa_footTarget".

    Whatwewantatthisstage,istohave"hexa_footTip"follow"hexa_footTarget",whilehavingtheattachedmechanismautomaticallyadjustforthat(i.e.whilehavingthenewjointpositionsautomaticallycalculated).Wehavetodefineaninversekinematictask:

    First,let'sinformthetwodummiesthattheyareatiptargetpairforinversekinematicsresolution.Doubleclickthedummyiconof"hexa_footTip"inthescenehierarchy:thisopensthedummypropertiesdialog.IntheDummydummylinkingsection,specify"hexa_footTarget"asLinkeddummy.Noticehowbothdummiesgotlinkedthrougharedstippledlineinthescenehierarchy(thetwodummiesarealsolinkedinthescenethrougharedline,butsincebothdummiesarecoincident,thelinecannotbeseen).Inthesamedialog,Linktypeisalready"IK,tiptarget",whichisthedefaultvalue.Thisiswhatyoushouldhavebynow:

    Nowopentheinversekinematicsdialog,andclickAddnewIKgroup.AnewitemappearsintheIKgroupslist:"IK_Group".Whilethatitemisselected,opentheIKelementdialog(clickEditIKelements)andindicate"hexa_footTip"inthedropdownboxrighttoAddnewIKelementwithtip.ThenclickAddnewIKelementwithtip.Closethedialog,andattach"hexa_footTarget"to"hexapod".Ourinversekinematicstaskisreadyforthisleg!Let'stestit.

    First,temporarilydisabledynamicsbyopeningthegeneraldynamicspropertiesdialog,thenunchecking

  • 7/6/2015 Hexapodtutorial

    http://www.coppeliarobotics.com/helpFiles/en/hexapodTutorial.htm 10/12

    Dynamicsenabled.Next,startthesimulationandinthescenehierarchselect"hexa_footTarget".Movethe"hexa_footTarget"aroundwiththeobjectmanipulationtoolbarbuttons:thelegshouldfollow.Stopthesimulationandenabledynamicsagain.

    Wewillcontrolthehexapodrobotbygeneratingthemovementforoneleg,andapplyingitinadelayedwayforall6legs,whereeachlegwillhaveadifferentdelay.Weimplementthisbyhavingonechildscriptgeneratingthemovementsequenceforoneleg,andhaving6additionalchildscriptsapplyingthatmovementsequenceinadelayedmanner.Select"hexa_joint1"andclick[Menubar>Add>Associatedchildscript>Nonthreaded].Wejustattachedachildscripttothe"hexa_joint1"object.

    Nowwewillduplicatetheleg5times.Selectallobjectscomposingtheleg(hiddenobjectsaswell):from"hexa_joint1"to"hexa_footTip".Alsoselect"hexa_footTarget".Makesurethat"hexa_bodyRespondable"and"hexa_body"arenotselected,thencopyandpastetheobjects.Opentheorientationandrotationdialogandinsection3enter"60"fortheAroundZitem(keepingtheAroundXandAroundYitemsat0).MakesurethetransformationwillberelativetoWorld,thenclickRotateselection.Pastetheinitialleganothertime,thenadjusttheAroundZitemto120,thenclickRotateselectionagain.Repeattheprocedurefortheremaining3legs(makesureyouadjusttherotationangleto180,240andfinally300degrees).Thisiswhatyoushouldhave:

    Let'sattachalllegstothebody.Select"hexa_joint1#0"through"hexa_joint1#4",then"hexapod",andclick[Menubar>Edit>Makelastselectedobjectparent].Inthescenehierarch,collapsealllegtreesbyclickingtheir""icon.Thenselect"hexa_footTarget#0"through"hexa_footTarget#4",then"hexapod",andclick[Menubar>Edit>Makelastselectedobjectparent].

    Opentheinversekinematicsdialog.Noticehowtheinversekinematicstaskswerealsocopied.Thisiswhatyoushouldhave:

  • 7/6/2015 Hexapodtutorial

    http://www.coppeliarobotics.com/helpFiles/en/hexapodTutorial.htm 11/12

    Closetheinversekinematicsdialog.Opentheobjectselectiondialogwith[Menubar>Tools>Selection],orbypressingtheappropriatetoolbarbutton.ClickClearSelection,thenDummies:0/13.Alldummiesinthescenehavebeenselected.Deselect(withctrlclick)thedummythatisnotpartofthehexapodrobot.Wenowhaveour12dummiesonthehexapodselected.Nowopentheobjectcommonproperties.IntheVisibilitylayerssection,disablelayer3andenablelayer11,thenclicktherelatedApplytoselectionbutton.Thisjustsentalldummiestothevisibilitylayer11,effectivelymakingtheminvisible.Havealookatthelayerselectiondialogifyouwishtotemporarilyenable/disablesomelayers.

    Next,sendalljointstothevisibilitylayer10byfollowingthesameprocedureasabove.

    Thenaddanewdummytothesceneandrenameit"hexa_base".Alsosendittothevisibilitylayer11.Thenmakeitchildof"hexapod"."hexa_base"representsthepositionofourhexapodrobot,thatweselectedtobe(000).

    Nowlet'sdefinethehexapodmodel.Asyoumighthavenoticed,whenyouclickanobjectonthehexapodrobot,onlythatobjectgetsselected.Butwhatwenowwantistoprotectindividualobjectsfrommodification,andselectthewholerobotinstead.Foreachobjectcomposingthehexapodrobot,exceptfortheobject"hexapod",enabletheSelectbaseofmodelinsteaditemintheobjectcommonpropertiesdialog.Cleartheselection,thenselect"hexapod".Inthesamedialog,enabletheObjectismodelbaseitem.Nowclickanyobjectonthehexapodrobot:thewholerobotnowgetsselectedinstead:

  • 7/6/2015 Hexapodtutorial

    http://www.coppeliarobotics.com/helpFiles/en/hexapodTutorial.htm 12/12

    Nowopenthepositionandtranslationdialogandinspectitssection1(makesurethat"hexapod"isselected).Youcanseethattranslationof"hexapod"withthemousehappensinanxyplaneoftheabsolutereferenceframe.Youcanchangethedefaultmousetranslationbehaviourfortheselectedobjectbyadjustingthevariousitemsinsection1(ifyoudonotclickRemembersettings,thetranslationbehaviourisjusttemporary,otherwiseitisstoredintheselectedobject).Makesuretoalsoinspectsection1oftheorientationandrotationdialog,whereasimilarmechanismishandlingthemouserotationmode.

    Whenyounowtrytoshiftorrotatetherobotinthescene(usingtheobjectmanipulationtoolbarbuttons),itwillalwaysstayonthefloor,andkeepaproperorientation.Tryit!(thenmakesureyouresetittoitsinitialposition/orientationwiththeundotoolbarbutton).Ifyoupressthectrlkeyduringthetranslationoperation,youcanmovetherobotupanddown.

    Nowattachanonthreadedchildscriptto"hexapod".Createanotherscene(scene3),andopenthe"hexapod.ttm"modelfile.Doubleclickthechildscripticonofobject"hexapod"toopenthescripteditor.Copythescript,switchbacktotheoriginalscene(scene1),doubleclickthechildscripticonofobject"hexapod"andpastethescript.Repeatthesameprocedureforthechildscriptsassociatedwitheachleg.Noticehowallchildscriptsassociatedwiththehexapod'slegsareexactlythesame.Alastelementisstillmissing:weneedeachlegtoapplythemovementsequencewithadifferenttimedelay.Ifyoutakeacloserlookatthelegs'childscripts,theyareeachreadingadelayvaluefromtheirscriptsimulationparameterswiththeinstruction:

    modulePos=simGetScriptSimulationParameter(sim_handle_self,'modulePosition')

    Youcanopenthescriptsimulationparameterdialogbydoubleclickingtheiconontherighthandsideofachildscript.Addtheexactsamescriptsimulationparametersasthehexapodintheotherscene.Runthesimulation.Thehexapodrobotshouldnowwalk.

    Usingascripttocontrolarobotormodelisonlyonewayofdoing.VREPoffersmanydifferentways(alsocombined),havealookattheexternalcontrollertutorial,orattheplugintutorial.