コード例 #1
0
ファイル: MotorInfo.java プロジェクト: OpenVnmrJ/OpenVnmrJ
  public void writePersistence() {
    StringBuffer sb = new StringBuffer();
    if (!m_minSWVersion.equalsIgnoreCase("0.0")) {
      sb.append("ReqSWVersion " + m_minSWVersion + NL);
    }
    sb.append("Steps/rev " + m_stepsPerRev + NL);
    if (m_indexDirection != 0) {
      sb.append("IndexDirection " + m_indexDirection + NL);
    }
    if (m_indexDistance != 0) {
      sb.append("IndexDistance " + m_indexDistance + NL);
    }
    sb.append("Limit " + m_minLimit + " " + m_maxLimit + NL);
    sb.append("Backlash " + getBacklash() + NL);

    if (!Double.isNaN(m_minBacklash)) {
      sb.append("BacklashLimits " + (int) m_minBacklash);
      if (!Double.isNaN(m_maxBacklash)) {
        sb.append(" " + (int) m_maxBacklash);
      }
      sb.append(NL);
    }

    sb.append("Odom " + m_odometerCW + " " + m_odometerCCW + NL);
    if (m_minCalStep != 0) {
      sb.append("MinCalStep " + m_minCalStep + NL);
    }

    String path = getPersistenceFilePath(false);
    TuneUtilities.writeFile(path, sb.toString());
  }
コード例 #2
0
ファイル: MotorInfo.java プロジェクト: OpenVnmrJ/OpenVnmrJ
  public boolean readPersistence(String path) {
    BufferedReader input = TuneUtilities.getReader(path);

    String line = null;
    boolean rtn = true;
    try {
      while ((line = input.readLine()) != null) {
        StringTokenizer toker = new StringTokenizer(line);
        if (toker.hasMoreTokens()) {
          String key = toker.nextToken().toLowerCase();
          if (key.equals("backlash")) {
            double backlash = Double.parseDouble(toker.nextToken());
            // backlash = Math.max(MIN_BACKLASH, backlash);/*CMP*/
            // backlash = Math.min(MAX_BACKLASH, backlash);/*CMP*/
            setBacklash(backlash);
            m_backlashGroup.clear();
            while (toker.hasMoreTokens()) {
              m_backlashGroup.add(new Integer(toker.nextToken()));
            }
          } else if (key.equals("backlashlimits")) {
            m_maxBacklash = Double.parseDouble(toker.nextToken());
            if (toker.hasMoreTokens()) {
              m_minBacklash = Double.parseDouble(toker.nextToken());
            }
          } else if (key.equals("steps/rev")) {
            m_stepsPerRev = Integer.parseInt(toker.nextToken());
          } else if (key.equals("limit")) {
            m_minLimit = Integer.parseInt(toker.nextToken());
            if (toker.hasMoreTokens()) {
              m_maxLimit = Integer.parseInt(toker.nextToken());
            }

          } else if (key.equals("odom")) {
            m_odometerCW = Long.parseLong(toker.nextToken());
            m_odometerCCW = Long.parseLong(toker.nextToken());

          } else if (key.equals("mincalstep")) {
            m_minCalStep = Integer.valueOf(toker.nextToken());
          } else if (key.equals("indexdirection")) {
            int dir = Integer.parseInt(toker.nextToken());
            m_indexDirection = dir > 0 ? 1 : -1;
          } else if (key.equals("indexdistance")) {
            m_indexDistance = Integer.parseInt(toker.nextToken());
          } else if (key.equals("reqswversion")) {
            // Verify version of software and persistence file
            m_minSWVersion = toker.nextToken();
            if (!ProbeTune.isSwVersionAtLeast(m_minSWVersion)) {
              String msg =
                  "Require software version "
                      + m_minSWVersion
                      + "<br>"
                      + " to operate on the file "
                      + path;
              Messages.postError(msg);
              String title = "Incompatible_Motor_File";
              m_master.sendToGui("popup error title " + title + " msg " + msg);
            }
          }
        }
      }
    } catch (NumberFormatException nfe) {
      Messages.postError("Bad number in persistence file: " + path + ", line: \"" + line + "\"");
      rtn = false;
    } catch (NoSuchElementException nsee) {
      Messages.postError("Bad line in persistence file: " + path + ", line: \"" + line + "\"");
      rtn = false;
    } catch (Exception e) {
      rtn = false;
    } finally {
      try {
        input.close();
      } catch (Exception e) {
      }
    }
    return rtn;
  }