RLPark 1.0.0
Reinforcement Learning Framework in Java

CritterbotObservation.java

Go to the documentation of this file.
00001 package rlpark.plugin.critterbot.data;
00002 
00003 import java.io.Serializable;
00004 
00005 import rlpark.plugin.rltoys.envio.observations.Legend;
00006 import zephyr.plugin.core.api.monitoring.annotations.Monitor;
00007 
00008 @Monitor
00009 public class CritterbotObservation implements Serializable {
00010   private static final long serialVersionUID = -2034233010499765404L;
00011   public final int[] motorTemperature = new int[CritterbotLabels.NbMotors];
00012   public final int[] motorCurrent = new int[CritterbotLabels.NbMotors];
00013   public final int[] motorSpeed = new int[CritterbotLabels.NbMotors];
00014   public final int[] motorCommand = new int[CritterbotLabels.NbMotors];
00015   public final int[] thermal = new int[CritterbotLabels.NbThermal];
00016   public final int[] light = new int[CritterbotLabels.NbLight];
00017   public final int[] irLight = new int[CritterbotLabels.NbIRLight];
00018   public final int[] irDistance = new int[CritterbotLabels.NbIRDistance];
00019   public final int[] bat = new int[CritterbotLabels.NbBatteries];
00020   public final int rotationVel;
00021   public final int magX;
00022   public final int magY;
00023   public final int magZ;
00024   public final int accelX;
00025   public final int accelY;
00026   public final int accelZ;
00027   public final int busVoltage;
00028   public final int powerSource;
00029   public final int chargeState;
00030   public final int dataSource;
00031   public final long time;
00032 
00033   public CritterbotObservation(Legend legend, long time, double[] o) {
00034     this.time = time;
00035     rotationVel = valueOf(legend, o, CritterbotLabels.RotationVel);
00036     magX = valueOf(legend, o, CritterbotLabels.Mag + "X");
00037     magY = valueOf(legend, o, CritterbotLabels.Mag + "Y");
00038     magZ = valueOf(legend, o, CritterbotLabels.Mag + "Z");
00039     accelX = valueOf(legend, o, CritterbotLabels.Accel + "X");
00040     accelY = valueOf(legend, o, CritterbotLabels.Accel + "Y");
00041     accelZ = valueOf(legend, o, CritterbotLabels.Accel + "Z");
00042     busVoltage = valueOf(legend, o, CritterbotLabels.BusVoltage);
00043     powerSource = valueOf(legend, o, CritterbotLabels.PowerSource);
00044     chargeState = valueOf(legend, o, CritterbotLabels.ChargeState);
00045     dataSource = valueOf(legend, o, CritterbotLabels.DataSource);
00046 
00047     fillMotor(legend, o, CritterbotLabels.Temperature, motorTemperature);
00048     fillMotor(legend, o, CritterbotLabels.Current, motorCurrent);
00049     fillMotor(legend, o, CritterbotLabels.Speed, motorSpeed);
00050     fillMotor(legend, o, CritterbotLabels.Command, motorCommand);
00051     fill(legend, o, CritterbotLabels.Thermal, thermal);
00052     fill(legend, o, CritterbotLabels.Light, light);
00053     fill(legend, o, CritterbotLabels.IRLight, irLight);
00054     fill(legend, o, CritterbotLabels.IRDistance, irDistance);
00055     fill(legend, o, CritterbotLabels.Bat, bat);
00056   }
00057 
00058   private int valueOf(Legend legend, double[] o, String label) {
00059     int index = legend.indexOf(label);
00060     return index >= 0 ? (int) o[index] : 0;
00061   }
00062 
00063   private void fill(Legend legend, double[] o, String prefix, int[] result) {
00064     for (int i = 0; i < result.length; i++)
00065       result[i] = (int) o[legend.indexOf(prefix + i)];
00066   }
00067 
00068   private void fillMotor(Legend legend, double[] o, String prefix, int[] result) {
00069     for (int i = 0; i < result.length; i++)
00070       result[i] = (int) o[legend.indexOf(CritterbotLabels.Motor + prefix + i)];
00071   }
00072 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark