Ignition Gazebo

API Reference

7.0.0~pre1
Light config

This tutorial gives an introduction to Ignition Gazebo's service /world/<world name>/light_config. This service will allow to modify lights in the scene.

Modifying lights

To modify lights inside the scene we need to use the service /world/<world name>/light_config and fill the message ignition::msgs::Light. In particular this example modifies the point light that we introduced with the function createLight().

ignition::msgs::EntityFactory entityFactoryRequest;
entityFactoryRequest.mutable_light()->set_name("point");
entityFactoryRequest.mutable_light()->set_range(4);
entityFactoryRequest.mutable_light()->set_attenuation_linear(0.5);
entityFactoryRequest.mutable_light()->set_attenuation_constant(0.2);
entityFactoryRequest.mutable_light()->set_attenuation_quadratic(0.01);
entityFactoryRequest.mutable_light()->set_cast_shadows(false);
entityFactoryRequest.mutable_light()->mutable_direction(),
ignition::math::Vector3d(directionX, directionY, directionZ));
ignition::msgs::Set(entityFactoryRequest.mutable_light()->mutable_pose(),
ignition::math::Pose3d(0.0, 0, 3.0, 0.0, 0.0, 0.0));

NOTE:: You can check the entity creation tutorial to learn how to include models and lights in the scene.

As you can see in the snippet we modify the specular and diffuse colors of the light in the scene.

lightRequest.set_name("point");
lightRequest.set_range(4);
lightRequest.set_attenuation_linear(0.5);
lightRequest.set_attenuation_constant(0.2);
lightRequest.set_attenuation_quadratic(0.01);
lightRequest.set_cast_shadows(false);
lightRequest.set_type(ignition::msgs::Light::POINT);
// direction field only affects spot / directional lights
ignition::msgs::Set(lightRequest.mutable_direction(),
ignition::math::Vector3d(directionX, directionY, directionZ));
ignition::msgs::Set(lightRequest.mutable_pose(),
ignition::math::Pose3d(0.0, -1.5, 3.0, 0.0, 0.0, 0.0));
ignition::msgs::Set(lightRequest.mutable_diffuse(),
ignition::math::Color(r, g, b, 1));
ignition::msgs::Set(lightRequest.mutable_specular(),
ignition::math::Color(r, g, b, 1));

In this case we are creating random numbers to fill the diffuse and specular.

while (m < epsilon)
{
r = distr(twister);
g = distr(twister);
b = distr(twister);
m = std::sqrt(r*r + b*b + g*g);
}
r /= m;
b /= m;
b /= m;

Run the example

To run this example you should cd into examples/standalone/light_control and build the code:

mkdir build
cd build
cmake ..
make

Then you should open two terminals and run:

  • Terminal one:
    ign gazebo -r -v 4 empty.sdf
  • Terminal two:
    ./light_control