Exemplo n.º 1
0
/// Tests logicals operators (&&, ||)
void read_and_create_files (madara::knowledge::KnowledgeBase & knowledge)
{
  ACE_TRACE (ACE_TEXT ("test_assignments"));

  knowledge.clear ();

  knowledge.read_file ("sample", "/files/sample.jpg");
  knowledge.write_file ("sample", "/files/sample_copy.jpg");

  knowledge.set (".a_string", "Hello world!");
  knowledge.write_file (".a_string", "/files/hello_world.txt");
  knowledge.read_file ("hello_world", "/files/hello_world.txt");
  knowledge.write_file ("hello_world", "/files/hello_world_copy.txt");
  
  knowledge.set (".an_integer", madara::knowledge::KnowledgeRecord::Integer (10));
  knowledge.write_file (".an_integer", "/files/ten.txt");
  knowledge.read_file ("ten", "/files/ten.txt");
  knowledge.write_file ("ten", "/files/ten_copy.txt");
  
  knowledge.set (".a_double", 12.5);
  knowledge.write_file (".a_double", "/files/twelve.txt");
  knowledge.read_file ("double", "/files/twelve.txt");
  knowledge.write_file ("double", "/files/twelve_copy.txt");

  knowledge.set (".an_xml",
    "<tree><leaf>15</leaf><leaf>This leaf is empty.</leaf></tree>");
  knowledge.write_file (".an_xml", "/files/an_xml_file.xml");
  knowledge.read_file ("a_tree", "/files/an_xml_file.xml");
  knowledge.write_file ("a_tree", "/files/an_xml_file_copy.xml");

  
  knowledge.set ("finished_transmitting");
  
}
Exemplo n.º 2
0
void
test_hz(engine::KnowledgeBase & knowledge,
  controllers::BaseController & loop, double hz = 0.0, double duration = 10.0)
{
  algorithm->reset_counters();
  std::cerr << "Testing " << duration << "s experiment with "
    << hz << "hz.\n";
  loop.run_hz(hz, duration);
  knowledge.set(".loops", algorithm->loops);

#ifndef _MADARA_NO_KARL_
  knowledge.evaluate(".loop_speed = .loops / 10");
  knowledge.evaluate(".legible_speed = to_legible_hertz(.loop_speed)");
#else
  knowledge.set(".loop_speed", algorithm->loops / 10);
#endif
  knowledge.print(
    "  Results: {.loops} loop executions @ {.legible_speed}\n");

  if (hz == 0.0 ||((double)algorithm->loops > hz * .1 * duration) || 
      algorithm->loops > 100)
  {
    knowledge.print(
      "  SUCCESS: {.loops} > hz * .1 * duration\n");
  }
  else
  {
    knowledge.print(
      "  FAIL: {.loops} < hz * .1 * duration\n");
    ++gams_fails;
  }
}
Exemplo n.º 3
0
/// Tests logicals operators (&&, ||)
void create_arrays(madara::knowledge::KnowledgeBase& knowledge)
{
  knowledge.clear();

  std::vector<double> doubles_vector;
  doubles_vector.resize(5);
  doubles_vector[0] = 2.0 / 3;
  doubles_vector[1] = 5.0 / 4;
  doubles_vector[2] = -3.14159;
  doubles_vector[3] = 42.0;
  doubles_vector[4] = 3000.5238;

  knowledge.set(
      "doubles_vector", doubles_vector, madara::knowledge::EvalSettings::SEND);

  madara::knowledge::KnowledgeRecord::Integer* integer_array =
      new madara::knowledge::KnowledgeRecord::Integer[3];
  integer_array[0] = 0;
  integer_array[1] = 1;
  integer_array[2] = 2;

  knowledge.set("integers_vector", integer_array, 3,
      madara::knowledge::EvalSettings::SEND);

#ifndef _MADARA_NO_KARL_
  knowledge.evaluate(
      "var_array[1] = 3.0", madara::knowledge::EvalSettings::SEND);
  knowledge.evaluate(
      "var_array[3] = 20", madara::knowledge::EvalSettings::SEND);
#else
  knowledge.set_index(
      "var_array", 1, 3.0, madara::knowledge::EvalSettings::SEND);
  knowledge.set_index(
      "var_array", 3, Integer(3.0), madara::knowledge::EvalSettings::SEND);
#endif  // _MADARA_NO_KARL_

  knowledge.set(
      "finished_transmitting", 1, madara::knowledge::EvalSettings::SEND);
  knowledge.print("Sending the following data sets to id 1\n");
  knowledge.print("doubles_vector = [{doubles_vector}]\n");
  knowledge.print("integers_vector = [{integers_vector}]\n");
  knowledge.print("var_array = [{var_array}]\n");

  madara::knowledge::KnowledgeRecord::set_precision(10);

  knowledge.print("Setting precision to 10 and reprinting\n");
  knowledge.print("doubles_vector = [{doubles_vector}]\n");
  knowledge.print("integers_vector = [{integers_vector}]\n");
  knowledge.print("var_array = [{var_array}]\n");

  delete[] integer_array;
}