GAMS  1.2.2
BaseController.h
Go to the documentation of this file.
1 
54 #ifndef _GAMS_BASE_CONTROLLER_H_
55 #define _GAMS_BASE_CONTROLLER_H_
56 
57 #include "ControllerSettings.h"
58 
59 #include "gams/GamsExport.h"
60 #include "gams/variables/Agent.h"
61 #include "gams/variables/Swarm.h"
62 #include "gams/variables/Self.h"
63 #include "gams/variables/Sensor.h"
70 #include "gams/groups/GroupBase.h"
71 
72 #include "madara/knowledge/containers/String.h"
73 #include "madara/knowledge/containers/Vector.h"
74 
75 #ifdef _GAMS_JAVA_
76 #include <jni.h>
77 #endif
78 
79 namespace gams
80 {
81  namespace controllers
82  {
88  {
89  public:
95  BaseController (madara::knowledge::KnowledgeBase & knowledge,
96  const ControllerSettings & settings = ControllerSettings ());
97 
101  virtual ~BaseController ();
102 
107  virtual int monitor (void);
108 
114  virtual int system_analyze (void);
115 
120  virtual int analyze (void);
121 
126  virtual int plan (void);
127 
132  virtual int execute (void);
133 
140  int run_once (void);
141 
153  int run (double loop_period,
154  double max_runtime = -1,
155  double send_period = -1.0);
156 
167  inline int run_hz (double loop_hz = 0.0,
168  double max_runtime = -1,
169  double send_hz = -1.0)
170  {
171  double loop_rate, send_rate;
172 
173  // check for bad data
174  if (loop_hz <= 0.0)
175  loop_rate = 0.0;
176  // otherwise, set rate to 1s divided by the intended hz
177  else
178  loop_rate = 1.0 / loop_hz;
179 
180  // copy from loop hz if send hz is non-positive
181  if (send_hz <= 0)
182  send_rate = loop_rate;
183  // otherwise, set rate to 1s divided by the intended hz
184  else
185  send_rate = 1.0 / send_hz;
186 
187  return run (loop_rate, max_runtime, send_rate);
188  }
189 
194  int run (void);
195 
201  void init_accent (const std::string & algorithm,
202  const madara::knowledge::KnowledgeMap & args =
203  madara::knowledge::KnowledgeMap ());
204 
208  void clear_accents (void);
209 
218  void add_platform_factory (
219  const std::vector <std::string> & aliases,
220  platforms::PlatformFactory * factory);
221 
230  void add_algorithm_factory (
231  const std::vector <std::string> & aliases,
232  algorithms::AlgorithmFactory * factory);
233 
239  void init_algorithm (const std::string & algorithm,
240  const madara::knowledge::KnowledgeMap & args = madara::knowledge::KnowledgeMap ());
241 
248  void init_algorithm (algorithms::BaseAlgorithm * algorithm);
249 
255  void init_platform (const std::string & platform,
256  const madara::knowledge::KnowledgeMap & args =
257  madara::knowledge::KnowledgeMap ());
258 
265  void init_platform (platforms::BasePlatform * platform);
266 
270  void configure (const ControllerSettings & settings);
271 
272 #ifdef _GAMS_JAVA_
273 
277  void init_algorithm (jobject algorithm);
278 
283  void init_platform (jobject platform);
284 #endif
285 
291  void init_vars (const madara::knowledge::KnowledgeRecord::Integer & id = 0,
292  const madara::knowledge::KnowledgeRecord::Integer & processes = -1);
293 
300  void init_vars (const std::string & self_prefix,
301  const std::string & group_name = "");
302 
308  void init_vars (const std::string & self_prefix,
309  const groups::GroupBase * group);
310 
317  void init_vars (platforms::BasePlatform & platform);
318 
325  void init_vars (algorithms::BaseAlgorithm & algorithm);
326 
331  algorithms::BaseAlgorithm * get_algorithm (void);
332 
337  platforms::BasePlatform * get_platform (void);
338 
343  variables::Sensors * get_sensors (void);
344 
348  void save_checkpoint (void);
349 
350  protected:
351 
354 
357 
360 
363 
365  madara::knowledge::KnowledgeBase & knowledge_;
366 
369 
372 
375 
378 
381 
384 
387  private:
388 
390  int run_once_ (void);
391  };
392  }
393 }
394 
395 #endif // _GAMS_BASE_CONTROLLER_H_
Base class for algorithm factories that classes derived from.
Copyright (c) 2014 Carnegie Mellon University.
A container for swarm information.
Definition: Swarm.h:75
Copyright (c) 2016 Carnegie Mellon University.
std::vector< BaseAlgorithm * > Algorithms
std::map< std::string, AlgorithmStatus > Algorithms
a map of sensor names to the sensor information
Copyright (c) 2014 Carnegie Mellon University.
std::map< std::string, Sensor * > Sensors
a map of sensor names to the sensor information
Definition: Sensor.h:238
variables::Swarm swarm_
Containers for swarm-related variables.
algorithms::BaseAlgorithm * algorithm_
Algorithm to perform.
madara::knowledge::KnowledgeBase & knowledge_
Knowledge base.
The base platform for all platforms to use.
Definition: BasePlatform.h:190
Copyright (c) 2014 Carnegie Mellon University.
std::vector< Agent > Agents
An array of agent knowledge.
Definition: Agent.h:246
Copyright (c) 2014 Carnegie Mellon University.
variables::Sensors sensors_
Containers for sensor information.
variables::Agents agents_
Containers for agent-related variables.
ControllerSettings settings_
Settings for controller management and qos.
GAMS_EXPORT void init_vars(AccentStatuses &variables, madara::knowledge::KnowledgeBase &knowledge, const std::string &prefix)
Initializes accent status containers.
Copyright (c) 2017 Carnegie Mellon University.
Contains all GAMS-related tools, classes and code.
A container for self referencing information.
Definition: Self.h:69
Copyright (c) 2014 Carnegie Mellon University.
std::map< std::string, PlatformStatus > Platforms
a map of sensor names to the sensor information
Base class for a group of agents.
Definition: GroupBase.h:90
int checkpoint_count_
keeps track of the checkpoints saved in the control loop
#define GAMS_EXPORT
Definition: GamsExport.h:20
variables::Self self_
Containers for self-referencing variables.
The base class that algorithms in GAMS use.
Definition: BaseAlgorithm.h:94
int run_hz(double loop_hz=0.0, double max_runtime=-1, double send_hz=-1.0)
Runs iterations of the MAPE loop with specified hertz.
Base class for platform factories to create BasePlatforms.
Copyright (c) 2014 Carnegie Mellon University.
variables::Algorithms algorithms_
Containers for algorithm information.
platforms::BasePlatform * platform_
Platform on which the controller is running.
The basic controller that can be used to perform actions on platforms and algorithms.
algorithms::Algorithms accents_
Accents on the primary algorithm.
Copyright (c) 2014-2018 Carnegie Mellon University.
Copyright (c) 2014 Carnegie Mellon University.
Copyright (c) 2014 Carnegie Mellon University.
Settings used for initializing GAMS controllers.
variables::Platforms platforms_
Containers for platform information.