Skip to content

Commit

Permalink
Skip publishing a topic with no subscribers (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroaki Masuzawa <[email protected]>
  • Loading branch information
Hiroaki-Masuzawa and Hiroaki Masuzawa authored Jun 26, 2023
1 parent 28ec820 commit cc3d8a1
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/plugin/BodyROSItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ void BodyROSItem::updateForceSensor
if(!sensor->on()){
return;
}
if(publisher.getNumSubscribers() == 0){
return;
}
geometry_msgs::WrenchStamped force;
force.header.stamp.fromSec(io->currentTime());
force.header.frame_id = sensor->name();
Expand All @@ -388,6 +391,9 @@ void BodyROSItem::updateRateGyroSensor
if(!sensor->on()){
return;
}
if(publisher.getNumSubscribers() == 0){
return;
}
sensor_msgs::Imu gyro;
gyro.header.stamp.fromSec(io->currentTime());
gyro.header.frame_id = sensor->name();
Expand All @@ -404,6 +410,9 @@ void BodyROSItem::updateAccelSensor
if(!sensor->on()){
return;
}
if(publisher.getNumSubscribers() == 0){
return;
}
sensor_msgs::Imu accel;
accel.header.stamp.fromSec(io->currentTime());
accel.header.frame_id = sensor->name();
Expand All @@ -420,6 +429,9 @@ void BodyROSItem::updateImu
if(!sensor->on()){
return;
}
if(publisher.getNumSubscribers() == 0){
return;
}
sensor_msgs::Imu imu;
imu.header.stamp.fromSec(io->currentTime());
imu.header.frame_id = sensor->name();
Expand All @@ -439,6 +451,9 @@ void BodyROSItem::updateVisionSensor
if(!sensor->on()){
return;
}
if(publisher.getNumSubscribers() == 0){
return;
}
sensor_msgs::Image vision;
vision.header.stamp.fromSec(io->currentTime());
vision.header.frame_id = sensor->name();
Expand All @@ -465,6 +480,9 @@ void BodyROSItem::updateRangeVisionSensor
if(!sensor->on()){
return;
}
if(publisher.getNumSubscribers() == 0){
return;
}
sensor_msgs::PointCloud2 range;
range.header.stamp.fromSec(io->currentTime());
range.header.frame_id = sensor->name();
Expand Down Expand Up @@ -539,6 +557,9 @@ void BodyROSItem::updateRangeSensor
if(!sensor->on()){
return;
}
if(publisher.getNumSubscribers() == 0){
return;
}
sensor_msgs::LaserScan range;
range.header.stamp.fromSec(io->currentTime());
range.header.frame_id = sensor->name();
Expand Down Expand Up @@ -571,6 +592,9 @@ void BodyROSItem::update3DRangeSensor
if(!sensor->on()){
return;
}
if(publisher.getNumSubscribers() == 0){
return;
}
sensor_msgs::PointCloud2 range;
// Header Info
range.header.stamp.fromSec(io->currentTime());
Expand Down Expand Up @@ -645,6 +669,9 @@ void BodyROSItem::update3DRangeSensor
if(!sensor->on()){
return;
}
if(publisher.getNumSubscribers() == 0){
return;
}
sensor_msgs::PointCloud range;
// Header Info
range.header.stamp.fromSec(io->currentTime());
Expand Down

0 comments on commit cc3d8a1

Please sign in to comment.