Gazebo | Ignition | Community
Ask Your Question
0

pointing to a ray sensor

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

Robot_sim_person gravatar image

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

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>

    <ray>

      <scan>

        <horizontal>

          <samples>640</samples>

          <resolution>1</resolution>

          <min_angle>-2.26889</min_angle>

          <max_angle>2.268899</max_angle>

        </horizontal>

      </scan>

      <range>

        <min>0.08</min>

        <max>10</max>

        <resolution>0.01</resolution>

      </range>

    </ray>

    <plugin name="laser" filename="libRayPlugin.so" />

    <always_on>1</always_on>

    <update_rate>30</update_rate>

    <visualize>true</visualize>

  </sensor>

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
1

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

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

Comments

This worked perfectly, thanks!

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

Question Tools

1 follower

Stats

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

Seen: 1,017 times

Last updated: Dec 06 '16