19 #include "gazebo/physics/physics.hh"    20 #include "gazebo/common/common.hh"    21 #include "gazebo/gazebo.hh"    29   private: physics::WorldPtr 
world;
    32   public: 
void Load(physics::WorldPtr _parent, sdf::ElementPtr )
    34     this->world = _parent;
    36     transport::NodePtr node(
new transport::Node());
    39     node->Init(_parent->GetName());
    42     std::string sensorStateChangeTopic =
    43       "~/laser/proximity_ray_plugin/state_change";
    48     std::string conveyorControlTopic =
    49       "~/conveyor_belt_contact/conveyor_belt_plugin/control_command";
    51       node->Advertise<msgs::Header>(conveyorControlTopic);
    53     this->beltVelocity = 0.5;
    58     bool controlCommand = 
true;
    59     double desiredVelocity = controlCommand*this->
beltVelocity;
    60     msg.set_str_id(std::to_string(desiredVelocity));
    61     msgs::Set(msg.mutable_stamp(), _parent->GetSimTime());
    64     this->controlPub->Publish(msg);
    69     gzdbg << 
"Sensor state changed.\n";
    72     bool sensorValue = _msg->index();
    74     std::string outputFunction = _msg->str_id();
    75     if (
"normally_open" == outputFunction) {
    76       controlCommand = !sensorValue;
    78     else if (
"normally_closed" == outputFunction) {
    79       controlCommand = sensorValue;
    82       gzerr << 
"output_function can only be either normally_open or normally_closed" << std::endl;
    85     double desiredVelocity = controlCommand*this->
beltVelocity;
    86     msg.set_str_id(std::to_string(desiredVelocity));
    87     msgs::Set(msg.mutable_stamp(), this->world->GetSimTime());
    90     this->controlPub->Publish(msg);
 
GZ_REGISTER_WORLD_PLUGIN(ROSPopulationPlugin)
transport::PublisherPtr controlPub
void OnSensorStateChange(ConstHeaderPtr &_msg)
void Load(physics::WorldPtr _parent, sdf::ElementPtr)
transport::SubscriberPtr sensorSub