22 #include <gazebo/common/Console.hh> 26 #include "osrf_gear/PopulationControl.h" 27 #include "osrf_gear/PopulationState.h" 36 public: std::unique_ptr<ros::NodeHandle>
rosnode;
60 this->
dataPtr->rosnode->shutdown();
70 <<
"unable to load plugin. Load the Gazebo system plugin " 71 <<
"'libgazebo_ros_api_plugin.so' in the gazebo_ros package)");
76 std::string robotNamespace =
"";
77 if (_sdf->HasElement(
"robot_namespace"))
79 robotNamespace = _sdf->GetElement(
80 "robot_namespace")->Get<std::string>() +
"/";
83 std::string controlTopic =
"population/control";
84 if (_sdf->HasElement(
"control_topic"))
85 controlTopic = _sdf->Get<std::string>(
"control_topic");
87 std::string stateTopic =
"population/state";
88 if (_sdf->HasElement(
"state_topic"))
89 stateTopic = _sdf->Get<std::string>(
"state_topic");
97 auto v = std::getenv(
"ARIAC_COMPETITION");
101 this->
dataPtr->controlService =
102 this->
dataPtr->rosnode->advertiseService(controlTopic,
108 osrf_gear::PopulationState>(stateTopic, 1000);
114 PopulationPlugin::Reset();
118 osrf_gear::PopulationControl::Request &_req,
119 osrf_gear::PopulationControl::Response &_res)
123 if (_req.action ==
"pause")
125 else if (_req.action ==
"resume")
127 else if (_req.action ==
"restart")
131 gzerr <<
"ROSPopulationPlugin::OnPopulationControl() error: Illegal " 132 <<
"action received: [" << _req.action <<
"]" << std::endl;
133 _res.success =
false;
142 osrf_gear::PopulationState
msg;
144 this->
dataPtr->statePub.publish(msg);
virtual void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
bool Enabled() const
True when the plugin is enabled or false if it's paused.
GZ_REGISTER_WORLD_PLUGIN(ROSPopulationPlugin)
void Pause()
Pause the object population.
void Resume()
Resume the object population after a pause.
ROSCPP_DECL bool isInitialized()
virtual ~ROSPopulationPlugin()
Destructor.
ros::ServiceServer controlService
Receives service calls to control the plugin.
virtual void Reset()
Documentation inherited.
std::unique_ptr< ros::NodeHandle > rosnode
ROS node handle.
#define ROS_FATAL_STREAM(args)
ROSPopulationPlugin()
Constructor.
bool OnPopulationControl(osrf_gear::PopulationControl::Request &_req, osrf_gear::PopulationControl::Response &_res)
Receives messages for controlling the object population plugin on the object population's topic...
virtual void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
virtual void Publish() const
Overwrite this method for sending periodic updates with the plugin state.
std::unique_ptr< ROSPopulationPluginPrivate > dataPtr
A plugin that allows models to be spawned at a given location in a specific simulation time...
ROS interface for the Population plugin.
virtual void Restart()
Restart the the object population.
ros::Publisher statePub
Publishes the state of the plugin.