Пример #1
0
/// Tests logicals operators (&&, ||)
void write_transported_arrays(madara::knowledge::KnowledgeBase& knowledge)
{
  knowledge.print("\nReceived the following arrays from id 0\n");
  knowledge.print("doubles_vector = [{doubles_vector}]\n");
  knowledge.print("integers_vector = [{integers_vector}]\n");
  knowledge.print("var_array = [{var_array}]\n\n");

  madara::knowledge::KnowledgeRecord doubles_vector =
      knowledge.get("doubles_vector");
  doubles_vector.set_index(5, 127.25);
  doubles_vector.set_index(6, 1.2575);

  std::cerr << "adding two doubles (127.25, 1.2575) to the doubles_vector\n";
  std::cerr << "doubles_vector = [" << doubles_vector.to_string(", ") << "]"
            << std::endl;

  madara::knowledge::KnowledgeRecord integers_vector =
      knowledge.get("integers_vector");

  std::cerr << "\nintegers_vector = [" << integers_vector.to_string(", ") << "]"
            << std::endl;

  integers_vector.set_index(7, madara::knowledge::KnowledgeRecord::Integer(7));

  std::cerr << "adding one integer (7) to the integers_vector\n";

  std::cerr << "integers_vector = [" << integers_vector.to_string(", ") << "]"
            << std::endl;

  std::cerr << "adding one double (6.0) to the integers_vector\n";

  integers_vector.set_index(6, 6.0);

  std::cerr << "integers_vector = [" << integers_vector.to_string(", ")
            << "]\n\n";

  knowledge.print("var_array = [{var_array}]\n");
  std::cerr << "copying elements of var_array to var_array\n";

#ifndef _MADARA_NO_KARL_
  knowledge.evaluate(
      "var_array[0] = var_array[3]", madara::knowledge::EvalSettings::SEND);
  knowledge.evaluate(
      "var_array[2] = var_array[1]", madara::knowledge::EvalSettings::SEND);
  knowledge.evaluate(
      "var_array[8] = 100.012", madara::knowledge::EvalSettings::SEND);
#else
  knowledge.set_index("var_array", 0,
      knowledge.retrieve_index("var_array", 3).to_double(),
      madara::knowledge::EvalSettings::SEND);
  knowledge.set_index("var_array", 2,
      knowledge.retrieve_index("var_array", 1).to_double(),
      madara::knowledge::EvalSettings::SEND);
  knowledge.set_index(
      "var_array", 8, 100.012, madara::knowledge::EvalSettings::SEND);
#endif  // _MADARA_NO_KARL_

  knowledge.print("var_array = [{var_array}]\n\n");
}
Пример #2
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;
}