0
$\begingroup$

I'm trying to implement a simple light sensor plugin in Gazebo Ignition; this will be output measurements based on the distance between the object (where the plugin is attached) and the light sources. My idea is to store the poses of the lights in a vector named lightPoses

The problem is that I'm not able to access to the position of the light sources. I tried to follow this turorial https://gazebosim.org/api/gazebo/6.6/createsystemplugins.html but I'm not able to get the light pose with the EntityComponentManager. This is my code for the Configure interface:

void LightSensor::Configure(const ignition::gazebo::Entity &_entity,
const std::shared_ptr<const sdf::Element> &_sdf,
ignition::gazebo::EntityComponentManager &_ecm,
ignition::gazebo::EventManager &/*_eventMgr*/)
{
    
    _ecm.Each<ignition::gazebo::components::Light,
            ignition::gazebo::components::Pose>(
            [&](const ignition::gazebo::Entity &_entity,
            const ignition::gazebo::components::Light *,
            const ignition::gazebo::components::Pose *_pose) -> bool
    {   

        
        ignition::math::Pose3d light_pose = _pose->Data();
        lightPoses.push_back(light_pose);

        

        return true;

    });

    // set the topic for sensor data publication
    std::string topic = ignition::gazebo::scopedName(_entity, _ecm) + "/" + "light_value";
    topic = ignition::transport::TopicUtils::AsValidTopic(topic);

    // create the publisher
    this->publisher = this->node.Advertise<ignition::msgs::Float>(topic);


}

And this is my SDF file:

   <world name="text">
    <light type="point" name="point_light1">
        <intensity>1</intensity>
        <pose>0 -0.6 1.5 0 0 0</pose>
        <diffuse>1 1 0 1</diffuse>
        <specular>.1 .1 .1 1</specular>
        <attenuation>
            <range>4</range>
            <linear>1</linear>
            <constant>0.8</constant>
            <quadratic>0</quadratic>
        </attenuation>
        <cast_shadows>false</cast_shadows>
    </light>


    <light type="point" name="point_light2">
        <intensity>1</intensity>
        <pose>1.5 -0.6 1.5 0 0 0</pose>
        <diffuse>1 1 0 1</diffuse>
        <specular>.1 .1 .1 1</specular>
        <attenuation>
            <range>4</range>
            <linear>1</linear>
            <constant>0.8</constant>
            <quadratic>0</quadratic>
        </attenuation>
        <cast_shadows>false</cast_shadows>
    </light>

    <light type="point" name="point_light3">
        <intensity>1</intensity>
        <pose>1.5 0.6 1.5 0 0 0</pose>
        <diffuse>1 1 0 1</diffuse>
        <specular>.1 .1 .1 1</specular>
        <attenuation>
            <range>4</range>
            <linear>1</linear>
            <constant>0.8</constant>
            <quadratic>0</quadratic>
        </attenuation>
        <cast_shadows>false</cast_shadows>
    </light>


    <model name="light_sensor">

        <static>true</static>
        <link name="sensor_link">
            <visual name="visual_object">                   
                <geometry>
                    <cylinder>
                        <radius>.1</radius>
                        <length>0.08</length>
                    </cylinder>
                    </geometry>
                    <material>
                        <diffuse>1 0 0 1</diffuse>
                    </material>
            </visual>

        </link>

        <!--FIXME no absoulte path-->
        <plugin
            filename="/home/paolo/light_sensor_plugin/install/lib/libLightSensor.so"
            name="custom_light_sensor::LightSensor">
            <update_rate>1</update_rate>
        </plugin>

    </model>


</world>

`

$\endgroup$

0

Your Answer

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