Gazebo | Ignition | Community
Ask Your Question
0

How to properly use get_sensor?

asked 2017-01-16 03:37:56 -0500

Robot_sim_person gravatar image

Hi,

I have some code which uses get_sensor to get a laser sensor, however when I want to use two of this model, they get muddled up as I can't reference the full model name.

sensors::SensorPtr model_sensor;

model_sensor = sensors::get_sensor("laser"); // this is fine when there's only one laser sensor

I want to get something like:

model_sensor = sensors::get_sensor("my_model::hoyoko::link::laser"); but I'm confident this is wrong as gazebo crashes with this new code.

I have the get_sensor refference : http://osrf-distributions.s3.amazonaw... (Ctrl f "get_sensor" to find the relevant part)

But I don't fully understand what they mean by " This name should be fully scoped. This means _name = world_name::model_name::link_name::sensor_name."

Any help would be much appreciated, thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-01-17 08:39:39 -0500

Robot_sim_person gravatar image

It turns out you can either use just the sensor_name for the string, or the whole thing. But nothing in between (i.e. "model_name::link_name::sensor_name" is not acceptable.

An easy way to get an example of this is to print GetScopedName() on the terminal ( "model_sensor->GetScopedName()" ) .

edit flag offensive delete link more

Comments

Thanks for posting your solution. I'm curious, what do you mean by "the whole thing" if it's not the scoped name? Maybe this is a bug in Gazebo, it shouldn't crash with a bad string.

chapulina gravatar imagechapulina ( 2017-01-17 12:19:51 -0500 )edit
1

If I try to find the sensor without the world name, i.e: sensorLocation = /*"default::" +*/ this->model->GetName() + "::hokuyo::link::laser"; the get_sensor function will crash. But it will work fine if I either include all the names, or just the sensor name. The whole thing is: sensorLocation = "default::" + this->model->GetName() + "::hokuyo::link::laser"; Just the sensor name is: sensorLocation = "laser";

Robot_sim_person gravatar imageRobot_sim_person ( 2017-01-18 04:19:19 -0500 )edit

Thanks for the clarification

chapulina gravatar imagechapulina ( 2017-01-18 11:03:22 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-16 03:37:56 -0500

Seen: 249 times

Last updated: Jan 17 '17