Create multiple boxes with LED on top

Requests regarding how to set up experiments in ARGoS.
mbt925
Posts: 36
Joined: Mon Aug 07, 2017 12:21 pm

Create multiple boxes with LED on top

Postby mbt925 » Sun May 13, 2018 12:00 pm

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.

mbt925
Posts: 36
Joined: Mon Aug 07, 2017 12:21 pm

Re: Create multiple boxes with LED on top

Postby mbt925 » Sun May 20, 2018 6:49 am

Is something wrong with my question? :cry:
At least, redirect me to some tutorial or documentation.
Last edited by mbt925 on Mon May 21, 2018 8:49 am, edited 1 time in total.

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

Re: Create multiple boxes with LED on top

Postby pincy » Sun May 20, 2018 2:25 pm

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.
I made ARGoS.

mbt925
Posts: 36
Joined: Mon Aug 07, 2017 12:21 pm

Re: Create multiple boxes with LED on top

Postby mbt925 » Mon May 21, 2018 11:02 am

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");

mbt925
Posts: 36
Joined: Mon Aug 07, 2017 12:21 pm

Re: Create multiple boxes with LED on top

Postby mbt925 » Mon May 21, 2018 11:03 am

How can I get the position of a box?

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

Re: Create multiple boxes with LED on top

Postby pincy » Mon May 21, 2018 8:13 pm

Code: Select all

CBoxEntity& cBox = ... cBox.GetEmbodiedEntity().GetOriginAnchor()
I made ARGoS.

mbt925
Posts: 36
Joined: Mon Aug 07, 2017 12:21 pm

Re: Create multiple boxes with LED on top

Postby mbt925 » Tue May 22, 2018 6:18 am

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.

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

Re: Create multiple boxes with LED on top

Postby pincy » Tue May 22, 2018 12:48 pm

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.
I made ARGoS.

mbt925
Posts: 36
Joined: Mon Aug 07, 2017 12:21 pm

Re: Create multiple boxes with LED on top

Postby mbt925 » Thu May 24, 2018 12:38 pm

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 :) .

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

Re: Create multiple boxes with LED on top

Postby pincy » Thu May 24, 2018 1:05 pm

What should I do with the sources?
I made ARGoS.


Return to “How to... ?”



cron