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

Conversation

ahcorde
Copy link
Contributor

@ahcorde ahcorde commented Dec 10, 2020

I add a new service called /world/lights/config to be able to change the configuration of a light. This was added in the UserCommand system plugin.

As you can see in the gif the configuration can be changed in the Component Inspector.

lights

Signed-off-by: ahcorde [email protected]

@ahcorde ahcorde added the enhancement New feature or request label Dec 10, 2020
@ahcorde ahcorde requested review from iche033 and chapulina December 10, 2020 23:03
@ahcorde ahcorde self-assigned this Dec 10, 2020
@github-actions github-actions bot added the 🔮 dome Ignition Dome label Dec 10, 2020
Signed-off-by: ahcorde <[email protected]>
@ahcorde ahcorde mentioned this pull request Dec 10, 2020
@chapulina chapulina added GUI Gazebo's graphical interface (not pure Ignition GUI) rendering Involves Ignition Rendering labels Dec 14, 2020
Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

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

Did a first pass 👍

Mind adding a test to test/integration/user_commands.cc?

src/gui/plugins/component_inspector/ComponentInspector.cc Outdated Show resolved Hide resolved
src/gui/plugins/component_inspector/ComponentInspector.hh Outdated Show resolved Hide resolved
src/gui/plugins/component_inspector/ComponentInspector.cc Outdated Show resolved Hide resolved
src/gui/plugins/component_inspector/Light.qml Outdated Show resolved Hide resolved
src/rendering/RenderUtil.cc Outdated Show resolved Hide resolved
src/systems/user_commands/UserCommands.cc Show resolved Hide resolved
src/systems/user_commands/UserCommands.cc Outdated Show resolved Hide resolved
src/systems/user_commands/UserCommands.cc Outdated Show resolved Hide resolved
Signed-off-by: ahcorde <[email protected]>
@ahcorde ahcorde requested a review from chapulina December 15, 2020 16:42
src/gui/plugins/plotting/Plotting.hh Outdated Show resolved Hide resolved
src/gui/plugins/plotting/Plotting.hh Outdated Show resolved Hide resolved
}

this->iface->ecm->SetChanged(entity,
components::Pose::typeId, ComponentState::OneTimeChange);
Copy link
Contributor

Choose a reason for hiding this comment

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

what is there is no new pose? i.e. lightMsg->has_pose() is false. Should we still call SetChanged on components::Pose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This call is able to change the light properties and the pose

const components::Pose *_pose)->bool
{
this->entityPoses[_entity] = _pose->Data();
this->entityLights[_entity] = _light->Data();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking of making this more efficient. Currently we are populating entityLights for all lights in the scene and going through the update process every iteration. Even though we check to see if any light properties have changed, there is still a bit of computation overhead every iteration. In an upcoming environment we are creating, we plan to put in a few hundred lights so this may add up.

How about we handle light requests similar to pose commands by adding a new components::LightCmd? When the light service request is received, we create a LightCmd component and attach it to the light entity in UserCommands, e.g. see WorldPoseCmd creation here. In RenderUtil, we will instead be looping through entities with components::LightCmd:

_ecm.Each<components::LightCmd>(
      [&](const Entity &_entity,
        const components::LightCmd *_light) -> bool
   this->entityLights[_entity] = _light->Data();
   ...

We then remove the components::LightCmd from the entity afterwards to indicate that we've processed the cmd, e.g. see removing WorldPoseCmd here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iche033 I added most of your feedback, but I'm not sure where I should remove the LightCmd. The worldPoseCmd is remove in Physics, but where is the right place to remove these cmds? renderutils.cc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iche033 I removed the LightCmd, I had to convert the const-EntityComponentManager vriable in to a non-const EntityComponentManager variable to be able to remove the LightCmd. is this correct ?

https://github.com/ignitionrobotics/ign-gazebo/blob/19b3c9f06d5c097dc923324501a2a05bb889a2dd/src/rendering/RenderUtil.cc#L1162-L1169

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm I see. UpdateFromECM is called in the PostUpdate function in the sensors system on the server side in the sensors system, which gets a const ref EntityComponentManager. The physics system is able to remove the component as it's done in Update function which has a mutable reference to ECM. We may have to create a new UpdateECM function in RenderUtil and call it from a new Update function (which also needs to be added) in sensors system.

On the gui side, the UpdateFromECM is called in a function that has a mutable reference to ECM. So we should be able to just do UpdateECM() and followed by UpdateFromECM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
@ahcorde
Copy link
Contributor Author

ahcorde commented Feb 5, 2021

@chapulina can you try this patch ?

--- a/src/EntityComponentManager.cc
+++ b/src/EntityComponentManager.cc
@@ -809,6 +809,9 @@ void EntityComponentManagerPrivate::SetRemovedComponentsMsgs(Entity &_entity,
   // Find the entity in the message
   auto entIter = _msg.mutable_entities()->find(_entity);
 
+  if (entIter == _msg.mutable_entities()->end())
+    return;
+
   auto it = this->removedComponents.find(_entity);
   for (uint64_t i = 0; i < nEntityKeys; ++i)
   {

Signed-off-by: ahcorde <[email protected]>
@ahcorde
Copy link
Contributor Author

ahcorde commented Feb 5, 2021

I added the patch in the last commit with another segfault

@ahcorde ahcorde requested a review from chapulina February 8, 2021 08:48
@iche033
Copy link
Contributor

iche033 commented Feb 8, 2021

I ran into this crash in #614 as well. There is a fix in #495. We should try to get that merged.

@adlarkin adlarkin mentioned this pull request Feb 9, 2021
@ahcorde
Copy link
Contributor Author

ahcorde commented Feb 12, 2021

friendly ping @iche033 and @chapulina

Copy link
Contributor

@chapulina chapulina left a comment

Choose a reason for hiding this comment

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

Thanks for iterating! I can't reproduce the weird behaviour and crash anymore. Feel free to merge once the last final details have been addressed. Be sure to also sign all commits for DCO.

Thanks! 💡

tutorials/light_config.md Outdated Show resolved Hide resolved
src/rendering/RenderUtil.cc Show resolved Hide resolved
src/systems/sensors/Sensors.hh Outdated Show resolved Hide resolved
Signed-off-by: ahcorde <[email protected]>
@ahcorde ahcorde force-pushed the ahcorde/feature/lights branch from 6a372e2 to a3f74a5 Compare February 17, 2021 07:07
* Added light tutorial and example

Signed-off-by: ahcorde <[email protected]>

* Added some feedback

Signed-off-by: ahcorde <[email protected]>

* Split tutorial in two

Signed-off-by: ahcorde <[email protected]>

* remove ids from tutorial

Signed-off-by: ahcorde <[email protected]>

* Added feedback

Signed-off-by: ahcorde <[email protected]>

* update tutorial

Signed-off-by: ahcorde <[email protected]>

Co-authored-by: Louise Poubel <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔮 dome Ignition Dome enhancement New feature or request GUI Gazebo's graphical interface (not pure Ignition GUI) rendering Involves Ignition Rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants