Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Light Usercommand and include Light parameters in the componentInspector #482

Merged
merged 67 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
d4fc697
Add Light Usercommand and include Light parameters in the componentIn…
ahcorde Dec 10, 2020
2b81da5
make linters happy
ahcorde Dec 10, 2020
8adc695
Included spot and directional features
ahcorde Dec 14, 2020
deea452
Fix compile warning
ahcorde Dec 14, 2020
ef53a13
make linters happy
ahcorde Dec 14, 2020
c11d628
Added feedback
ahcorde Dec 15, 2020
6609c26
make linters happy
ahcorde Dec 15, 2020
f8519ae
Added light user commands tests
ahcorde Dec 15, 2020
248af9e
make linters happy
ahcorde Dec 15, 2020
3e79da9
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Dec 15, 2020
9823e74
Allow to plot Light values with the plotting plugin
ahcorde Dec 16, 2020
45d6faf
Merge branch 'ahcorde/feature/lights' of https://github.com/ignitionr…
ahcorde Dec 16, 2020
89f2791
Fixed plotting plugin
ahcorde Dec 16, 2020
7d80435
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Dec 16, 2020
55e20e6
Added feedback
ahcorde Dec 16, 2020
19b3c9f
Removed LightCmd
ahcorde Dec 17, 2020
eb00612
make linters happy
ahcorde Dec 17, 2020
8877542
make linters happy
ahcorde Dec 17, 2020
0e660f9
Added UpdateECM method
ahcorde Dec 18, 2020
9ff266b
Fixed year in the License
ahcorde Dec 21, 2020
eb1d450
Fix lights inside link
ahcorde Dec 21, 2020
dc97cf2
Removed compiler warning
ahcorde Dec 21, 2020
5595db1
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Dec 21, 2020
d175a11
make linters happy
ahcorde Dec 21, 2020
eec5a1e
Merge branch 'ahcorde/feature/lights' of https://github.com/ignitionr…
ahcorde Dec 21, 2020
2d8b9d5
simplifying the search for lights attached to links
ahcorde Dec 22, 2020
135c827
used convert method
ahcorde Dec 23, 2020
fd4edbc
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
chapulina Dec 23, 2020
254a197
added some feedback
ahcorde Dec 24, 2020
d7709b4
Merge branch 'ahcorde/feature/lights' of https://github.com/ignitionr…
ahcorde Dec 28, 2020
d414397
Improved GUI
ahcorde Dec 28, 2020
cadc2ba
Fixed tests
ahcorde Dec 28, 2020
89b603a
make linters happy
ahcorde Dec 28, 2020
57e7ca3
Changed LightCmd to use msgs::Light
ahcorde Dec 30, 2020
8220d40
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Jan 6, 2021
e68d524
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
chapulina Jan 8, 2021
ab1f9b3
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
chapulina Jan 8, 2021
1b0b091
Removed LightCmd from Plotting class
ahcorde Jan 12, 2021
0c78305
Fixed GUI when a color is picked through the color palette
ahcorde Jan 12, 2021
7e849ef
Merge branch 'ahcorde/feature/lights' of https://github.com/ignitionr…
ahcorde Jan 12, 2021
c49e071
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Jan 12, 2021
69d9d66
Removed LightCmd form component inspector
ahcorde Jan 12, 2021
690b43c
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Jan 13, 2021
642c12c
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Jan 14, 2021
2fa8b6f
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Jan 26, 2021
e316926
Added feedback
ahcorde Jan 26, 2021
d6f0c5f
Added feedback
ahcorde Jan 26, 2021
7a6e162
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
chapulina Jan 29, 2021
7b6d922
Added feedback
ahcorde Feb 1, 2021
5bafe43
Merge branch 'ahcorde/feature/lights' of https://github.com/ignitionr…
ahcorde Feb 1, 2021
5eb2bb1
improved variable name
ahcorde Feb 1, 2021
53f045b
Added light tutorial and example (#515)
ahcorde Feb 2, 2021
4b77b66
Merge remote-tracking branch 'origin/ign-gazebo4' into ahcorde/featur…
ahcorde Feb 3, 2021
a9e2e59
Restored some files
ahcorde Feb 3, 2021
291b1d5
Fixed tests
ahcorde Feb 3, 2021
4b322b8
Fixed tests
ahcorde Feb 4, 2021
40320e7
Added feedback
ahcorde Feb 5, 2021
79779e6
Fix seg faults
ahcorde Feb 5, 2021
10a63ff
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Feb 5, 2021
f0c104a
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Feb 9, 2021
35c376a
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Feb 11, 2021
0a22adc
Fixed merge
ahcorde Feb 11, 2021
88c736b
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Feb 12, 2021
50d10e2
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
ahcorde Feb 16, 2021
9004fc5
Merge branch 'ign-gazebo4' into ahcorde/feature/lights
chapulina Feb 16, 2021
b993f9d
Added feedback
ahcorde Feb 17, 2021
71623c3
Added light tutorial and example (#515)
ahcorde Feb 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/standalone/light_control/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR)

find_package(ignition-transport9 QUIET REQUIRED OPTIONAL_COMPONENTS log)
set(IGN_TRANSPORT_VER ${ignition-transport9_VERSION_MAJOR})

find_package(ignition-gazebo4 REQUIRED)
set(IGN_GAZEBO_VER ${ignition-gazebo4_VERSION_MAJOR})

add_executable(light_control light_control.cc)
target_link_libraries(light_control
ignition-transport${IGN_TRANSPORT_VER}::core
ignition-gazebo${IGN_GAZEBO_VER}::ignition-gazebo${IGN_GAZEBO_VER})
179 changes: 179 additions & 0 deletions examples/standalone/light_control/light_control.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/*
* Copyright (C) 2020 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <chrono>
#include <iostream>

#include <ignition/gazebo/components/Light.hh>
#include <ignition/gazebo/components/LightCmd.hh>
#include <ignition/msgs.hh>
#include <ignition/transport.hh>

using namespace std::chrono_literals;

// Create a transport node.
ignition::transport::Node node;

bool result;
// timeout used for services
constexpr unsigned int timeout = 5000;

std::mt19937 twister(std::time(0));
std::uniform_real_distribution<double> distr(0, 1000);
constexpr double epsilon = 0.1;

float directionX = 0.5;
float directionY = 0.2;
float directionZ = -0.9;

void createLight()
{
ignition::msgs::Boolean rep;
//! [create light]
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()->set_type(ignition::msgs::Light::POINT);
ignition::msgs::Set(
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));
//! [create light]

bool executedEntityFactory = node.Request("/world/empty/create",
entityFactoryRequest, timeout, rep, result);
if (executedEntityFactory)
{
if (result)
std::cout << "Light was created : [" << rep.data() << "]" << std::endl;
else
{
std::cout << "Service call failed" << std::endl;
return;
}
}
else
std::cerr << "Service call timed out" << std::endl;
}

void createSphere()
{
auto modelStr = R"(
<?xml version="1.0" ?>
<sdf version='1.7'>
<model name='sphere'>
<link name='link'>
<pose>0 0 0.5 0 0 0</pose>
<visual name='visual'>
<geometry><sphere><radius>1</radius></sphere></geometry>
</visual>
<collision name='collision'>
<geometry><sphere><radius>1</radius></sphere></geometry>
</collision>
</link>
</model>
</sdf>)";

ignition::msgs::EntityFactory req;
ignition::msgs::Boolean res;
req.set_sdf(modelStr);

bool executed = node.Request("/world/empty/create",
req, timeout, res, result);
if (executed)
{
if (result)
std::cout << "Sphere was created : [" << res.data() << "]" << std::endl;
else
{
std::cout << "Service call failed" << std::endl;
return;
}
}
else
std::cerr << "Service call timed out" << std::endl;
}

//////////////////////////////////////////////////
int main(int argc, char **argv)
{
ignition::msgs::Boolean rep;
ignition::msgs::Light lightRequest;
auto lightConfigService = "/world/empty/light_config";

createSphere();
createLight();

while (1)
{
float r, g, b;
double m = 0;
//! [random numbers]
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;
//! [random numbers]

//! [modify light]
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));
//! [modify light]
bool executed = node.Request(lightConfigService, lightRequest, timeout,
rep, result);
std::cout << "Service called: [" << r << ", " << g << ", " << b << "]"
<< std::endl;

if (executed)
{
if (result)
std::cout << "Response: [" << rep.data() << "]" << std::endl;
else
std::cout << "Service call failed" << std::endl;
}
else
std::cerr << "Service call timed out" << std::endl;

std::this_thread::sleep_for(1s);
}
}
48 changes: 48 additions & 0 deletions include/ignition/gazebo/components/LightCmd.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2020 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef IGNITION_GAZEBO_COMPONENTS_LIGHTCMD_HH_
#define IGNITION_GAZEBO_COMPONENTS_LIGHTCMD_HH_

#include <sdf/Light.hh>

#include <ignition/gazebo/config.hh>
#include <ignition/gazebo/Export.hh>
#include <ignition/gazebo/components/Factory.hh>
#include <ignition/gazebo/components/Component.hh>
#include <ignition/gazebo/components/Serialization.hh>

#include <ignition/msgs/light.pb.h>

namespace ignition
{
namespace gazebo
{
// Inline bracket to help doxygen filtering.
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
namespace components
{
/// \brief A component type that contains commanded light of an
/// entity in the world frame represented by msgs::Light.
using LightCmd = Component<ignition::msgs::Light,
class LightCmdTag, serializers::MsgSerializer>;
IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.LightCmd",
LightCmd)
}
}
}
}
#endif
Loading