ros-simulation / gazebo_ros_pkgs

Wrappers, tools and additional API's for using ROS with Gazebo
http://wiki.ros.org/gazebo_ros_pkgs
770 stars 773 forks source link

Issue in compliling a plugin inherited from gazebo_plugins/gazebo_ros_camera #1404

Open Luckykantnayak opened 2 years ago

Luckykantnayak commented 2 years ago

Bug report

Required Info:

include "gazebo_light_sensor/visibility_control.h"

include <gazebo_plugins/gazebo_ros_camera.hpp>

include

include <rclcpp/rclcpp.hpp>

include <sensor_msgs/msg/illuminance.hpp>

namespace gazebo {

class LightSensorPlugin : public gazebo_plugins::GazeboRosCamera { public: LightSensorPlugin();

  virtual ~LightSensorPlugin();
  void Load(gazebo::sensors::SensorPtr _parent, sdf::ElementPtr _sdf);
protected:  void OnNewFrame(const unsigned char *_image,
    unsigned int _width, unsigned int _height,
    unsigned int _depth, const std::string &_format) override;
std::shared_ptr<rclcpp::Node> ros_node_ = rclcpp::Node::make_shared("light_sensor_plugin");
rclcpp::Publisher<sensor_msgs::msg::Illuminance>::SharedPtr sensor_pub_;

double _fov;
double _range;

};

} // namespace gazebo_light_sensor

endif // GAZEBO_LIGHT_SENSOR__LIGHT_SENSOR_PLUGINHPP

**light_sensor_plugin.cpp**

include "gazebo_light_sensor/light_sensor_plugin.hpp"

include <gazebo/common/Plugin.hh>

include

include <gazebo/sensors/Sensor.hh>

include <gazebo/sensors/CameraSensor.hh>

include <gazebo/sensors/SensorTypes.hh>

include <sensor_msgs/msg/illuminance.hpp>

namespace gazebo { //GZ_REGISTER_SENSOR_PLUGIN(LightSensorPlugin) LightSensorPlugin::LightSensorPlugin() :_fov(6),_range(10) {

}

LightSensorPlugin::~LightSensorPlugin() { RCLCPP_DEBUG_STREAM(rosnode->get_logger(), "Camera unloaded"); } void LightSensorPlugin::Load(gazebo::sensors::SensorPtr _parent, sdf::ElementPtr _sdf) { gazebo_plugins::GazeboRosCamera::Load(_parent,_sdf); if(!rclcpp::ok()) { RCLCPP_FATAL_STREAM(rosnode->get_logger(),"A ROS node for Gazebo has not been initialized, unable to load plugin. " << "Load the Gazebo system plugin 'libgazebo_ros_api_plugin.so' in the gazebo_ros package)"); return; }

sensorpub = rosnode->create_publisher("lightSensor",1);

} void LightSensorPlugin::OnNewFrame(const unsigned char *_image, unsigned int _width, unsigned int _height, unsigned int _depth, const std::string &_format) {

sensor_msgs::msg::Illuminance msg;
msg.header.stamp = rclcpp::Clock().now();
msg.header.frame_id = "";
//msg.header.seq = seq;

int startingPix = _width * ( (int)(_height/2) - (int)( _fov/2)) - (int)(_fov/2);

double illum = 0;
for (int i=0; i<_fov ; ++i)
{
  int index = startingPix + i*_width;
  for (int j=0; j<_fov ; ++j)
    illum += _image[index+j];
}

msg.illuminance = illum/(_fov*_fov);
msg.variance = 0.0;

sensor_pub_->publish(msg);

}

} // namespace gazebo_light_sensor



#### Error while building package
![Screenshot from 2022-07-02 12-29-21](https://user-images.githubusercontent.com/53001392/176990457-e205247e-600e-4d76-824b-529a58930e40.png)

#### Additional information

<!-- If you are reporting a bug delete everything below
     If you are requesting a feature deleted everything above this line -->
----
@shiveshkhaitan  @jacobperron  @davetcoleman @ahcorde @scpeters
#1959 #
jacobperron commented 2 years ago

Looks like the gazebo_ros camera plugin is missing a header that should be included. As a workaround in your plugin, you can try including the missing the rclcpp header(s) before including gazebo_ros_camera.hpp. E.g. #include "rclcpp/rclcpp.hpp"

jacobperron commented 2 years ago

I've proposed a fix in https://github.com/ros-simulation/gazebo_ros_pkgs/pull/1408