Passing of data

Requests regarding how to set up experiments in ARGoS.
Max
Posts: 20
Joined: Tue Mar 31, 2015 4:55 pm

Passing of data

Postby Max » Tue Sep 08, 2015 3:59 pm

Hi Carlo,

I'm currently writing an Swarm - ACO simulation with reference from Foraging example given by you. I have observed that the data were pass from footbot_foraging.cpp into footbot_foraging_loop.cpp thru a handler to controller entity. I will like to ask if is possible to pass a array of struct data from a loop.ccp to a controller.cpp.

Thank you
Max

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

Re: Passing of data

Postby pincy » Wed Sep 09, 2015 6:34 pm

Hi Max,

Sure it's possible.
  1. Add a method to your controller that accepts the array (or, better, std::vector) that you want;
  2. Once you have the pointer to a controller in the loop functions, you simply need to call that method with the data in the loop functions.
An example of how a loop functions can inform a robot is offered in the foraging (to tell a robot "you've got the object") and in the embedding one (to setup the neural network for a trial).

Cheers,
Carlo
I made ARGoS.

Max
Posts: 20
Joined: Tue Mar 31, 2015 4:55 pm

Re: Passing of data

Postby Max » Sat Sep 12, 2015 6:04 pm

Hi Carlo,

Thanks for your advice, i tried writing the program with the example given in foraging file but i'm hit with these errors:

[WARNING] Can't open library "./build/controllers/quadcopter/libquadcopter.so": ./build/controllers/quadcopter/libquadcopter.so: undefined symbol: _ZTV24CQuadcopterLoopFunctions
[WARNING] Can't open library "./build/controllers/quadcopter/libquadcopter.so.so": ./build/controllers/quadcopter/libquadcopter.so.so: cannot open shared object file: No such file or directory
[WARNING] Can't open library "./build/controllers/quadcopter/libquadcopter.so.so": ./build/controllers/quadcopter/libquadcopter.so.so: cannot open shared object file: No such file or directory
[WARNING] Can't open library "/usr/local/lib/argos3/build/controllers/quadcopter/libquadcopter.so": /usr/local/lib/argos3/build/controllers/quadcopter/libquadcopter.so: cannot open shared object file: No such file or directory
[WARNING] Can't open library "/usr/local/lib/argos3/build/controllers/quadcopter/libquadcopter.so.so": /usr/local/lib/argos3/build/controllers/quadcopter/libquadcopter.so.so: cannot open shared object file: No such file or directory
[WARNING] Can't open library "/usr/local/lib/argos3/build/controllers/quadcopter/libquadcopter.so.so": /usr/local/lib/argos3/build/controllers/quadcopter/libquadcopter.so.so: cannot open shared object file: No such file or directory

Based on past experiences i believe is the CMakeLists.txt is the culprit but after trying to look thru all the possible CMakeList. I'm still unable to solve this problem, totally out of my wits.

Any advice on the areas i should look into?
Thank you
Max

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

Re: Passing of data

Postby pincy » Mon Sep 14, 2015 5:52 am

Hi Max,

You are encountering a linking error.

Code: Select all

undefined symbol: _ZTV24CQuadcopterLoopFunctions
Linking errors occur when you declare something in the .h file, and forget to implement it in the .cpp file. Sometimes, the error is that you simply forgot to add the .cpp file in the list of files to compile. Other times, you're missing a method.

To understand what is going wrong, you should use the following command:

Code: Select all

$ c++filt _ZTV24CQuadcopterLoopFunctions
This command translates ("demangles") the missing symbol into human readable form. Knowing which symbol it is should tell you what is missing in your code.

Cheers,
Carlo
I made ARGoS.

Max
Posts: 20
Joined: Tue Mar 31, 2015 4:55 pm

Re: Passing of data

Postby Max » Mon Sep 14, 2015 7:14 am

Hi Carlo,

Thank you for the quick reply, i have tried out the command you have given. It gives "
vtable for CQuadcopterLoopFunctions". i don't quite understand if this means that there is something wrong with vtable. I read up on vtable (which is know as virtual table) but don't quite understand what is this all about. Appreciate if you are able to explain what is this.

Thank you very much
Max

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

Re: Passing of data

Postby pincy » Mon Sep 14, 2015 9:26 am

Well, I suggest you to read a little about how C++ works inside :-)

The vtable is a little data structure that is prepended to each object that contains virtual methods. This structure allows the run-time environment to call the right method when you have a class hierarchy.

Often, when the error is the one you get, it is because you forgot to provide an implementation for the class destructor. You have the declaration but don't have the implementation. Try that. If that's not the case, attach your code and I'll see if I spot the problem.

Anyway, the idea is that you're missing a method implementation. Go through the .h and check that each method of your class has an implementation in the .cpp. Also, make sure that you actually compile the .cpp file! :-)

Cheers,
Carlo
I made ARGoS.

Max
Posts: 20
Joined: Tue Mar 31, 2015 4:55 pm

Re: Passing of data

Postby Max » Mon Sep 14, 2015 5:14 pm

Hi Carlo,

thank you for your suggestion. Pardon me as i'm quite new to C++ and may ask some newbie questions.
i have found the problem and are able to pass the struct data from Loop function.cpp to controller.cpp but the interesting part about the program is that i'm not able to change any struct variable in the Loop function. After searching online for this problem and going thru the code again, i'm still not quite sure what am i missing out that cause such a problem.

I have attached my working file for your reference and appreciate your guidance on this.

Thank you
Max
Attachments
quadcopter_loop_functions.zip
(4.05 KiB) Downloaded 823 times
quadcopter.zip
(6.73 KiB) Downloaded 749 times

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

Re: Passing of data

Postby pincy » Wed Sep 16, 2015 8:51 am

Hi,

I looked at your code, but I didn't understand the problem. Can you explain a little more in detail what you're trying to achieve?

Cheers,
Carlo
I made ARGoS.

Max
Posts: 20
Joined: Tue Mar 31, 2015 4:55 pm

Re: Passing of data

Postby Max » Wed Sep 16, 2015 2:30 pm

Hi Carlo,

Pardon me for my poor explanation, as mention, i have created a struct data (name:Trailphe) in the loop_function.h with the intention to pass the data to quadcopter.cpp. the data must be able to be change in both loop_function.cpp and quadcopter.cpp. It seems that i tried change the value of variables in the struct by doing the following in CQuadcopterLoopFunctions::Init

trailphe.LocationY=123.0f;
trailphe.LocationX=124.0f;
trailphe.phe=6.0;

Next i tried calling out the values of trailphe.phe but the values turns out to be 3 which is the initializing value. It seems that the code is not writing in the values into the variables and i don't know what to look into for this.

Thank you
Max

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

Re: Passing of data

Postby pincy » Wed Sep 16, 2015 4:37 pm

The problem in your code is that you have these lines in your controller:

Code: Select all

CQuadcopterLoopFunctions* trailpheu = new CQuadcopterLoopFunctions; CQuadcopterLoopFunctions::Trailphe& trailphe = trailpheu->GetTrailData();
You seem to have not understood how ARGoS works. When you do a real-word experiment, you have two things to set up: (a) the experimental arena, and (b) the robot controller.

ARGoS, as a simulator, allows you to do the same.
  1. Regarding the experimental arena in the real world, there are (1) static aspects, like the position of the walls, and (2) dynamic aspects, like you, as a person, moving robots around and taking measures as the experiment goes to evaluate the robot controller. In ARGoS, (1) maps to the .argos file, and (2) maps to the loop functions. In other words, the loop functions are a set of functions executed by ARGoS to allow you to play "God mode" on the simulation.
  2. Regarding the robot controller, this in ARGoS simply maps to the controller class.
For this reason, creating a loop function in the controller makes no sense. It is like you going "inside" the robot and then trying to change the world from there.

Have a look at how the foraging examples is made: the loop functions, playing the role of you, collect a list of pointers to robot controllers. Then, data is exchanged between the robot controllers and the loop functions just by calling relevant functions of the controller in the loop functions. This is because you, as "God", can modify the world as you please; but robots can't, they need to use their sensors and actuators.

Hope this clears a bit how ARGoS works. As for what you want to achieve, you simply need to add a method in the robot controller that allows one to get the values that you want to store in the loop functions. Then, in the loop functions you add a loop executed when necessary (e.g., after each time step) that goes through the controllers and collects the data.

Cheers,
Carlo
I made ARGoS.


Return to “How to... ?”