Kilobot data and LoopFunction

Requests regarding how to set up experiments in ARGoS.
AntonioC
Posts: 48
Joined: Mon Aug 30, 2021 7:02 pm

Kilobot data and LoopFunction

Postby AntonioC » Thu Jan 20, 2022 11:23 pm

I am working with loop functions but I have some problems.
I use the following functions but am told they are not declared. It seems strange to me since I have imported all the libraries.

Code: Select all

void CTrajectoryLoopFunctions::UpdateKilobotState(CKilobotEntity &c_kilobot_entity){ UInt16 unKilobotID=GetKilobotId(c_kilobot_entity); CVector2 vecKilobotPosition=GetKilobotPosition(c_kilobot_entity); CColor cKilobotColor=GetKilobotLedColor(c_kilobot_entity); if (cKilobotColor == CColor::BLUE){ } }

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

Re: Kilobot data and LoopFunction

Postby pincy » Thu Jan 20, 2022 11:36 pm

I don't understand the problem, can you please provide accurate information? Exact error messages etc
I made ARGoS.

AntonioC
Posts: 48
Joined: Mon Aug 30, 2021 7:02 pm

Re: Kilobot data and LoopFunction

Postby AntonioC » Fri Jan 21, 2022 4:41 pm

Below is the code of the ARK system

Code: Select all

#include "trajectory_loop_functions.h" /****************************************/ /****************************************/ CTrajectoryLoopFunctions::CTrajectoryLoopFunctions(): m_unDataAcquisitionFrequency(10){ } /****************************************/ /****************************************/ void CTrajectoryLoopFunctions::Init(TConfigurationNode& t_node) { /* Initialize ALF*/ CALF::Init(t_node); /* Other initializations: Varibales, Log file opening... */ // Open a log file m_cOutput.open(m_strOutputFileName, std::ios_base::trunc | std::ios_base::out); } /****************************************/ /****************************************/ void CTrajectoryLoopFunctions::Reset() { /* Close data file */ m_cOutput.close(); /* Reopen the file, erasing its contents */ m_cOutput.open(m_strOutputFileName, std::ios_base::trunc | std::ios_base::out); } /****************************************/ /****************************************/ void CTrajectoryLoopFunctions::Destroy() { /* Close data file */ m_cOutput.close(); } /****************************************/ /****************************************/ void CTrajectoryLoopFunctions::PostStep(){ /* Log experiment's results*/ if(((UInt16)m_fTimeInSeconds%m_unDataAcquisitionFrequency==0)&&((m_fTimeInSeconds-(UInt16)m_fTimeInSeconds)==0)){ m_cOutput << (UInt16) m_fTimeInSeconds << '\t'; UInt16 unKilobotID; CVector2 cKilobotPosition; for(UInt16 it=0;it< m_tKilobotEntities.size();it++){ unKilobotID=GetKilobotId(*m_tKilobotEntities[it]); cKilobotPosition=GetKilobotPosition(*m_tKilobotEntities[it]); m_cOutput << unKilobotID << '\t' << cKilobotPosition.GetX() << '\t' << cKilobotPosition.GetY() << '\t' << (UInt16)m_vecHasFood[unKilobotID] << '\t'; } m_cOutput << std::endl; } } /****************************************/ /****************************************/ /****************************************/ /****************************************/ /****************************************/ /****************************************/ /****************************************/ /****************************************/ void CTrajectoryLoopFunctions::GetExperimentVariables(TConfigurationNode& t_tree){ /* Get the experiment variables node from the .argos file */ TConfigurationNode& tExperimentVariablesNode = GetNode(t_tree,"variables"); /* Get Gradient field radius */ GetNodeAttribute(tExperimentVariablesNode, "gradientfieldradius", m_fGradientFieldRadius); /* Get Gradient field color */ GetNodeAttribute(tExperimentVariablesNode, "gradientfieldcolor", m_cGradientFieldColor); /* Get the output datafile name and open it */ GetNodeAttribute(tExperimentVariablesNode, "datafilename", m_strOutputFileName); /* Get the frequency of data saving */ GetNodeAttributeOrDefault(tExperimentVariablesNode, "dataacquisitionfrequency", m_unDataAcquisitionFrequency, m_unDataAcquisitionFrequency); /* Get the frequency of updating the environment plot */ GetNodeAttributeOrDefault(tExperimentVariablesNode, "m_unEnvironmentPlotUpdateFrequency", m_unEnvironmentPlotUpdateFrequency, m_unEnvironmentPlotUpdateFrequency); /* Get the time for one kilobot message */ GetNodeAttributeOrDefault(tExperimentVariablesNode, "timeforonemessage", m_fTimeForAMessage, m_fTimeForAMessage); } /****************************************/ /****************************************/ void CTrajectoryLoopFunctions::UpdateKilobotState(CKilobotEntity &c_kilobot_entity){ UInt16 unKilobotID=GetKilobotId(c_kilobot_entity); CVector2 vecKilobotPosition=GetKilobotPosition(c_kilobot_entity); CColor cKilobotColor=GetKilobotLedColor(c_kilobot_entity); if (cKilobotColor == CColor::BLUE){ } } /****************************************/ /****************************************/ /****************************************/ /****************************************/ REGISTER_LOOP_FUNCTIONS(CTrajectoryLoopFunctions, "trajectory_loop_functions")
Below is the code of the ARK system library

Code: Select all

#ifndef TRAJECTORY_LOOP_FUNCTIONS_H #define TRAJECTORY_LOOP_FUNCTIONS_H namespace argos { class CSpace; class CFloorEntity; class CSimulator; } #include <math.h> #include <argos3/core/simulator/loop_functions.h> #include <argos3/plugins/robots/kilobot/simulator/ALF.h> #include <argos3/core/simulator/simulator.h> #include <argos3/core/simulator/physics_engine/physics_engine.h> #include <argos3/core/utility/math/vector3.h> #include <argos3/core/utility/math/vector2.h> #include <argos3/core/utility/math/ray2.h> #include <argos3/core/utility/math/quaternion.h> #include <argos3/core/utility/math/rng.h> #include <argos3/core/utility/logging/argos_log.h> #include <argos3/core/simulator/entity/embodied_entity.h> #include <argos3/core/simulator/entity/composable_entity.h> #include <argos3/plugins/simulator/entities/led_equipped_entity.h> #include <argos3/core/simulator/entity/floor_entity.h> #include <argos3/plugins/robots/kilobot/simulator/kilobot_communication_entity.h> #include <argos3/plugins/robots/kilobot/simulator/kilobot_communication_medium.h> #include <argos3/plugins/robots/kilobot/simulator/kilobot_communication_default_actuator.h> //kilobot messaging #include <argos3/plugins/robots/kilobot/control_interface/kilolib.h> #include <argos3/plugins/robots/kilobot/control_interface/message_crc.h> #include <argos3/plugins/robots/kilobot/control_interface/message.h> #include <array> using namespace argos; class CTrajectoryLoopFunctions : public CLoopFunctions { public: CTrajectoryLoopFunctions(); virtual ~CTrajectoryLoopFunctions(){} virtual void Init(TConfigurationNode& t_tree); virtual void Reset(); virtual void Destroy(); virtual void PostStep(); /** Get a Vector of all the Kilobots in the space */ void GetKilobotsEntities(); /** Setup the initial state of the Kilobots in the space */ void SetupInitialKilobotStates(); /** Setup the initial state of the kilobot pc_kilobot_entity */ void SetupInitialKilobotState(CKilobotEntity& c_kilobot_entity); /** Setup virtual environment */ void SetupVirtualEnvironments(TConfigurationNode& t_tree); /** Get experiment variables */ void GetExperimentVariables(TConfigurationNode& t_tree); /** Get the message to send to a Kilobot according to its position */ void UpdateKilobotState(CKilobotEntity& c_kilobot_entity); /** Get the message to send to a Kilobot according to its position */ void UpdateVirtualSensor(CKilobotEntity& c_kilobot_entity); /** Used to plot the Virtual environment on the floor */ virtual CColor GetFloorColor(const CVector2& vec_position_on_plane); private: /************************************/ /* Virtual Environment variables */ /************************************/ /** virtual environment types*/ enum EAreaType { HOME = 0, FOOD = 1 }; /** virtual environment struct*/ struct SVirtualArea { EAreaType EnvType; CVector2 GoalLocation; Real GoalSize; SInt16 UpperBoundVS=13; CColor Color; Real MinTimeBetweenTwoMsg; std::vector < Real > LastSent; std::vector < bool > SignalSwap; }; /** Virtual environments (one food area and one home area in this example) */ SVirtualArea m_sFoodEnv={FOOD}; SVirtualArea m_sHomeEnv={HOME}; /***********************************/ /* Experiment variables */ /***********************************/ /** Virtual robots' states*/ std::vector < bool > m_vecHasFood; std::vector <SVirtualArea*> m_vecKilobotsEnvironment; /** Gradient field radius */ Real m_fGradientFieldRadius; /** Gradiant field color*/ CColor m_cGradientFieldColor; /** output file for data acquizition */ std::ofstream m_cOutput; /** output file name*/ std::string m_strOutputFileName; /** data acquisition frequency in ticks */ UInt16 m_unDataAcquisitionFrequency; }; #endif
Below is the error message when I run the make command

Code: Select all

antonio@antonio-Lenovo-V110-15AST:~/Desktop/argos3-kilobot-master/build$ make [ 1%] Automatic MOC for target argos3plugin_simulator_kilolib [ 1%] Built target argos3plugin_simulator_kilolib_autogen [ 5%] Built target argos3plugin_simulator_kilolib [ 6%] Automatic MOC for target argos3plugin_simulator_kilobot [ 6%] Built target argos3plugin_simulator_kilobot_autogen [ 23%] Built target argos3plugin_simulator_kilobot [ 25%] Automatic MOC for target kilobot_diffusion [ 25%] Built target kilobot_diffusion_autogen [ 28%] Built target kilobot_diffusion [ 29%] Automatic MOC for target kilobot_phototaxis [ 29%] Built target kilobot_phototaxis_autogen [ 32%] Built target kilobot_phototaxis [ 33%] Automatic MOC for target orbit_star [ 33%] Built target orbit_star_autogen [ 36%] Built target orbit_star [ 37%] Automatic MOC for target test_speaker_mod [ 37%] Built target test_speaker_mod_autogen [ 40%] Built target test_speaker_mod [ 41%] Automatic MOC for target move_to_light [ 41%] Built target move_to_light_autogen [ 44%] Built target move_to_light [ 45%] Automatic MOC for target simple_movement [ 45%] Built target simple_movement_autogen [ 48%] Built target simple_movement [ 50%] Automatic MOC for target gradient_simple [ 50%] Built target gradient_simple_autogen [ 53%] Built target gradient_simple [ 54%] Automatic MOC for target test_listener [ 54%] Built target test_listener_autogen [ 57%] Built target test_listener [ 58%] Automatic MOC for target blinky [ 58%] Built target blinky_autogen [ 61%] Built target blinky [ 62%] Automatic MOC for target test_speaker [ 62%] Built target test_speaker_autogen [ 65%] Built target test_speaker [ 66%] Automatic MOC for target nonblocked_movement [ 66%] Built target nonblocked_movement_autogen [ 69%] Built target nonblocked_movement [ 70%] Automatic MOC for target test_listener_mod [ 70%] Built target test_listener_mod_autogen [ 73%] Built target test_listener_mod [ 75%] Automatic MOC for target disperse [ 75%] Built target disperse_autogen [ 78%] Built target disperse [ 79%] Automatic MOC for target orbit_planet [ 79%] Built target orbit_planet_autogen [ 82%] Built target orbit_planet [ 83%] Automatic MOC for target sync [ 83%] Built target sync_autogen [ 86%] Built target sync [ 87%] Automatic MOC for target test_debug [ 87%] Built target test_debug_autogen [ 90%] Built target test_debug [ 91%] Automatic MOC for target debug_loop_functions [ 91%] Built target debug_loop_functions_autogen [ 94%] Built target debug_loop_functions [ 95%] Automatic MOC for target trajectory_loop_functions [ 95%] Built target trajectory_loop_functions_autogen Scanning dependencies of target trajectory_loop_functions [ 96%] Building CXX object examples/loop_functions/trajectory_loop_functions/CMakeFiles/trajectory_loop_functions.dir/trajectory_loop_functions.cpp.o /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp: In member function ‘virtual void CTrajectoryLoopFunctions::Init(argos::TConfigurationNode&)’: /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:16:22: error: cannot call member function ‘virtual void CALF::Init(argos::TConfigurationNode&)’ without object CALF::Init(t_node); ^ /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp: In member function ‘virtual void CTrajectoryLoopFunctions::PostStep()’: /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:45:17: error: ‘m_fTimeInSeconds’ was not declared in this scope if(((UInt16)m_fTimeInSeconds%m_unDataAcquisitionFrequency==0)&&((m_fTimeInSeconds-(UInt16)m_fTimeInSeconds)==0)){ ^~~~~~~~~~~~~~~~ /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:49:29: error: ‘m_tKilobotEntities’ was not declared in this scope for(UInt16 it=0;it< m_tKilobotEntities.size();it++){ ^~~~~~~~~~~~~~~~~~ /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:49:29: note: suggested alternative: ‘GetKilobotsEntities’ for(UInt16 it=0;it< m_tKilobotEntities.size();it++){ ^~~~~~~~~~~~~~~~~~ GetKilobotsEntities /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:50:25: error: ‘GetKilobotId’ was not declared in this scope unKilobotID=GetKilobotId(*m_tKilobotEntities[it]); ^~~~~~~~~~~~ /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:50:25: note: suggested alternative: ‘unKilobotID’ unKilobotID=GetKilobotId(*m_tKilobotEntities[it]); ^~~~~~~~~~~~ unKilobotID /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:51:30: error: ‘GetKilobotPosition’ was not declared in this scope cKilobotPosition=GetKilobotPosition(*m_tKilobotEntities[it]); ^~~~~~~~~~~~~~~~~~ /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:51:30: note: suggested alternative: ‘cKilobotPosition’ cKilobotPosition=GetKilobotPosition(*m_tKilobotEntities[it]); ^~~~~~~~~~~~~~~~~~ cKilobotPosition /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp: In member function ‘void CTrajectoryLoopFunctions::GetExperimentVariables(argos::TConfigurationNode&)’: /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:79:95: error: ‘m_unEnvironmentPlotUpdateFrequency’ was not declared in this scope GetNodeAttributeOrDefault(tExperimentVariablesNode, "m_unEnvironmentPlotUpdateFrequency", m_unEnvironmentPlotUpdateFrequency, m_unEnvironmentPlotUpdateFrequency); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:81:78: error: ‘m_fTimeForAMessage’ was not declared in this scope GetNodeAttributeOrDefault(tExperimentVariablesNode, "timeforonemessage", m_fTimeForAMessage, m_fTimeForAMessage); ^~~~~~~~~~~~~~~~~~ /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp: In member function ‘void CTrajectoryLoopFunctions::UpdateKilobotState(argos::CKilobotEntity&)’: /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:88:23: error: ‘GetKilobotId’ was not declared in this scope UInt16 unKilobotID=GetKilobotId(c_kilobot_entity); ^~~~~~~~~~~~ /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:88:23: note: suggested alternative: ‘unKilobotID’ UInt16 unKilobotID=GetKilobotId(c_kilobot_entity); ^~~~~~~~~~~~ unKilobotID /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:89:32: error: ‘GetKilobotPosition’ was not declared in this scope CVector2 vecKilobotPosition=GetKilobotPosition(c_kilobot_entity); ^~~~~~~~~~~~~~~~~~ /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:89:32: note: suggested alternative: ‘vecKilobotPosition’ CVector2 vecKilobotPosition=GetKilobotPosition(c_kilobot_entity); ^~~~~~~~~~~~~~~~~~ vecKilobotPosition /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:90:25: error: ‘GetKilobotLedColor’ was not declared in this scope CColor cKilobotColor=GetKilobotLedColor(c_kilobot_entity); ^~~~~~~~~~~~~~~~~~ /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:90:25: note: suggested alternative: ‘cKilobotColor’ CColor cKilobotColor=GetKilobotLedColor(c_kilobot_entity); ^~~~~~~~~~~~~~~~~~ cKilobotColor /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:88:11: warning: unused variable ‘unKilobotID’ [-Wunused-variable] UInt16 unKilobotID=GetKilobotId(c_kilobot_entity); ^~~~~~~~~~~ /home/antonio/Desktop/argos3-kilobot-master/src/examples/loop_functions/trajectory_loop_functions/trajectory_loop_functions.cpp:89:13: warning: unused variable ‘vecKilobotPosition’ [-Wunused-variable] CVector2 vecKilobotPosition=GetKilobotPosition(c_kilobot_entity); ^~~~~~~~~~~~~~~~~~ examples/loop_functions/trajectory_loop_functions/CMakeFiles/trajectory_loop_functions.dir/build.make:62: recipe for target 'examples/loop_functions/trajectory_loop_functions/CMakeFiles/trajectory_loop_functions.dir/trajectory_loop_functions.cpp.o' failed make[2]: *** [examples/loop_functions/trajectory_loop_functions/CMakeFiles/trajectory_loop_functions.dir/trajectory_loop_functions.cpp.o] Error 1 CMakeFiles/Makefile2:1654: recipe for target 'examples/loop_functions/trajectory_loop_functions/CMakeFiles/trajectory_loop_functions.dir/all' failed make[1]: *** [examples/loop_functions/trajectory_loop_functions/CMakeFiles/trajectory_loop_functions.dir/all] Error 2 Makefile:151: recipe for target 'all' failed make: *** [all] Error 2 antonio@antonio-Lenovo-V110-15AST:~/Desktop/argos3-kilobot-master/build$

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

Re: Kilobot data and LoopFunction

Postby pincy » Fri Jan 21, 2022 4:58 pm

The code you've attached has a number of errors, e.g., you call the method CALF::Init() despite your class not being a subclass of CALF.

The issues you're encountering seem to be more on C++ programming than ARGoS. I can't provide detailed support with external plugins like ARK. If you need specific guidance with it, please reach out to the authors of the paper.
I made ARGoS.


Return to “How to... ?”



cron