コード例 #1
0
ファイル: FuzzyCommunication.java プロジェクト: jvitku/logic
  @Test
  public void fuzzyNOT() {

    RosRunner gate = runNode("org.hanns.logic.fuzzy.gates.impl.NOT");

    RosRunner rr = runNode("org.hanns.logic.fuzzy.gates.SisoFuzzyGateTester");
    NodeMain node = rr.getNode();
    SisoFuzzyGateTester mt = null;
    if (node instanceof SisoFuzzyGateTester) {
      mt = (SisoFuzzyGateTester) node;
    } else {
      fail(
          "Launched node SisoFuzzyGateTester, but found this one!: "
              + node.getClass().getCanonicalName());
    }
    assertTrue(gate.isRunning());
    assertTrue(rr.isRunning());

    ArrayList<Float> receivedData = new ArrayList<Float>();
    ArrayList<Float> sentData = new ArrayList<Float>(50);

    appendRandomFloatData(sentData, 30, -1);
    appendRandomFloatData(sentData, 10, 5);
    appendRandomFloatData(sentData, 5, 100);

    for (int i = 0; i < sentData.size(); i++) {
      receivedData.add(mt.computeRemotely(sentData.get(i)));
    }

    assertEquals(sentData.size(), receivedData.size());

    FuzzyLogic l = new FuzzyLogic(2);

    for (int i = 0; i < sentData.size(); i++) {
      System.out.println(
          "checking no."
              + i
              + " of: "
              + sentData.size()
              + " => operation("
              + sentData.get(i)
              + " == "
              + receivedData.get(i));
      assertTrue(receivedData.get(i) == l.compute(sentData.get(i), 0));
    }

    // after switching these two lines, core throws warning "no publisher for topic.."
    rr.stop();
    gate.stop();

    assertFalse(gate.isRunning());
    assertFalse(rr.isRunning());
  }
コード例 #2
0
ファイル: FuzzyCommunication.java プロジェクト: jvitku/logic
  /**
   * check if all results are consistent with the chosen logical operation
   *
   * @param l
   * @param sentData
   * @param receivedData
   */
  private void testOperations(
      FuzzyLogic l, ArrayList<Float[]> sentData, ArrayList<Float> receivedData) {

    for (int i = 0; i < sentData.size(); i++) {
      System.out.println(
          "checking no."
              + i
              + " of: "
              + sentData.size()
              + " => operation("
              + sentData.get(i)[0]
              + ","
              + sentData.get(i)[1]
              + ") == "
              + receivedData.get(i));
      assertTrue(receivedData.get(i) == l.compute(sentData.get(i)[0], sentData.get(i)[1]));
    }
  }