Page 1 of 4

Create multiple boxes with LED on top

Posted: Sun May 13, 2018 12:00 pm
by mbt925
I want to create multiple boxes at random locations each of which has a LED on top. The boxes are foods and will be removed later from the simulation.
Please provide some samples to do it via loop functions.
Thanks in advance.

Re: Create multiple boxes with LED on top

Posted: Sun May 20, 2018 6:49 am
by mbt925
Is something wrong with my question? :cry:
At least, redirect me to some tutorial or documentation.

Re: Create multiple boxes with LED on top

Posted: Sun May 20, 2018 2:25 pm
by pincy
Nothing is wrong with your question - I just had no time to make a complete example for you because I'm working on a paper. I can give this at the moment.

You can do it in the XML:

Code: Select all

<!-- Check argos3 -q box --> <distribute> <position method="uniform" min="-2,-2,0" max="2,2,0" /> <orientation method="uniform" min="0,0,0" max="360,0,0" /> <entity quantity="5" max_trials="100"> <box id="b" size="0.5,0.5,0.5" movable="true"> <leds medium="id_of_led_medium"> <led offset="0,0,1.0" anchor="origin" color="red" /> </leds> </box> </entity> </distribute>
To create a box with an LED on top, you can do this instead:

Code: Select all

CMyLoopFunctions::Init(...) { // Get a reference to the LED medium // // The passed id "leds" corresponds to the id of the led_medium in // the XML file // // see https://github.com/ilpincy/argos3/blob/master/src/core/simulator/simulator.h // see https://github.com/ilpincy/argos3/blob/master/src/plugins/simulator/media/led_medium.h CLEDMedium& cLEDMedium = GetSimulator().GetMedium("leds"); // Add a new box with an LED on top // see https://github.com/ilpincy/argos3/blob/master/src/plugins/simulator/entities/box_entity.h CBoxEntity* pcBox = new CBoxEntity("box1", // id CVector3(1.0, 2.0, 0.0), // position CQuaternion(), // orientation true, // movable or not? CVector3(0.5, 0.5, 0.5), // size 1.0); // mass in kg // Add LED on top of the box pcBox->AddLED(CVector3(0.0, 0.0, 1.0), // offset CColor::RED); // color // Enable LED management for the box pcBox->EnableLEDs(cLEDMedium); // Add the box to the simulation AddEntity(*pcBox); }
The same would be for a cylinder.

(if the code formatting looks wrong, press Shift in your keyboard and the reload button of your browser - I had to make a fix to the CSS of the forum to display code correctly)

EDIT: This is the correct code. The discussion that follows is based on a bug in the original code I posted. The rest of the discussion won't refer to this code and can be ignored.

Re: Create multiple boxes with LED on top

Posted: Mon May 21, 2018 11:02 am
by mbt925
Thank you very much for spending time on this question.

I am getting the following error when using:

Code: Select all

CLEDMedium& cLEDMedium = GetSimulator().GetMedium("leds");
error: no matching function for call to ‘argos::CSimulator::GetMedium(const char [5])’
CLEDMedium& cLEDMedium = GetSimulator().GetMedium("leds");

Re: Create multiple boxes with LED on top

Posted: Mon May 21, 2018 11:03 am
by mbt925
How can I get the position of a box?

Re: Create multiple boxes with LED on top

Posted: Mon May 21, 2018 8:13 pm
by pincy

Code: Select all

CBoxEntity& cBox = ... cBox.GetEmbodiedEntity().GetOriginAnchor()

Re: Create multiple boxes with LED on top

Posted: Tue May 22, 2018 6:18 am
by mbt925
Thank you very much for spending time on this question.

I am getting the following error when using:

Code: Select all

CLEDMedium& cLEDMedium = GetSimulator().GetMedium("leds");
error: no matching function for call to ‘argos::CSimulator::GetMedium(const char [5])’
CLEDMedium& cLEDMedium = GetSimulator().GetMedium("leds");
I am using ARGoS v3.0.0-beta47.

Re: Create multiple boxes with LED on top

Posted: Tue May 22, 2018 12:48 pm
by pincy
Try

Code: Select all

CLEDMedium& cLEDMedium = GetSimulator().GetMedium<CLEDMedium>("leds");
It would be helpful if you posted your code and the full error you get.

Also, I suggest you to familiarize with the ARGoS API rather than proceeding by individual examples.

Re: Create multiple boxes with LED on top

Posted: Thu May 24, 2018 12:38 pm
by mbt925
I appreciate your patience and time to thoroughly answering all of my questions. I uploaded the full project here: https://ufile.io/tq3vn.

I am learning ARGoS APIs using the example-based method. It's one of the well-known learning methods :) .

Re: Create multiple boxes with LED on top

Posted: Thu May 24, 2018 1:05 pm
by pincy
What should I do with the sources?