Performance: Gazebo plugins for sensors
This affects simulation frame rate and real-time responsiveness by controlling how sensor data is generated and processed in Gazebo.
Jump into concepts and practice - no test required
class GoodLidarPlugin : public SensorPlugin { private: common::Time last_update_; double update_rate_ = 10.0; // 10 Hz public: void OnUpdate() { common::Time current_time = this->sensor->LastUpdateTime(); if ((current_time - last_update_).Double() >= 1.0 / update_rate_) { PublishLidarData(); last_update_ = current_time; } } };
class BadLidarPlugin : public SensorPlugin {
public:
void OnUpdate() {
// Publish data every simulation iteration without throttling
PublishLidarData();
}
};| Pattern | CPU Usage | Simulation Frame Rate | Data Freshness | Verdict |
|---|---|---|---|---|
| Unthrottled sensor updates | High | Low | Very fresh | [X] Bad |
| Throttled sensor updates | Medium | High | Fresh enough | [OK] Good |
| Heavy processing in update loop | Very High | Very Low | Fresh | [X] Bad |
| Offloaded processing | Medium | High | Slightly delayed | [OK] Good |
<plugin name="camera_plugin" filename="libgazebo_ros_camera.so">
<ros>
<namespace>/robot/camera</namespace>
<remapping>/image_raw:=/camera/image_raw</remapping>
</ros>
</plugin>