Cast entity to EyeBot entity

Requests regarding how to set up experiments in ARGoS.
emerckx
Posts: 15
Joined: Tue Mar 29, 2016 1:37 pm
Location: Belgium
Contact:

Cast entity to EyeBot entity

Postby emerckx » Sun Apr 10, 2016 3:03 am

Hello,

I've retrieved the entities by the type of "eye-bot" and I want to cast them to CEyeBotEntity objects. In order to do so, I've used the code listed below.

Code: Select all

// get the entities CSpace::TMapPerType& tEntityMap = CSimulator::GetInstance().GetLoopFunctions().GetSpace().GetEntitiesByType( "eye-bot"); // loop over the entities for(CSpace::TMapPerType::iterator it = tEntityMap.begin(); it != tEntityMap.end(); ++it) { // cast the entity to an eye-bot entity CEyeBotEntity& cEyebotEnt = *any_cast<CEyeBotEntity*>(it->second); }
When I compile the code, no error messages are given. I have also included the header file for the eye-bot entity. But when I try to run the ARGoS simulator, I get the following error:
[INFO] Loaded library "/argos3/build_simulator/core/libargos3core_simulator.so"
[INFO] Loaded library "/argos3/build_simulator/testing/libtest_footbot_controller.so"
[INFO] Loaded library "/argos3/build_simulator/testing/libtest_eyebot_controller.so"
[FATAL] Can't load library "/argos3/build_simulator/testing/libtest_loop_functions.so" even after trying to add extensions for shared library (so) and module library (so):
/argos3/build_simulator/testing/libtest_loop_functions.so: /argos3/build_simulator/plugins/simulator/visualizations/qt-opengl/libargos3plugin_simulator_qtopengl.so: undefined symbol: _ZTIN5argos13CEyeBotEntityE
/argos3/build_simulator/testing/libtest_loop_functions.so.so: /argos3/build_simulator/testing/libtest_loop_functions.so.so: cannot open shared object file: No such file or directory
/argos3/build_simulator/testing/libtest_loop_functions.so.so: OK
So I have run the c++filt command on the error:

Code: Select all

c++filt _ZTIN5argos13CEyeBotEntityE
And I got the following output:
typeinfo for argos::CEyeBotEntity
Which I think it indicates that he can't find the CEyeBotEntity, or am I wrong?
I have the same issue with the CEPuckEntity and the CSpiriEntity objects.
But oddly enough, I do not have this issue with the CFootBotEntity :!:

Do you know what might cause this issue?

Sincerely yours,
Ewout Merckx.

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

Re: Cast entity to EyeBot entity

Postby pincy » Sun Apr 10, 2016 6:47 am

Hi Ewout,

It looks like you need to link the eye-bot library to your loop functions. In practice, in the CMakeLists.txt file that compiles your test_loop_functions, you need to have something like:

Code: Select all

target_link_libraries(test_loop_functions argos3core_simulator argos3plugin_simulator_dynamics2d argos3plugin_simulator_entities argos3plugin_simulator_eyebot # <- THIS IS MISSING! argos3plugin_simulator_genericrobot argos3plugin_simulator_media)
Cheers,
Carlo
I made ARGoS.

emerckx
Posts: 15
Joined: Tue Mar 29, 2016 1:37 pm
Location: Belgium
Contact:

Re: Cast entity to EyeBot entity

Postby emerckx » Sun Apr 10, 2016 1:49 pm

Hi Carlo,

Thank you very much for the explanation and quick response, with it I have been able to solve the issue. :D
I documented the changes I made below. Note that this is for the source version of ARGoS.

I first added the argos3plugin_${ARGOS_BUILD_FOR}_eyebot statement to the /argos3/src/testing/CMakeLists.txt file.

Code: Select all

if(ARGOS_BUILD_FOR_SIMULATOR OR ARGOS_BUILD_FOR STREQUAL "foot-bot") // other statements target_link_libraries(test_loop_functions argos3core_${ARGOS_BUILD_FOR} argos3plugin_${ARGOS_BUILD_FOR}_eyebot // <- I've added this line argos3plugin_${ARGOS_BUILD_FOR}_footbot ) endif(ARGOS_BUILD_FOR_SIMULATOR OR ARGOS_BUILD_FOR STREQUAL "foot-bot")
But that wasn't enough. I had to edit the test too. So in the /argos3/src/testing/experiment/test_footbot.argos file, I have added an eye-bot controller to the controllers node.

Code: Select all

<test_eyebot_controller id="y"> <actuators> <range_and_bearing implementation="default" /> </actuators> <sensors> <range_and_bearing implementation="medium" medium="rab" /> </sensors> <params /> </test_eyebot_controller>
Of course, I also had to add an eye-bot to the arena.

Code: Select all

<eye-bot id="eb"> <body position="1,1,0" orientation="0,0,0"/> <controller config="y"/> </eye-bot>
And in the implementation file /argos3/src/testing/experiment/test_loop_functions.cpp, I have changed the Init method by adding the code listing below.

Code: Select all

CEyeBotEntity& eb = dynamic_cast<CEyeBotEntity&>(GetSpace().GetEntity("eb")); CLEDEntity& cLedD = eb.GetComponent<CLEDEntity>("leds.led[led_2]"); cLedD.SetColor(CColor::GREEN);
Sincerely yours,
Ewout Merckx.

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

Re: Cast entity to EyeBot entity

Postby pincy » Sun Apr 10, 2016 6:09 pm

Hi Ewout,

You should be able to shorten

Code: Select all

CEyeBotEntity& eb = dynamic_cast<CEyeBotEntity&>(GetSpace().GetEntity("eb")); CLEDEntity& cLedD = eb.GetComponent<CLEDEntity>("leds.led[led_2]"); cLedD.SetColor(CColor::GREEN);
into the following one-liner:

Code: Select all

(dynamic_cast<CLEDEntity&>(GetSpace().GetEntity("eb.leds.led[led_2]"))).SetColor(CColor::GREEN);
Cheers,
Carlo
I made ARGoS.


Return to “How to... ?”