Gazebo机器人仿真学习探索笔记六工具和实用程序Word格式文档下载.docx
《Gazebo机器人仿真学习探索笔记六工具和实用程序Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《Gazebo机器人仿真学习探索笔记六工具和实用程序Word格式文档下载.docx(12页珍藏版)》请在冰豆网上搜索。
Currentstateofeachmodelinthescene,aswellasthestateofeachlinkandjointinthemodel.Thisincludesinformationsuchasinstantaneouspose,velocity,accelerationandforces.
Currentposeofeachlightintheworld.
Tip:
Youcanfindthewholespecfortheworldstatehere.
Inthistutorialwewillrecordafewlogfilesandthentakeapeekinsidethemattheend.
Recordalog
LoggingfromtheGUI
Startyoursimulation.Here,asanexample,wehaveasimpleworldwithadoublependulum.
Clickontheloggingicononthetopright,orhitCtrl+DtobringuptheDataLogger.
YoucanchoosethedirectorywhereyourlogfilewillbesavedbyclickingtheBrowsebutton.Bydefault,logfilesGotothe~/.gazebo/logdirectory.Inthisexample,wewillsaveitinthe~/logs/double_pendulum/directory.
Clickontheredbuttontostartrecording.Youshouldseethenumberofbytesinyourlogfileincreasingontheright.
Note:
Forefficiency,onlymodelsandlightswhichmoveovertimearelogged.Ifyoursceneisstatic,thenumberofbytesinyourlogfilewillnotincrease.Thisalsomeansthatthenumberofsamplesinyourlogfilemaybedifferentfromthenumberofiterationsinsimulation.
Clickontheredbuttonagaintostoplogging.
ExpandRecordingstoseethepathtothestate.logfilewhichwasgenerated.Itwillbeinsideatime-stampeddirectory.
Loggingfromthecommandline
Fromthecommandline,itispossibletologthewholesimulationfromthemomentGazebostartsrunninguntilitstops,ortotriggerloggingfromanarbitarytime.
Loggingthewholesimulation
Asanexample,youcanrecordtherandom_velocity.worldasfollows:
gazebo-r--record_path~/logs/random_velocityworlds/random_velocity.world
Youcanseealistofalloftheavailableloggingoptionsbyrunninggazebo--help.
-p[--play]arg:
Playalogfile.
-r[--record]:
RecordalogfromthemomentGazeboisopeneduntilitisclosed.
--record_encodingarg:
Compressionencodingformatforlogdata.Theoptionsarezlib(default),bz2andtxt.
ThelogfilewillonlybeterminatedwhenGazeboisclosed.Youcancheckthefilewascreatedbylookingintothepathgiven:
$ls~/logs/random_velocity/
state.log
Loggingpartofthesimulation
Gazeboalsoprovidesthegzlogtool,whichcanbeusedtotriggerloggingatanymoment.WhileGazeboisrunning,openanotherterminalandrunthefollowingtostartrecording:
gzlog-d1
Andtostop:
gzlog-d0
Checkoutgzlog--helpforotheroptions.
Playbackalogfile
Onceyouhavealogfile,youcanreplayitvisuallyorintrospectitinseveralways.
VisualizeinGUI
Currently,itisnotpossibletoopenalogfilefromtheGUI,soplaybackmustbestartedfromthecommandline.SimplystartGazebousingthe-poptiontospecifyalogfile,suchastheonewerecordedearlier:
gazebo-u-p~/logs/double_pendulum/2016-01-25T15\:
09\:
49.677400/gzserver/state.log
The-uoptionstartsthelogpaused.
Gazebowillopeninplaybackmode.Youcanplay,pause,rewindandstepthroughtheplayback.
UsePlay/Pausetostoptheplayback.
UseRewind/Forwardtoskiptothebeginning/endofthefile.
UseStepback/Stepforwardtoskipsamples.Thenumberofsamplesskippedeachtimeyoupressastepbuttoncanbechangedintheboxbelow.Samplesmightbeanynumberofiterationsandsecondsapart.
Dragthecurrenttimemarkeranddropittoskipthroughthelog.
Inputacurrenttimeontherighttoskiptothatsample.
Commandlinetools
Asmentionedabove,thegzlogtoolprovidesseveraloptionsforintrospectingyourlogfile.Checkoutthistutorialforlogfiltering,forexample.
Here,let'
squicklygooverhowyouwouldtakealookattherecordedstates.
We'
lluse-stostepthrougharecordedfile,likethis:
gzlog-s-f~/logs/double_pendulum/2016-01-25T15\:
You'
llseethefullinitialSDFrepresentationoftheworld,somethinglikethis:
<
?
xmlversion='
1.0'
>
gazebo_log>
header>
log_version>
1.0<
/log_version>
gazebo_version>
7.0.0~pre1<
/gazebo_version>
rand_seed>
10622214<
/rand_seed>
log_start>
43380000000<
/log_start>
log_end>
69651000000<
/log_end>
/header>
chunkencoding='
txt'
!
[CDATA[
sdfversion='
1.6'
worldname='
default'
(...)
<
lightname='
sun'
type='
directional'
/light>
modelname='
ground_plane'
/model>
double_pendulum_with_base'
/world>
/sdf>
]]>
/chunk>
---Pressspacetocontinue,'
q'
toquit---
Asyoupressspace,youwillstepthroughthesubsequentstates.You'
llnotethatthestatesaremorecompactandonlycontaininformationaboutwhathaschangedintheworld.Here'
sanexampleofastate:
sdfversion='
stateworld_name='
sim_time>
/sim_time>
real_time>
43478499228<
/real_time>
wall_time>
1453763389677873530<
/wall_time>
iterations>
43380<
/iterations>
pose>
1.140-1.074-0.0000.000-0.0000.000<
/pose>
scale>
1.0001.0001.000<
/scale>
linkname='
base'
1.13998-1.07367-0.000000.000000.00000-0.00042<
velocity>
-0.00000.0000-0.00050.00040.00300.0001<
/velocity>
/link>
lower_link'
1.38969-1.798151.41059-2.453510.00000-0.00042<
0.0042-0.25570.26591.96940.00480.0001<
upper_link'
1.13999-1.073672.100002.33144-0.00000-0.00042<
0.0063-0.0008-0.0005-0.37390.00320.0001<
0.0000.0000.0000.000-0.0000.000<
link'
0.000000.000000.000000.00000-0.000000.00000<
0.00000.00000.00000.0000-0.00000.0000<
/state>
Notethatthere'
snoinformationforthesunortheground_plane,sincetheyarenotmoving.
Logfiltering
Introduction
StatelogsarerecordingsofworldstateinformationfromGazebo.Stateincludespose,velocity,acceleration,andforcesappliedtoalllinksofallmodels.Gazebowillonlyrecordstateinformationformodelsthatchangeovertime.Astatelogfilecontainsaheader,theinitialworlddescription,andatimeseriesofstate.
GazeboLogCommandlinetool
Gazeboshipswithaloggingutilitythatisaccessedviathegzlogcommand.
Viewthehelpinformationusing:
gzhelplog
or
gzlog-h
ExampleUsage
Checkoutthetutorialonloggingandplaybackforanoverviewofwaystorecordalog.
Step1:
Createastatelogfile
Startbyremovingoldlogfiles
rm-rf~/.gazebo/log/*
WewillusethePR2worldtocreateastatelogfile.
StartbyrunningtheGazeboserverwiththe-rcommandlineoption
gzserver-rworlds/pr2.world
Afterafewseconds,stoptheserverusingctrl-c.
Anewtimestampeddirectoryshouldexistin~/.gazebo/logwithonesubdirectoryandastate.logfile.Hereisanexample
~/.gazebo/log/2013-07-25T07\:
29\:
05.122275/gzserver/state.log
YoucanverifythislogfilebyreplayingitinGazebo.
gazebo-p~/.gazebo/log/*/gzserver/state.log
Step2:
Filterastatelogfile
Thegzlogcommandlinetoolprovidesmechanismsforsteppingthroughalogfileandechoingthecontentsofalogfiletoscreen.Theechotoscreenfeaturecanbecombinedwithafiltertoproducealogfilethatcontainsspecificinformationsuchasjusttheposeofmodelsandlinks.
Tryechoingtherecordedstatelogfiletoscreen.
gzlog-e-f~/.gazebo/log/*/gzserver/state.log
Youshouldseealotofinformationscrollby.
Nowlet'
sremoveallvelocity,acceleration,andforceinformationfromthelogfile.Thiswillleavejustposeinformation.
gzlog-e-f~/.gazebo/log/*/gzserver/state.log--filter*.pose/*.pose
The--filteroptionisaflexiblecommandlineargumenttoextractinformationfromalogfile.
ItisalsopossibletofilterbasedonsimulationtimeusingaHzfilter.Forexample,wecanoutputstateinformationat30Hzusing:
gzlog-e-f~/.gazebo/log/*/gzserver/state.log-z30
Thesefilterscanbecombinedandpipedtoafileforplayback.Thismaytakesometimedependingonthesizeofthestate.log.
gzlog-e-f~/.gazebo/log/*/gzserver/state.log-z30--filter*.pose/*.pose>
/tmp/filtered_state.log
ThislogfilecanthenbereplayedinGazebo
gazebo-p/tmp/filtered_state.log
ApplyingForce/Torque
Thistutorialwillexplainhowtoapplyforceand/ortorquetomodelsduringsimulationusingthegraphicaluserinterface.
Applyingforceandtorqueexamples
Let'
sgothroughanexampleofapplyingforceandtorquetosimplemodels.OpenGazeboandfromtheinserttab,insertaSimpleArmintothescene.Then,fromthetoptoolbar,insertabox.Makesurethesimulationisnotpaused.
Applyforcetoalink
Wewantto