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 28 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
8 changes: 8 additions & 0 deletions include/ignition/gazebo/Model.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <ignition/gazebo/Export.hh>
#include <ignition/gazebo/Types.hh>

#include <sdf/Light.hh>
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

namespace ignition
{
namespace gazebo
Expand Down Expand Up @@ -169,6 +171,12 @@ namespace ignition
public: void SetWorldPoseCmd(EntityComponentManager &_ecm,
const math::Pose3d &_pose);

/// \brief Set a command to change the light.
/// \param[in] _ecm Entity-component manager.
/// \param[in] _light New model light.
public: void SetLightCmd(EntityComponentManager &_ecm,
const sdf::Light &_light);
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

/// \brief Pointer to private data.
private: std::unique_ptr<ModelPrivate> dataPtr;
};
Expand Down
53 changes: 53 additions & 0 deletions include/ignition/gazebo/components/LightCmd.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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>

namespace ignition
{
namespace gazebo
{
// Inline bracket to help doxygen filtering.
inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
namespace serializers
{
using LightCmdSerializer =
serializers::ComponentToMsgSerializer<sdf::Light, msgs::Light>;
}

namespace components
{
/// \brief A component type that contains commanded light of an
/// entity in the world frame represented by sdf::Light.
using LightCmd =
Component<sdf::Light, class LightCmdTag, serializers::LightCmdSerializer>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend using msgs::Light as the data for this component. This may save some conversions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chapulina, I tried to be coherent with the other CMD commands.

  • AngularVelocityCmd -> math::Vector3d
  • JointForceCmd -> std::vector
  • JointVelocityCmd -> std::vector
  • LinearVelocityCmd -> math::Vector3D
  • PoseCmd -> math::Pose3d

none of them are using the message type

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commands aren't using SDF types either 😉 We have a couple of components using messages to hold their data, but it's true that there are more using SDF. I think this is mainly historical though, we started thinking we'd use SDF more widely, but I think that's becoming less true. See #494 for more context.

The reason I suggested a message is that it matches better what the components do. They hold data and are serialized. Right now, using SDF, you're still relying on a message for serialization. If you just used the message directly in the type, then you save the SDF <-> msgs conversion by using a MsgSerializer directly.

IGN_GAZEBO_REGISTER_COMPONENT("ign_gazebo_components.LightCmd",
LightCmd)
}
}
}
}
#endif
4 changes: 4 additions & 0 deletions include/ignition/gazebo/rendering/RenderUtil.hh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
/// \return Pointer to the scene
public: rendering::ScenePtr Scene() const;

/// \brief Helper Update function for updating the scene
public: void UpdateECM(const UpdateInfo &_info,
EntityComponentManager &_ecm);

/// \brief Helper PostUpdate function for updating the scene
public: void UpdateFromECM(const UpdateInfo &_info,
const EntityComponentManager &_ecm);
Expand Down
19 changes: 19 additions & 0 deletions src/Model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "ignition/gazebo/components/Joint.hh"
#include "ignition/gazebo/components/LightCmd.hh"
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
#include "ignition/gazebo/components/Link.hh"
#include "ignition/gazebo/components/Model.hh"
#include "ignition/gazebo/components/Name.hh"
Expand Down Expand Up @@ -193,3 +194,21 @@ void Model::SetWorldPoseCmd(EntityComponentManager &_ecm,
}
}

//////////////////////////////////////////////////
void Model::SetLightCmd(EntityComponentManager &_ecm,
const sdf::Light &_light)
{
auto lightCmdComp = _ecm.Component<components::LightCmd>(
this->dataPtr->id);
if (!lightCmdComp)
{
_ecm.CreateComponent(this->dataPtr->id, components::LightCmd(_light));
}
else
{
lightCmdComp->SetData(_light,
[](const sdf::Light &, const sdf::Light &){return false;});
_ecm.SetChanged(this->dataPtr->id,
components::LightCmd::typeId, ComponentState::OneTimeChange);
}
}
121 changes: 115 additions & 6 deletions src/gui/plugins/component_inspector/ComponentInspector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "ignition/gazebo/components/Joint.hh"
#include "ignition/gazebo/components/Level.hh"
#include "ignition/gazebo/components/Light.hh"
#include "ignition/gazebo/components/LightCmd.hh"
#include "ignition/gazebo/components/LinearAcceleration.hh"
#include "ignition/gazebo/components/LinearVelocity.hh"
#include "ignition/gazebo/components/LinearVelocitySeed.hh"
Expand Down Expand Up @@ -76,6 +77,9 @@ namespace ignition::gazebo
/// \brief Name of the world
public: std::string worldName;

/// \brief Entity name
public: std::string entityName;

/// \brief Entity type, such as 'world' or 'model'.
public: QString type;

Expand Down Expand Up @@ -112,6 +116,50 @@ void ignition::gazebo::setData(QStandardItem *_item, const math::Pose3d &_data)
}), ComponentsModel::RoleNames().key("data"));
}

//////////////////////////////////////////////////
template<>
void ignition::gazebo::setData(QStandardItem *_item, const sdf::Light &_data)
{
int lightType = -1;
if (_data.Type() == sdf::LightType::POINT)
{
lightType = 0;
}
else if (_data.Type() == sdf::LightType::SPOT)
{
lightType = 1;
}
else if (_data.Type() == sdf::LightType::DIRECTIONAL)
{
lightType = 2;
}
ahcorde marked this conversation as resolved.
Show resolved Hide resolved

_item->setData(QString("Light"),
ComponentsModel::RoleNames().key("dataType"));
_item->setData(QList({
QVariant(_data.Specular().R()),
QVariant(_data.Specular().G()),
QVariant(_data.Specular().B()),
QVariant(_data.Specular().A()),
QVariant(_data.Diffuse().R()),
QVariant(_data.Diffuse().G()),
QVariant(_data.Diffuse().B()),
QVariant(_data.Diffuse().A()),
QVariant(_data.AttenuationRange()),
QVariant(_data.LinearAttenuationFactor()),
QVariant(_data.ConstantAttenuationFactor()),
QVariant(_data.QuadraticAttenuationFactor()),
QVariant(_data.CastShadows()),
QVariant(_data.Direction().X()),
QVariant(_data.Direction().Y()),
QVariant(_data.Direction().Z()),
QVariant(_data.SpotInnerAngle().Radian()),
QVariant(_data.SpotOuterAngle().Radian()),
QVariant(_data.SpotFalloff()),
QVariant(lightType)
}), ComponentsModel::RoleNames().key("data"));
}

//////////////////////////////////////////////////
template<>
void ignition::gazebo::setData(QStandardItem *_item,
Expand Down Expand Up @@ -370,12 +418,6 @@ void ComponentInspector::Update(const UpdateInfo &,
continue;
}

if (typeId == components::Light::typeId)
{
this->SetType("light");
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

if (typeId == components::Actor::typeId)
{
this->SetType("actor");
Expand Down Expand Up @@ -499,6 +541,7 @@ void ComponentInspector::Update(const UpdateInfo &,

if (this->dataPtr->entity == this->dataPtr->worldEntity)
this->dataPtr->worldName = comp->Data();
this->dataPtr->entityName = comp->Data();
}
else if (typeId == components::ParentEntity::typeId)
{
Expand All @@ -521,6 +564,19 @@ void ComponentInspector::Update(const UpdateInfo &,
if (comp)
setData(item, comp->Data());
}
else if (typeId == components::Light::typeId)
{
this->SetType("light");
auto comp = _ecm.Component<components::Light>(this->dataPtr->entity);
if (comp)
setData(item, comp->Data());
}
else if (typeId == components::LightCmd::typeId)
{
auto comp = _ecm.Component<components::LightCmd>(this->dataPtr->entity);
if (comp)
setData(item, comp->Data());
}
else if (typeId == components::Pose::typeId)
{
auto comp = _ecm.Component<components::Pose>(this->dataPtr->entity);
Expand Down Expand Up @@ -728,6 +784,59 @@ void ComponentInspector::OnPose(double _x, double _y, double _z, double _roll,
this->dataPtr->node.Request(poseCmdService, req, cb);
}

/////////////////////////////////////////////////
void ComponentInspector::OnLight(
double _rSpecular, double _gSpecular, double _bSpecular, double _aSpecular,
double _rDiffuse, double _gDiffuse, double _bDiffuse, double _aDiffuse,
double _attRange, double _attLinear, double _attConstant,
double _attQuadratic, bool _castShadows, double _directionX,
double _directionY, double _directionZ, double _innerAngle,
double _outerAngle, double _falloff, int _type)
{
std::function<void(const ignition::msgs::Boolean &, const bool)> cb =
[](const ignition::msgs::Boolean &/*_rep*/, const bool _result)
{
if (!_result)
ignerr << "Error setting light configuration" << std::endl;
};

ignition::msgs::Light req;
req.set_name(this->dataPtr->entityName);
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
req.set_id(this->dataPtr->entity);
ignition::msgs::Set(req.mutable_diffuse(),
ignition::math::Color(_rDiffuse, _gDiffuse, _bDiffuse, _aDiffuse));
ignition::msgs::Set(req.mutable_specular(),
ignition::math::Color(_rSpecular, _gSpecular, _bSpecular, _aSpecular));
req.set_range(_attRange);
req.set_attenuation_linear(_attLinear);
req.set_attenuation_constant(_attConstant);
req.set_attenuation_quadratic(_attQuadratic);
req.set_cast_shadows(_castShadows);
if (_type == 0)
req.set_type(ignition::msgs::Light::POINT);
else if (_type == 1)
req.set_type(ignition::msgs::Light::SPOT);
else
req.set_type(ignition::msgs::Light::DIRECTIONAL);

if (_type == 1) // sdf::LightType::SPOT
{
req.set_spot_inner_angle(_innerAngle);
req.set_spot_outer_angle(_outerAngle);
req.set_spot_falloff(_falloff);
}

// if sdf::LightType::SPOT || sdf::LightType::DIRECTIONAL
if (_type == 1 || _type == 2) {
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
ignition::msgs::Set(req.mutable_direction(),
ignition::math::Vector3d(_directionX, _directionY, _directionZ));
}

auto lightConfigService = "/world/" + this->dataPtr->worldName +
"/light_config";
ahcorde marked this conversation as resolved.
Show resolved Hide resolved
this->dataPtr->node.Request(lightConfigService, req, cb);
}

/////////////////////////////////////////////////
bool ComponentInspector::NestedModel() const
{
Expand Down
38 changes: 38 additions & 0 deletions src/gui/plugins/component_inspector/ComponentInspector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <ignition/gazebo/gui/GuiSystem.hh>
#include <ignition/gazebo/Types.hh>

#include <sdf/Light.hh>

Q_DECLARE_METATYPE(ignition::gazebo::ComponentTypeId)

namespace ignition
Expand Down Expand Up @@ -69,6 +71,12 @@ namespace gazebo
template<>
void setData(QStandardItem *_item, const math::Pose3d &_data);

/// \brief Specialized to set light data.
/// \param[in] _item Item whose data will be set.
/// \param[in] _data Data to set.
template<>
void setData(QStandardItem *_item, const sdf::Light &_data);

/// \brief Specialized to set vector data.
/// \param[in] _item Item whose data will be set.
/// \param[in] _data Data to set.
Expand Down Expand Up @@ -207,6 +215,36 @@ namespace gazebo
public: Q_INVOKABLE void OnPose(double _x, double _y, double _z,
double _roll, double _pitch, double _yaw);

/// \brief Callback in Qt thread when specular changes.
/// \param[in] _rSpecular specular red
/// \param[in] _gSpecular specular green
/// \param[in] _bSpecular specular blue
/// \param[in] _aSpecular specular alpha
/// \param[in] _rDiffuse Diffuse red
/// \param[in] _gDiffuse Diffuse green
/// \param[in] _bDiffuse Diffuse blue
/// \param[in] _aDiffuse Diffuse alpha
/// \param[in] _attRange Range attenuation
/// \param[in] _attLinear Linear attenuation
/// \param[in] _attConstant Constant attenuation
/// \param[in] _attQuadratic Quadratic attenuation
/// \param[in] _castShadows Specify if this light should cast shadows
/// \param[in] _directionX X direction of the light
/// \param[in] _directionY Y direction of the light
/// \param[in] _directionZ Z direction of the light
/// \param[in] _innerAngle Inner angle of the spotlight
/// \param[in] _outerAngle Outer angle of the spotlight
/// \param[in] _falloff Falloff of the spotlight
/// \param[in] _type light type
public: Q_INVOKABLE void OnLight(
double _rSpecular, double _gSpecular, double _bSpecular,
double _aSpecular, double _rDiffuse, double _gDiffuse,
double _bDiffuse, double _aDiffuse, double _attRange,
double _attLinear, double _attConstant, double _attQuadratic,
bool _castShadows, double _directionX, double _directionY,
double _directionZ, double _innerAngle, double _outerAngle,
double _falloff, int _type);

/// \brief Get whether the entity is a nested model or not
/// \return True if the entity is a nested model, false otherwise
public: Q_INVOKABLE bool NestedModel() const;
Expand Down
15 changes: 15 additions & 0 deletions src/gui/plugins/component_inspector/ComponentInspector.qml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ Rectangle {
ComponentInspector.OnPose(_x, _y, _z, _roll, _pitch, _yaw)
}

/**
* Forward light changes to C++
*/
function onLight(_rSpecular, _gSpecular, _bSpecular, _aSpecular,
_rDiffuse, _gDiffuse, _bDiffuse, _aDiffuse,
_attRange, _attLinear, _attConstant, _attQuadratic,
_castShadows, _directionX, _directionY, _directionZ,
_innerAngle, _outerAngle, _falloff, _type) {
ComponentInspector.OnLight(_rSpecular, _gSpecular, _bSpecular, _aSpecular,
_rDiffuse, _gDiffuse, _bDiffuse, _aDiffuse,
_attRange, _attLinear, _attConstant, _attQuadratic,
_castShadows, _directionX, _directionY, _directionZ,
_innerAngle, _outerAngle, _falloff, _type)
}

Rectangle {
id: header
height: lockButton.height
Expand Down
1 change: 1 addition & 0 deletions src/gui/plugins/component_inspector/ComponentInspector.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<qresource prefix="ComponentInspector/">
<file>Boolean.qml</file>
<file>ComponentInspector.qml</file>
<file>Light.qml</file>
<file>NoData.qml</file>
<file>Pose3d.qml</file>
<file>String.qml</file>
Expand Down
Loading