RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package rlpark.plugin.irobot.robots; 00002 00003 import rlpark.plugin.irobot.data.IRobotLabels; 00004 import rlpark.plugin.irobot.internal.descriptors.CreateSerialDescriptor; 00005 import rlpark.plugin.irobot.internal.descriptors.DropDescriptors; 00006 import rlpark.plugin.irobot.internal.descriptors.IRobotCreateSerialConnection; 00007 import rlpark.plugin.irobot.internal.irobot.IRobotDiscoConnection; 00008 import rlpark.plugin.irobot.internal.server.IRobotDiscoServer; 00009 import rlpark.plugin.robot.observations.ObservationReceiver; 00010 00011 public class CreateRobot extends IRobotEnvironment { 00012 static public final double MaxAction = 500; 00013 static public final String SerialLinkFile = "/dev/cu.ElementSerial-ElementSe"; 00014 00015 public CreateRobot() { 00016 this(false); 00017 } 00018 00019 public CreateRobot(boolean persistent) { 00020 this("localhost", IRobotLabels.DiscoDefaultPort, persistent); 00021 } 00022 00023 public CreateRobot(String serialPortPath) { 00024 this(new IRobotCreateSerialConnection(serialPortPath, new CreateSerialDescriptor()), false); 00025 } 00026 00027 public CreateRobot(String localhost, int port, boolean persitent) { 00028 this(new IRobotDiscoConnection(localhost, port, DropDescriptors.newCreateSensorDrop()), persitent); 00029 } 00030 00031 private CreateRobot(ObservationReceiver receiver, boolean persistent) { 00032 super(receiver, persistent); 00033 } 00034 00035 @Override 00036 public void sendLeds(int powerColor, int powerIntensity, boolean play, boolean advance) { 00037 byte ledBits = 0; 00038 if (play) 00039 ledBits |= 2; 00040 if (advance) 00041 ledBits |= 8; 00042 sendMessage(new byte[] { (byte) 139, ledBits, (byte) powerColor, (byte) powerIntensity }); 00043 } 00044 00045 @Override 00046 protected void sendActionToRobot(double left, double right) { 00047 short shortLeft = toActionValue(MaxAction, left); 00048 short shortRight = toActionValue(MaxAction, right); 00049 sendMessage(new byte[] { (byte) 145, (byte) (shortRight >> 8), (byte) shortRight, (byte) (shortLeft >> 8), 00050 (byte) shortLeft }); 00051 } 00052 00053 @Override 00054 public void resetForCharging() { 00055 sendMessage(new byte[] { 7 }); 00056 } 00057 00058 public static void main(String[] args) { 00059 String serialLinkFile = args.length == 0 ? SerialLinkFile : args[0]; 00060 System.out.println("Opening " + serialLinkFile + "..."); 00061 IRobotDiscoServer.runServer(serialLinkFile, new CreateSerialDescriptor()); 00062 } 00063 }