zoukankan      html  css  js  c++  java
  • Gazebo 机器人仿真流程之 World 类

    在 Gazebo 中,World 类可以认为是场景容器,包含了仿真场景中的所有对象。

    /// class World World.hh physics/physics.hh
    /// rief The world provides access to all other object within a simulated
    /// environment.
    ///
    /// The World is the container for all models and their components
    /// (links, joints, sensors, plugins, etc), and WorldPlugin instances.
    /// Many core function are also handled in the World, including physics
    /// update, model updates, and message processing.
    

    World 类参见 gazebo/gazebo/physics/World.hh,其中主要为成员函数的定义。而其中的成员变量,即仿真场景中的对象,则包含在 WorldPrivate 中,参见gazebo/gazebo/physics/WorldPrivate.hh


    World 类中,定义了大量成员方法,具体来说,较为重要的有:

    (1)加载场景

    /// rief Load the world using SDF parameters.
    /// Load a world from and SDF pointer.
    /// param[in] _sdf SDF parameters.
    public: void Load(sdf::ElementPtr _sdf);
    

    (2)初始化场景

    /// rief Initialize the world.
    /// This is called after Load.
    /// param[in] _func function to be called when Poses are available.
    public: void Init(UpdateScenePosesFunc _func);
    

    (3)运行/停止仿真场景

    /// rief Run the world in a thread.
    /// Run the update loop.
    /// param[in] _iterations Run for this many iterations, then stop.
    /// A value of zero disables run stop.
    public: void Run(const unsigned int _iterations = 0);
    
    /// rief Stop the world.
    /// Request the update loop thread to stop. Wait for it to join if this
    /// function is called from another thread. Return immediately otherwise.
    public: void Stop();
    
    /// rief Finalize the world.
    /// Call this function to tear-down the world.
    public: void Fini();
    
    /// rief Remove all entities from the world.
    /// This function has delayed effect. Models are cleared at the end
    /// of the current update iteration.
    public: void Clear();
    

    (4)获取/设置 WorldPrivate 中(场景中)的成员变量

    
    

    (5)仿真步

    /// rief Step the world forward in time.
    /// param[in] _steps The number of steps the World should take.
    public: void Step(const unsigned int _steps);
    
    /// rief Run the world. This call blocks.
    /// Run the update loop.
    /// param[in] _iterations Run for this many iterations, then stop.
    /// A value of zero disables run stop.
    public: void RunBlocking(const unsigned int _iterations = 0);
    
    /// rief Function to run physics. Used by physicsThread.
    private: void RunLoop();
    
    /// rief Step the world once.
    private: void Step();
    
    /// rief Step the world once by reading from a log file.
    private: void LogStep();
    
    /// rief Update the world.
    private: void Update();
    

    (6)载入插件

    /// rief Load a plugin
    /// param[in] _filename The filename of the plugin.
    /// param[in] _name A unique name for the plugin.
    /// param[in] _sdf The SDF to pass into the plugin.
    public: void LoadPlugin(const std::string &_filename,
                            const std::string &_name,
                            sdf::ElementPtr _sdf);
    
    /// rief Remove a running plugin.
    /// param[in] _name The unique name of the plugin to remove.
    public: void RemovePlugin(const std::string &_name);
    

    (7)载入

    /// rief Load all plugins.
    ///
    /// Load all plugins specified in the SDF for the model.
    private: void LoadPlugins();
    
    /// rief Create and load all entities.
    /// param[in] _sdf SDF element.
    /// param[in] _parent Parent of the model to load.
    private: void LoadEntities(sdf::ElementPtr _sdf, BasePtr _parent);
    
    /// rief Load a model.
    /// param[in] _sdf SDF element containing the Model description.
    /// param[in] _parent Parent of the model.
    /// 
    eturn Pointer to the newly created Model.
    private: ModelPtr LoadModel(sdf::ElementPtr _sdf, BasePtr _parent);
    
    /// rief Load a light.
    /// param[in] _sdf SDF element containing the Light description.
    /// param[in] _parent Parent of the light.
    /// 
    eturn Pointer to the newly created Light.
    public: LightPtr LoadLight(const sdf::ElementPtr &_sdf, const BasePtr &_parent);
    
    /// rief Load an actor.
    /// param[in] _sdf SDF element containing the Actor description.
    /// param[in] _parent Parent of the Actor.
    /// 
    eturn Pointer to the newly created Actor.
    private: ActorPtr LoadActor(sdf::ElementPtr _sdf, BasePtr _parent);
    
    /// rief Load a road.
    /// param[in] _sdf SDF element containing the Road description.
    /// param[in] _parent Parent of the Road.
    /// 
    eturn Pointer to the newly created Road.
    private: RoadPtr LoadRoad(sdf::ElementPtr _sdf, BasePtr _parent);
    

    (8)回调函数

    /// rief Pause callback.
    /// param[in] _p True if paused.
    private: void OnPause(bool _p);
    
    /// rief Step callback.
    private: void OnStep();
    
    /// rief Called when a world control message is received.
    /// param[in] _data The world control message.
    private: void OnControl(ConstWorldControlPtr &_data);
    
    /// rief Called when log playback control message is received.
    /// param[in] _data The log playback control message.
    private: void OnPlaybackControl(ConstLogPlaybackControlPtr &_data);
    
    /// rief Called when a request message is received.
    /// param[in] _msg The request message.
    private: void OnRequest(ConstRequestPtr &_msg);
    

    World 类中,主要的成员函数也就这些吧。其余的,对于理解仿真流程也并不重要,因此不再去细究。


  • 相关阅读:
    【题解】Image Perimeters-C++
    【题解】士兵训练-C++
    【题解】丑数Humble Numbers-C++
    【题解】P1638 逛画展-C++
    【题解】P3069 [USACO13JAN]牛的阵容Cow Lineup-C++
    【题解】[Noip2010]机器翻译-C++
    【题解】间隔排列-C++
    【极大化剪枝】Power Hungry Cows-C++【没有用A*!】【超级简单!】
    【题解】跳房子-C++
    C#高级编程第11版
  • 原文地址:https://www.cnblogs.com/wghou09/p/12726889.html
Copyright © 2011-2022 走看看