Gazebo | Ignition | Community
Ask Your Question

pointing to a ray sensor

asked 2016-12-05 04:02:12 -0600

Robot_sim_person gravatar image

updated 2016-12-06 10:42:51 -0600

chapulina gravatar image

(New to gazebo)

Hi, I'm trying to access the ray sensor part of the hoyuko sensor in c++:

<sensor name="laser" type="ray">

    <pose>0.01 0 0.0175 0 -0 0</pose>
















    <plugin name="laser" filename="" />





But I can't find or figure out the code required anywhere. I've looked through the other questions on this site, the tutorials and the API. The main thing I've figured out is that to use the functions in RaySensor you need a reference object. But I don't want to create a new object as it already exists in my model. instead I made a RaySensorPtr but have been unable to point to the RaySensor.

Before showing the code I should note that the Hoyuko model is a sub-model of my model (i.e. this->model does not reference the hoyuko model)

public: void OnUpdate(const common::UpdateInfo & /*_info*/)
  // Apply a small linear velocity to the model.
  this->model->SetLinearVel(math::Vector3(.3, 0, 0));

  int sensor_num = this->model->GetSensorCount();

  sensors::SensorPtr model_sensor = sensors::get_sensor("laser"); //points to sensor

  //RayShapePtr MultiRayShape::Ray(const unsigned int 0) const //DOESN'T WORK

  gazebo::sensors::RaySensorPtr model_ray_sensor;

  //double testNum = model_sensor->ray->AngleMax(); DOESN'T WORK

  //double testNum = this->model->sensor->ray->AngleMax(); DOESN'T WORK

  //model_ray_sensor = sensors::RaySensor::GetLaserShape(); DOESN'T WORK

  //physics::MultiRayShapePtr multi_ray_sensor = sensors::RaySensor::GetLaserShape(); DOESN'T WORK

  //model_ray_sensor = sensors::RaySensor::get_sensor("laser"); DOESN'T WORK

  double sensor_update_rate = model_sensor->GetUpdateRate(); //from generic sensor class

  printf("Sensor name: %f \n", sensor_update_rate); //%f NOT %d!!!!
  //printf("Sensor resolution: %f \n", sensor_angle_resolution); //%f NOT %d!!!!
  //printf("Sensors: %u \n", sensorNum);

TLDR; I can point to the sensor class and print it's update rate. But I can't figure out how to point to the raysensor class.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-12-06 10:41:50 -0600

chapulina gravatar image

You can use a dynamic pointer cast:

sensors::RaySensorPtr ray_sensor = std::dynamic_pointer_cast<sensors::RaySensor>(model_sensor);
edit flag offensive delete link more


This worked perfectly, thanks!

Robot_sim_person gravatar imageRobot_sim_person ( 2016-12-07 04:36:41 -0600 )edit

Question Tools

1 follower


Asked: 2016-12-05 04:02:12 -0600

Seen: 1,006 times

Last updated: Dec 06 '16