GAMS  1.2.2
Multicontroller.h
Go to the documentation of this file.
1 
54 #ifndef _GAMS_CONTROLLERS_MULTICONTROLLER_H_
55 #define _GAMS_CONTROLLERS_MULTICONTROLLER_H_
56 
57 #include "gams/GamsExport.h"
58 #include "gams/variables/Agent.h"
59 #include "gams/variables/Swarm.h"
60 #include "gams/variables/Self.h"
61 #include "gams/variables/Sensor.h"
68 
69 #include "madara/knowledge/containers/String.h"
70 #include "madara/knowledge/containers/Vector.h"
71 
72 #ifdef _GAMS_JAVA_
73 #include <jni.h>
74 #endif
75 
76 namespace gams
77 {
78  namespace controllers
79  {
84  {
85  public:
90  Multicontroller (madara::knowledge::KnowledgeBase & knowledge);
91 
95  virtual ~Multicontroller ();
96 
101  virtual int monitor (void);
102 
108  virtual int system_analyze (void);
109 
114  virtual int analyze (void);
115 
120  virtual int plan (void);
121 
126  virtual int execute (void);
127 
134  int run_once (void);
135 
147  int run (double loop_period = 0.0,
148  double max_runtime = -1,
149  double send_period = -1.0);
150 
161  inline int run_hz (double loop_hz = 0.0,
162  double max_runtime = -1,
163  double send_hz = -1.0)
164  {
165  double loop_rate, send_rate;
166 
167  // check for bad data
168  if (loop_hz <= 0.0)
169  loop_rate = 0.0;
170  // otherwise, set rate to 1s divided by the intended hz
171  else
172  loop_rate = 1.0 / loop_hz;
173 
174  // copy from loop hz if send hz is non-positive
175  if (send_hz <= 0)
176  send_rate = loop_rate;
177  // otherwise, set rate to 1s divided by the intended hz
178  else
179  send_rate = 1.0 / send_hz;
180 
181  return run (loop_rate, max_runtime, send_rate);
182  }
183 
189  void init_accent (const std::string & algorithm,
190  const madara::knowledge::KnowledgeMap & args = madara::knowledge::KnowledgeMap ());
191 
195  void clear_accents (void);
196 
205  void add_platform_factory (
206  const std::vector <std::string> & aliases,
207  platforms::PlatformFactory * factory);
208 
217  void add_algorithm_factory (
218  const std::vector <std::string> & aliases,
219  algorithms::AlgorithmFactory * factory);
220 
226  void init_algorithm (const std::string & algorithm,
227  const madara::knowledge::KnowledgeMap & args = madara::knowledge::KnowledgeMap ());
228 
235  void init_algorithm (algorithms::BaseAlgorithm * algorithm);
236 
242  void init_platform (const std::string & platform,
243  const madara::knowledge::KnowledgeMap & args =
244  madara::knowledge::KnowledgeMap ());
245 
252  void init_platform (platforms::BasePlatform * platform);
253 
254 #ifdef _GAMS_JAVA_
255 
259  void init_algorithm (jobject algorithm);
260 
265  void init_platform (jobject platform);
266 #endif
267 
273  void init_vars (const madara::knowledge::KnowledgeRecord::Integer & id = 0,
274  const madara::knowledge::KnowledgeRecord::Integer & processes = -1);
275 
282  void init_vars (platforms::BasePlatform & platform);
283 
290  void init_vars (algorithms::BaseAlgorithm & algorithm);
291 
296  algorithms::BaseAlgorithm * get_algorithm (void);
297 
302  platforms::BasePlatform * get_platform (void);
303 
304  protected:
305 
308 
311 
314 
317 
319  madara::knowledge::KnowledgeBase & knowledge_;
320 
323 
326 
329 
332 
335 
336  private:
337 
339  int run_once_ (void);
340  };
341  }
342 }
343 
344 #endif // _GAMS_CONTROLLERS_MULTICONTROLLER_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
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.
std::vector< BaseAlgorithm * > Algorithms
std::map< std::string, AlgorithmStatus > Algorithms
a map of sensor names to the sensor information
madara::knowledge::KnowledgeBase & knowledge_
Knowledge base.
Copyright (c) 2014 Carnegie Mellon University.
platforms::BasePlatform * platform_
Platform on which the controller is running.
std::map< std::string, Sensor * > Sensors
a map of sensor names to the sensor information
Definition: Sensor.h:238
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
variables::Algorithms algorithms_
Containers for algorithm information.
Copyright (c) 2014 Carnegie Mellon University.
algorithms::Algorithms accents_
Accents on the primary algorithm.
GAMS_EXPORT void init_vars(AccentStatuses &variables, madara::knowledge::KnowledgeBase &knowledge, const std::string &prefix)
Initializes accent status containers.
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
#define GAMS_EXPORT
Definition: GamsExport.h:20
variables::Self self_
Containers for self-referencing variables.
variables::Platforms platforms_
Containers for platform information.
algorithms::BaseAlgorithm * algorithm_
Algorithm to perform.
The base class that algorithms in GAMS use.
Definition: BaseAlgorithm.h:94
Base class for platform factories to create BasePlatforms.
Copyright (c) 2014 Carnegie Mellon University.
Copyright (c) 2014-2018 Carnegie Mellon University.
A controller that has the capability of starting many different threads.
Copyright (c) 2014 Carnegie Mellon University.
variables::Sensors sensors_
Containers for sensor information.
variables::Swarm swarm_
Containers for swarm-related variables.
Copyright (c) 2014 Carnegie Mellon University.
variables::Agents agents_
Containers for agent-related variables.