Skip to content

Commit

Permalink
Merge pull request #15 from cornell-cup/sensor_base
Browse files Browse the repository at this point in the history
Sensor base
  • Loading branch information
TrevorEdwards committed Apr 15, 2017
2 parents e554f5f + 883385a commit 69e7b51
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 197 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ target/
out/
__pycache__/
received.py
temp.py
*.iml
58 changes: 58 additions & 0 deletions cs-minibot-platform.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/jaw.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/XboxController.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="Maven: org.jbox2d:jbox2d-library:2.2.1.1" level="project" />
<orderEntry type="module" module-name="cs-base-station-interface" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.5" level="project" />
<orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.5" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.13" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.3.6.v20151106" level="project" />
<orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-http:9.3.6.v20151106" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:9.3.6.v20151106" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:9.3.6.v20151106" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-webapp:9.3.6.v20151106" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-xml:9.3.6.v20151106" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-servlet:9.3.6.v20151106" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-security:9.3.6.v20151106" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-server:9.3.6.v20151106" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-common:9.3.6.v20151106" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-client:9.3.6.v20151106" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-servlet:9.3.6.v20151106" level="project" />
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-api:9.3.6.v20151106" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.7" level="project" />
<orderEntry type="library" name="Maven: com.zeroc:ice:3.6.3" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.21" level="project" />
<orderEntry type="library" name="Maven: com.sparkjava:spark-template-velocity:2.3" level="project" />
<orderEntry type="library" name="Maven: org.apache.velocity:velocity:1.7" level="project" />
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.4" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import os
from os import sys, path
sys.path.append(os.path.dirname('../src/received/'))
sys.path.append(os.path.join('../src/received/sensor/'))
#sys.path.append(os.path.join(os.path.dirname('../src/received/'), '..'))
from sensor import Sensor
from cup_minibot_prepend import CupMiniBot
from .sensor.Sensor import Sensor

bot = CupMiniBot()
left = Sensor(bot, 'left')
right = Sensor(bot, 'right')
Expand All @@ -13,7 +19,7 @@
while(center.read() != 1):
if(left.read() == 1):
bot.turn_clockwise(100)
else if(right.read() == 1):
elif(right.read() == 1):
bot.turn_counter_clockwise(100)
else:
end = True
Expand Down
Binary file added python-interface/example-scripts/testcommand.pyc
Binary file not shown.
7 changes: 5 additions & 2 deletions python-interface/src/received/cup_minibot_prepend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from .sensor.Sensor import Sensor
from .sensor.GPIOSensor import GPIOSensor
import os
from os import sys, path
sys.path.append(os.path.join(os.path.dirname('sensor'), '..'))
from sensor import Sensor
from sensor import GPIOSensor


class CupMiniBot:
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion python-interface/src/received/sensor/GPIOSensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Needs to be updated to actually work, fake for now!
# Abstract class representing the sensor interface

from .Sensor import Sensor
from sensor import Sensor

class GPIOSensor(Sensor):
def __init__(self, bot, name, pin_number):
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions python-interface/src/received/sensor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from sensor import Sensor
Binary file added python-interface/src/received/sensor/__init__.pyc
Binary file not shown.
Binary file added python-interface/src/received/sensor/sensor.pyc
Binary file not shown.
Binary file added python-interface/src/tcp.pyc
Binary file not shown.
168 changes: 0 additions & 168 deletions script.py

This file was deleted.

18 changes: 11 additions & 7 deletions src/main/java/minibot/BaseHTTPInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,23 @@ public static void main(String[] args) {
}
else {
SimBotConnection sbc = new SimBotConnection();
PhysicalObject po = new PhysicalObject("simbot", 50, simvs.getWorld(), 0.0f, 0.0f, 1f, 3.6f, true);
SimBot simbot;
simbot = new SimBot(sbc, name, po);
newBot = simbot;

PhysicalObject po = new PhysicalObject("TESTBOT", 50, simvs.getWorld(), 0.4f, 0.0f, 1f, 1f, true);
SimBot smbot;
smbot = new SimBot(sbc, name, po);
newBot = smbot;


ArrayList<PhysicalObject> pObjs = new ArrayList<>();
pObjs.add(po);
simvs.processPhysicalObjects(pObjs);

// Color sensor TODO put somewhere nice
ColorIntensitySensor colorSensorL = new ColorIntensitySensor((SimBotSensorCenter) simbot.getSensorCenter(),"right",simbot, 5);
ColorIntensitySensor colorSensorR = new ColorIntensitySensor((SimBotSensorCenter) simbot.getSensorCenter(),"left",simbot, -5);
ColorIntensitySensor colorSensorM = new ColorIntensitySensor((SimBotSensorCenter) simbot.getSensorCenter(),"center",simbot, 0);

ColorIntensitySensor colorSensorL = new ColorIntensitySensor((SimBotSensorCenter) smbot.getSensorCenter(),"right",smbot, 7);
ColorIntensitySensor colorSensorR = new ColorIntensitySensor((SimBotSensorCenter) smbot.getSensorCenter(),"left",smbot, -7);
ColorIntensitySensor colorSensorM = new ColorIntensitySensor((SimBotSensorCenter) smbot.getSensorCenter(),"center",smbot, 0);

}

return BaseStation.getInstance().getBotManager().addBot(newBot);
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/simulator/simbot/SimBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void run() {
if (!content.contains("WHEELS") && !content.contains("REGISTER") && !content.contains("GET")) {
value = Double.parseDouble(content.substring(content.indexOf(':') + 1));
}
String name = content.substring(content.indexOf(':') + 1);
switch (content.substring(0, content.indexOf(':'))) {
case "FORWARD":
//fl fr bl br
Expand Down Expand Up @@ -118,7 +119,6 @@ public void run() {
System.out.println("Exiting\n");
break;
case "GET":
String name = content.substring(content.indexOf(':') + 1);
if (name.equals("ALL")) {
out.println(this.sensorCenter.getAllDataGson());
} else {
Expand All @@ -132,19 +132,15 @@ public void run() {
System.out.println("Added New sensor");
break;
default:
String cmd = content.substring(content.indexOf(':') + 1);
System.out.println(cmd);
String[] wheel_cmds = cmd.split(",");


System.out.println(name);
String[] wheel_cmds = name.split(",");
this.commandCenter.setWheelPower(
Double.parseDouble(wheel_cmds[0]),
Double.parseDouble(wheel_cmds[1]),
Double.parseDouble(wheel_cmds[2]),
Double.parseDouble(wheel_cmds[3])
);
break;

}
}
}
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/simulator/simbot/SimBotCommandCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,22 @@ public boolean sendKV(String key, String value) {
}

String prg = value;
BufferedWriter out = new BufferedWriter(new FileWriter("script.py"));
out.write(header);
out.write(prg);
out.close();
BufferedWriter scriptOut = new BufferedWriter(new FileWriter("temp.py"));
scriptOut.write(header);
scriptOut.write(prg);
scriptOut.close();

ProcessBuilder pb = new ProcessBuilder("python","script.py");
ProcessBuilder pb = new ProcessBuilder("python","temp.py");
Process p = pb.start();

BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader scriptFeedbackInStream = new BufferedReader(new InputStreamReader(p.getInputStream()));


String ret;
String line;
while ((line = in.readLine()) != null) {
ret = new String(line);
System.out.println(ret);
while ((line = scriptFeedbackInStream.readLine()) != null) {
int ret = new Integer(line).intValue();
System.out.println("" + ret);

}
}catch(Exception e){
System.out.println(e);
Expand Down

0 comments on commit 69e7b51

Please sign in to comment.