Gazebo 机器人仿真流程之 World 类

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

/// \class World World.hh physics/physics.hh
/// \brief 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)加载场景

/// \brief 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)初始化场景

/// \brief 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)运行/停止仿真场景

/// \brief 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);

/// \brief 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();

/// \brief Finalize the world.
/// Call this function to tear-down the world.
public: void Fini();

/// \brief 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)仿真步

/// \brief Step the world forward in time.
/// \param[in] _steps The number of steps the World should take.
public: void Step(const unsigned int _steps);

/// \brief 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);

/// \brief Function to run physics. Used by physicsThread.
private: void RunLoop();

/// \brief Step the world once.
private: void Step();

/// \brief Step the world once by reading from a log file.
private: void LogStep();

/// \brief Update the world.
private: void Update();

(6)载入插件

/// \brief 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);

/// \brief Remove a running plugin.
/// \param[in] _name The unique name of the plugin to remove.
public: void RemovePlugin(const std::string &_name);

(7)载入

/// \brief Load all plugins.
///
/// Load all plugins specified in the SDF for the model.
private: void LoadPlugins();

/// \brief 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);

/// \brief Load a model.
/// \param[in] _sdf SDF element containing the Model description.
/// \param[in] _parent Parent of the model.
/// \return Pointer to the newly created Model.
private: ModelPtr LoadModel(sdf::ElementPtr _sdf, BasePtr _parent);

/// \brief Load a light.
/// \param[in] _sdf SDF element containing the Light description.
/// \param[in] _parent Parent of the light.
/// \return Pointer to the newly created Light.
public: LightPtr LoadLight(const sdf::ElementPtr &_sdf, const BasePtr &_parent);

/// \brief Load an actor.
/// \param[in] _sdf SDF element containing the Actor description.
/// \param[in] _parent Parent of the Actor.
/// \return Pointer to the newly created Actor.
private: ActorPtr LoadActor(sdf::ElementPtr _sdf, BasePtr _parent);

/// \brief Load a road.
/// \param[in] _sdf SDF element containing the Road description.
/// \param[in] _parent Parent of the Road.
/// \return Pointer to the newly created Road.
private: RoadPtr LoadRoad(sdf::ElementPtr _sdf, BasePtr _parent);

(8)回调函数

/// \brief Pause callback.
/// \param[in] _p True if paused.
private: void OnPause(bool _p);

/// \brief Step callback.
private: void OnStep();

/// \brief Called when a world control message is received.
/// \param[in] _data The world control message.
private: void OnControl(ConstWorldControlPtr &_data);

/// \brief Called when log playback control message is received.
/// \param[in] _data The log playback control message.
private: void OnPlaybackControl(ConstLogPlaybackControlPtr &_data);

/// \brief Called when a request message is received.
/// \param[in] _msg The request message.
private: void OnRequest(ConstRequestPtr &_msg);

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


posted @ 2020-04-18 17:16  wghou09  阅读(718)  评论(0编辑  收藏  举报