0
$\begingroup$

Gazebo Answers logo

In my sensor plugin, I have a ray sensor which casts a single ray. From this ray, I would like to get the name of the entity with which the ray intersects.

I have a working workaround by creating a test_ray (physics::RayShapePtr) and calling test_ray->GetIntersection() every time my ray measures a finite distance. However, it doesn't feel like the right way to do and furthermore, I get occasional segfaults which are caused somehow by underlying collision checks of the test_ray->GetIntersection() call.

Is there a better way to get the entity name?

In my plugin I have access to the parent ray sensor which is of type sensors::RaySensorPtr. From the parent sensor I can access the LaserShape (physics::MultiRayShapePtr), but apparently not the single ray (tried getChild(0) already).

Cheers,


Originally posted by Hans-Joachim Krauch on Gazebo Answers with karma: 5 on 2016-04-01

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Gazebo Answers logo

I'm currently looking at Gazebo default, which may not match with your version of gazebo. I think you can use the following API calls:

  1. physics::MultiRayShapePtr RaySensor::LaserShape() const
  2. RayShapePtr MultiRayShape::Ray(const unsigned int _rayIndex) const
  3. void RayShape::GetIntersection(double &_dist, std::string &_entity)

An implementation might look like:

RaySensorPtr mySensor;
double dist;
std::string entity;

// Should check these pointers for NULL
mySensor->LaserShape()->Ray(0)->GetIntersection(dist, entity);

std::cout << "My ray intersected entity[" << entity << "] at a distance of[" << dist << "]\n";

Originally posted by nkoenig with karma: 7676 on 2016-04-01

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by Hans-Joachim Krauch on 2016-04-04:
Ah ok, I see you have added this functionality in Gazebo 7. I'm bound to 6.5 however (forgot to mention this), but it helps me anyway, thanks a lot!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.