Configuration.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
00015  */
00016 
00017 package com.github.rosjava.rosjava_extras.hokuyo.scip20;
00018 
00019 import com.google.common.annotations.VisibleForTesting;
00020 import com.google.common.base.Preconditions;
00021 
00022 import com.github.rosjava.rosjava_extras.hokuyo.LaserScannerConfiguration;
00023 
00024 
00025 
00026 
00030 public class Configuration implements LaserScannerConfiguration {
00031 
00032   private String model;
00033   private int minimumMeasurment; // mm
00034   private int maximumMeasurement; // mm
00035   private int totalSteps; // in 360 range
00036   private int firstStep; // first step in measurement range
00037   private int lastStep; // last step in measurement range
00038   private int frontStep; // step number on the sensor's front axis
00039   private int standardMotorSpeed; // RPM
00040 
00041   public static class Builder {
00042 
00043     private Configuration configuration;
00044 
00045     public Builder() {
00046       configuration = new Configuration();
00047     }
00048 
00049     public LaserScannerConfiguration build() {
00050       return configuration;
00051     }
00052 
00053     @VisibleForTesting
00054     int parseIntegerValue(String tag, String buffer) {
00055       Preconditions.checkArgument(buffer.startsWith(tag + ":"));
00056       return Integer.valueOf(buffer.substring(5, buffer.length()));
00057     }
00058 
00059     public Builder parseModel(String buffer) {
00060       Preconditions.checkArgument(buffer.startsWith("MODL:"));
00061       configuration.model = buffer.substring(5, buffer.length() - 1);
00062       return this;
00063     }
00064 
00065     public Builder parseMinimumMeasurement(String buffer) {
00066       configuration.minimumMeasurment = parseIntegerValue("DMIN", buffer);
00067       return this;
00068     }
00069 
00070     public Builder parseMaximumMeasurement(String buffer) {
00071       configuration.maximumMeasurement = parseIntegerValue("DMAX", buffer);
00072       return this;
00073     }
00074 
00075     public Builder parseTotalSteps(String buffer) {
00076       configuration.totalSteps = parseIntegerValue("ARES", buffer);
00077       return this;
00078     }
00079 
00080     public Builder parseFirstStep(String buffer) {
00081       configuration.firstStep = parseIntegerValue("AMIN", buffer);
00082       return this;
00083     }
00084 
00085     public Builder parseLastStep(String buffer) {
00086       configuration.lastStep = parseIntegerValue("AMAX", buffer);
00087       return this;
00088     }
00089 
00090     public Builder parseFrontStep(String buffer) {
00091       configuration.frontStep = parseIntegerValue("AFRT", buffer);
00092       return this;
00093     }
00094 
00095     public Builder parseStandardMotorSpeed(String buffer) {
00096       configuration.standardMotorSpeed = parseIntegerValue("SCAN", buffer);
00097       return this;
00098     }
00099   }
00100 
00101   private Configuration() {
00102     // Use the Configuration.Builder to construct a Configuration object.
00103   }
00104 
00108   @Override
00109   public String getModel() {
00110     return model;
00111   }
00112 
00116   @Override
00117   public int getMinimumMeasurment() {
00118     return minimumMeasurment;
00119   }
00120 
00124   @Override
00125   public int getMaximumMeasurement() {
00126     return maximumMeasurement;
00127   }
00128 
00132   @Override
00133   public int getTotalSteps() {
00134     return totalSteps;
00135   }
00136 
00144   @Override
00145   public int getFirstStep() {
00146     return firstStep;
00147   }
00148 
00156   @Override
00157   public int getLastStep() {
00158     return lastStep;
00159   }
00160 
00167   @Override
00168   public int getFrontStep() {
00169     return frontStep;
00170   }
00171 
00175   @Override
00176   public int getStandardMotorSpeed() {
00177     return standardMotorSpeed;
00178   }
00179 
00184   @Override
00185   public float getAngleIncrement() {
00186     return (float) ((2.0 * Math.PI) / getTotalSteps());
00187   }
00188 
00192   @Override
00193   public float getMinimumAngle() {
00194     return (getFirstStep() - getFrontStep()) * getAngleIncrement();
00195   }
00196 
00200   @Override
00201   public float getMaximumAngle() {
00202     return (getLastStep() - getFrontStep()) * getAngleIncrement();
00203   }
00204 
00208   @Override
00209   public float getTimeIncrement() {
00210     return (float) (60.0 / ((double) getStandardMotorSpeed() * getTotalSteps()));
00211   }
00212 
00216   @Override
00217   public float getScanTime() {
00218     return (float) (60.0 / (double) getStandardMotorSpeed());
00219   }
00220 
00221   @Override
00222   public String toString() {
00223     return String
00224         .format(
00225             "MODL: %s\nDMIN: %d\nDMAX: %d\nARES: %d\nAMIN: %d\nAMAX: %d\nAFRT: %d\nSCAN: %d",
00226             getModel(), getMinimumMeasurment(), getMaximumMeasurement(),
00227             getTotalSteps(), getFirstStep(), getLastStep(), getFrontStep(),
00228             getStandardMotorSpeed());
00229   }
00230 }


rosjava_extras
Author(s): Damon Kohler
autogenerated on Thu Aug 27 2015 14:53:42