Example #1
0
  protected Controller(
      Scenario myScenario,
      edu.berkeley.path.beats.jaxb.Controller jaxbC,
      Controller.Algorithm myType) {

    this.myScenario = myScenario;
    this.myType = myType;
    this.jaxbController = jaxbC;
    this.ison = false;
    //			this.activationTimes=new ArrayList<ActivationTimes>();
    this.dtinseconds = jaxbC.getDt() > 0 ? jaxbC.getDt() : myScenario.get.simdtinseconds();

    // Copy tables
    tables = new java.util.HashMap<String, Table>();
    for (edu.berkeley.path.beats.jaxb.Table table : jaxbC.getTable()) {
      if (tables.containsKey(table.getName()))
        BeatsErrorLog.addError("Table '" + table.getName() + "' already exists");
      tables.put(table.getName(), new Table(table));
    }

    //			// Get activation times and sort
    //			if (jaxbC.getActivationIntervals()!=null)
    //				for (edu.berkeley.path.beats.jaxb.Interval tinterval :
    // jaxbC.getActivationIntervals().getInterval())
    //					if(tinterval!=null)
    //						activationTimes.add(new
    // ActivationTimes(tinterval.getStartTime(),tinterval.getEndTime()));
    //			Collections.sort(activationTimes);

    // below this does not apply for scenario-less controllers  ..............................
    if (myScenario == null) return;

    samplesteps = BeatsMath.round(dtinseconds / myScenario.get.simdtinseconds());

    // read target actuators
    actuators = new ArrayList<Actuator>();
    actuator_usage = new ArrayList<String>();
    if (jaxbC.getTargetActuators() != null
        && jaxbC.getTargetActuators().getTargetActuator() != null) {
      for (TargetActuator ta : jaxbC.getTargetActuators().getTargetActuator()) {
        Actuator act = myScenario.get.actuatorWithId(ta.getId());
        actuators.add(act);
        act.setMyController(this);
        actuator_usage.add(ta.getUsage() == null ? "" : ta.getUsage());
      }
    }

    // read feedback sensors
    sensors = new ArrayList<Sensor>();
    sensor_usage = new ArrayList<String>();
    if (jaxbC.getFeedbackSensors() != null
        && jaxbC.getFeedbackSensors().getFeedbackSensor() != null) {
      for (FeedbackSensor fs : jaxbC.getFeedbackSensors().getFeedbackSensor()) {
        sensors.add(getMyScenario().get.sensorWithId(fs.getId()));
        sensor_usage.add(fs.getUsage() == null ? "" : fs.getUsage());
      }
    }
  }
Example #2
0
 /**
  * Retrieves a table with the given name
  *
  * @param jaxb_controller a controller to get a table from
  * @param name the table name
  * @return null, if a table with the given name was not found
  */
 protected static Table findTable(
     edu.berkeley.path.beats.jaxb.Controller jaxb_controller, String name) {
   Table table = null;
   for (edu.berkeley.path.beats.jaxb.Table jaxb_table : jaxb_controller.getTable())
     if (name.equals(jaxb_table.getName())) {
       if (null == table) table = new Table(jaxb_table);
       else
         logger.error(
             "Controller " + jaxb_controller.getId() + ": duplicate table '" + name + "'");
     }
   return table;
 }