17 #include "gazebo/physics/physics.hh" 18 #include "gazebo/common/common.hh" 19 #include "gazebo/gazebo.hh" 24 #include <osrf_gear/ConveyorBeltControl.h> 25 #include <osrf_gear/ConveyorBeltState.h> 26 #include <osrf_gear/LogicalCameraImage.h> 27 #include <osrf_gear/Model.h> 28 #include <osrf_gear/Proximity.h> 39 private: physics::WorldPtr
world;
51 public:
void Load(physics::WorldPtr _parent, sdf::ElementPtr )
56 ROS_FATAL_STREAM(
"A ROS node for Gazebo has not been initialized, unable to load plugin. " 57 <<
"Load the Gazebo system plugin 'libgazebo_ros_api_plugin.so' in the gazebo_ros package)");
61 this->world = _parent;
65 std::string sensorStateChangeTopic =
"/ariac/proximity_sensor_changed";
66 this->proximitySensorSub =
67 this->rosnode->
subscribe(sensorStateChangeTopic, 1000,
71 std::string breakBeamStateChangeTopic =
"/ariac/break_beam_changed";
73 this->rosnode->
subscribe(breakBeamStateChangeTopic, 1000,
77 std::string logicalCameraImageTopic =
"/ariac/logical_camera";
78 this->logicalCameraImageSub =
79 this->rosnode->
subscribe(logicalCameraImageTopic, 1000,
83 std::string conveyorControlTopic =
"/conveyor/control";
84 this->controlClient = this->rosnode->
serviceClient<osrf_gear::ConveyorBeltControl>(
85 conveyorControlTopic);
87 this->beltVelocity = 0.5;
95 gzdbg <<
"Sensor state changed\n";
97 bool sensorValue = _msg->object_detected;
98 bool controlCommand = !sensorValue;
104 osrf_gear::ConveyorBeltState controlMsg;
105 controlMsg.velocity = velocity;
106 osrf_gear::ConveyorBeltControl controlRequest;
107 controlRequest.request.state = controlMsg;
108 this->controlClient.
call(controlRequest);
113 bool modelDetected =
false;
114 for (osrf_gear::Model model : _msg->models)
116 if (model.type == this->searchModelType)
118 modelDetected =
true;
122 if (modelDetected != this->modelDetected)
127 gzdbg <<
"Object no longer detected by logical camera\n";
129 gzdbg <<
"Object detected by logical camera\n";
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void OnLogicalCameraImage(const osrf_gear::LogicalCameraImage::ConstPtr &_msg)
GZ_REGISTER_WORLD_PLUGIN(ROSPopulationPlugin)
void OnSensorStateChange(const osrf_gear::Proximity::ConstPtr &_msg)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL bool isInitialized()
bool call(MReq &req, MRes &res)
void Load(physics::WorldPtr _parent, sdf::ElementPtr)
ros::Subscriber proximitySensorSub
#define ROS_FATAL_STREAM(args)
ros::NodeHandle * rosnode
ros::ServiceClient controlClient
void SendControlRequest(double velocity)
ros::Subscriber breakBeamSub
std::string searchModelType
ros::Subscriber logicalCameraImageSub