Add entities programatically into a prototype

Requests regarding how to set up experiments in ARGoS.
Elendurwen
Posts: 41
Joined: Sat Aug 24, 2013 5:08 pm
Contact:

Add entities programatically into a prototype

Postby Elendurwen » Tue May 22, 2018 2:57 pm

Hi,

I am trying to attach LED entities to a prototype entity. The prototype entity is specified in the .argos file as a box and a loop function should get all prototype entities, and attach LEDs to them so that when a prototype moves, the LED moves with it. The code I currently have a) doesn't attach the LED to the prototype properly - when the prototype moves, the LED doesn't and b) crashes when you close the ARGoS window with segmentation fault (although the simulation runs normally).

I would like to know how to properly attach the LED and what to do in the Destroy function (perhaps) in order to prevent the crash. The code is:

Code: Select all

void MainLoopFunctions::Reset() { int i,w; //-- attach leds to distinguish between targets std::string entityId; w = 0; CLEDMedium& ledMedium(GetSimulator().GetMedium<CLEDMedium>("leds")); CSpace::TMapPerType& targets = GetSpace().GetEntitiesByType("prototype"); for (i=0; i<targets.size(); i++) { std::ostringstream oss; oss << "target" << i; CPrototypeEntity& prototypeEntity = *any_cast<CPrototypeEntity*>(targets[oss.str()]); entityId = "light" + std::to_string(i) + "-" + std::to_string(w); CLightEntity* light = new CLightEntity(entityId, CVector3(-0.25,0.1,0.1), CColor::RED, 3); light->SetMedium(ledMedium); GetSpace().AddEntity(*light); ledMedium.AddEntity(*light); prototypeEntity.AddComponent(*light); // IS THIS WRONG? The LED doesn't move with the box. Also, when this is commented out, the crash at close doesn't occur anymore. w++; } } void MainLoopFunctions::Destroy() { for (int i=0; i<lights.size(); i++) { lights[i]->GetParent().RemoveComponent(lights[i]->GetId()); delete lights[i]; } }
As you can see, the LEDs are stored in a vector of LED pointers (is this the right thing to do?) The problem I think is the line prototypeEntity.AddComponent(*light);

Thanks!

allsey87
Posts: 6
Joined: Tue May 22, 2018 3:30 pm

Re: Add entities programatically into a prototype

Postby allsey87 » Tue May 22, 2018 3:59 pm

There is a couple of things wrong here. Firstly adding entities programmatically to a prototype entity is not directly supported. The prototype entity is designed to be initialized by XML. That been said, as a work around you can create the TConfigurationNode etc programmatically and pass it to CPrototypeEntity::Init.

The reason why the LED/Light doesn't move with the box is most likely due to issue #73 on Github.

Finally, CLEDEntity != CLightEntity, they are different! The prototype entity only supports LEDs since lights are supposed to be standalone entities and not meant to be attached to robots.
I work with ARGoS a lot.

Elendurwen
Posts: 41
Joined: Sat Aug 24, 2013 5:08 pm
Contact:

Re: Add entities programatically into a prototype

Postby Elendurwen » Tue May 22, 2018 4:04 pm

Yes, that is right, I am trying to add a CLight entity (the led entities on a prototype do not seem to be readable by footbot's blobl detection camera).

I do not necessarily need to use prototypes. So I guess my question then is, how do you attach CLights to any object (say a simple box) properly?

allsey87
Posts: 6
Joined: Tue May 22, 2018 3:30 pm

Re: Add entities programatically into a prototype

Postby allsey87 » Tue May 22, 2018 4:17 pm

For attaching LEDs to boxes etc, the most common way is to use the XML. For the prototype, try to look at the examples in src/testing/examples/prototype_radio_test.argos

CLEDEntity should be detectable using the footbot's blob camera, CDirectionalLEDEntity is not. You may also want to look at src/testing/examples/footbot_camera_prototype_example.argos for inspiration.
I work with ARGoS a lot.

Elendurwen
Posts: 41
Joined: Sat Aug 24, 2013 5:08 pm
Contact:

Re: Add entities programatically into a prototype

Postby Elendurwen » Wed May 23, 2018 8:17 am

Hi,

the reason I need to attach CLights programatically is that in my experiment, there is simply too many different objects with different lights. Is there no way to do this in ARGoS?

Can CLEDEntity be attached to a prototype programatically?

Elendurwen
Posts: 41
Joined: Sat Aug 24, 2013 5:08 pm
Contact:

Re: Add entities programatically into a prototype

Postby Elendurwen » Fri May 25, 2018 11:21 am

After playing with this for a while, I found that you can add LEDs programatically to a prototype via

Code: Select all

prototypeEntity.GetLEDEquippedEntity().AddLED(CVector3(-0.1,-0.5,0), prototypeEntity.GetEmbodiedEntity().GetAnchor("base"), CColor::RED);
However, LEDs added programatically are NOT picked up by the footbot's blob detector. LEDs defined in the XML are.

pincy
Site Admin
Posts: 632
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

Re: Add entities programatically into a prototype

Postby pincy » Fri May 25, 2018 3:00 pm

It's because you need to add them to the led medium. The camera asks the led medium for leds around, if the medium does not know about them, then they won't be seen.

I think that the prototype entity should have a way to add entities from C++. It's managed by Michael - maybe he can find a solution.
I made ARGoS.


Return to “How to... ?”