From 0f7cfce1f6253cd46e582e0e2cf6c35e56ef9901 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Thu, 30 Mar 2017 00:26:49 -0400 Subject: [PATCH 1/3] Fix compile error line follower --- .../src/received/cup_minibot_prepend.py | 7 +++++-- .../src/received/cup_minibot_prepend.pyc | Bin 0 -> 5699 bytes python-interface/src/received/line_follower.py | 11 ++++++----- .../src/received/sensor/GPIOSensor.py | 2 +- .../src/received/sensor/GPIOSensor.pyc | Bin 0 -> 1140 bytes python-interface/src/received/sensor/__init__.py | 1 + .../src/received/sensor/__init__.pyc | Bin 0 -> 279 bytes python-interface/src/received/sensor/sensor.pyc | Bin 0 -> 614 bytes 8 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 python-interface/src/received/cup_minibot_prepend.pyc create mode 100644 python-interface/src/received/sensor/GPIOSensor.pyc create mode 100644 python-interface/src/received/sensor/__init__.pyc create mode 100644 python-interface/src/received/sensor/sensor.pyc diff --git a/python-interface/src/received/cup_minibot_prepend.py b/python-interface/src/received/cup_minibot_prepend.py index 23e6223..f29a824 100644 --- a/python-interface/src/received/cup_minibot_prepend.py +++ b/python-interface/src/received/cup_minibot_prepend.py @@ -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: diff --git a/python-interface/src/received/cup_minibot_prepend.pyc b/python-interface/src/received/cup_minibot_prepend.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a4341ad8d7d0b138039312cd003a24eec1bb49c3 GIT binary patch literal 5699 zcmds5-EJF26rPP;$4(k36a@+@3>OFkO`L)Nsj5(EDzz1AfOV>Z1zN3l$ML57*PU_F zKzf1NdmakJ9dE!bPrw7fch0PL-I4~iR}PkU_RQ?;?0nxjGv}OX{I#<5}2{*H)+NE|V6M6w_T3&K&3*j*624WUprXUbC|To4bP`tQ&H4H36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c76 100644 --- a/python-interface/src/received/line_follower.py +++ b/python-interface/src/received/line_follower.py @@ -1,12 +1,13 @@ from cup_minibot_prepend import CupMiniBot -from .sensor.Sensor import Sensor +import os +from os import sys, path +sys.path.append(os.path.join(os.path.dirname('sensor'), '..')) +from sensor import Sensor + bot = CupMiniBot() left = Sensor(bot, 'left') right = Sensor(bot, 'right') center = Sensor(bot, 'center') -# redundant? bot.register_sensor(left) -# redundant? bot.register_sensor(right) -# redundant? bot.register_sensor(center) end = False while(not end): @@ -16,7 +17,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 diff --git a/python-interface/src/received/sensor/GPIOSensor.py b/python-interface/src/received/sensor/GPIOSensor.py index f8160e4..80ef180 100644 --- a/python-interface/src/received/sensor/GPIOSensor.py +++ b/python-interface/src/received/sensor/GPIOSensor.py @@ -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): diff --git a/python-interface/src/received/sensor/GPIOSensor.pyc b/python-interface/src/received/sensor/GPIOSensor.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a1efee614d6de57a9507903aecc15dfb4024c947 GIT binary patch literal 1140 zcmd5+O-sZu5S_H^Cklc$Pacb~Mm^|7R9r#4sB{t3OIXuctu|>%vckgN^y)wK;D7K3 z=uGOzU)ZwqI%!`g^X9diel9OQzrJ5<_&HKKA5r)Xf`WbmDgYzkR)8oHKmkJmMGCI~ zF90{U2^1aZXEQ`Ezv##WWnq?}kJi^NEK+)Ud3Mn*|2AUUF@;|vK;Zhc9aZIuA|@&1 z{Vbu|xyrU@c~ literal 0 HcmV?d00001 diff --git a/python-interface/src/received/sensor/__init__.py b/python-interface/src/received/sensor/__init__.py index e69de29..07281d4 100644 --- a/python-interface/src/received/sensor/__init__.py +++ b/python-interface/src/received/sensor/__init__.py @@ -0,0 +1 @@ +from sensor import Sensor diff --git a/python-interface/src/received/sensor/__init__.pyc b/python-interface/src/received/sensor/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..78cd8f13c5baf24d159cc44aaaec2c520d3d653c GIT binary patch literal 279 zcmY*UOKJi^5bahF5wgo6W;0geBH4r>jB6JT0m-J(?i%c*KSNiK;0*+?=q+*ptuY~B zQT6Kg3SJF=9wzp9UTg7Z1I}{}dSo!{QaB;J6rWN^GZ1w#}>v{9hbPnJ9 Ihp5+k1se-X+5i9m literal 0 HcmV?d00001 diff --git a/python-interface/src/received/sensor/sensor.pyc b/python-interface/src/received/sensor/sensor.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5a218d88d67ef415c9e9eb1f5e91ef6a9bc70a43 GIT binary patch literal 614 zcma)3u};G<5IrZQ&`Jo21&JvW%2alQ5YUOGgR?*uD@{xllqM)=kdV5Sf8fjb5+=63 zvkOcJqTKn;=lAaU9DnSO-#*`OOWJ-h)=L;4!BzNUsuaBvt%>e()2x?^z#<(%|jahcpQ-f6RAl33jKm0!W<>neE{Y&^857lTe3qY?^ RivQ#B6Fd(pE<`H}b_3oMY8n6l literal 0 HcmV?d00001 From 1c930dbfc4fbe9d50c3470170b06dca4af4c61e5 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Thu, 30 Mar 2017 00:48:30 -0400 Subject: [PATCH 2/3] These file path bugs were so fking annoying holy sh1t --- .../line_follower.py | 6 ++++-- .../example-scripts/testcommand.pyc | Bin 0 -> 421 bytes .../src/received/cup_minibot_prepend.pyc | Bin 5699 -> 4485 bytes python-interface/src/tcp.pyc | Bin 0 -> 4328 bytes 4 files changed, 4 insertions(+), 2 deletions(-) rename python-interface/{src/received => example-scripts}/line_follower.py (74%) create mode 100644 python-interface/example-scripts/testcommand.pyc create mode 100644 python-interface/src/tcp.pyc diff --git a/python-interface/src/received/line_follower.py b/python-interface/example-scripts/line_follower.py similarity index 74% rename from python-interface/src/received/line_follower.py rename to python-interface/example-scripts/line_follower.py index ab41c76..e4c6747 100644 --- a/python-interface/src/received/line_follower.py +++ b/python-interface/example-scripts/line_follower.py @@ -1,8 +1,10 @@ -from cup_minibot_prepend import CupMiniBot import os from os import sys, path -sys.path.append(os.path.join(os.path.dirname('sensor'), '..')) +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 bot = CupMiniBot() left = Sensor(bot, 'left') diff --git a/python-interface/example-scripts/testcommand.pyc b/python-interface/example-scripts/testcommand.pyc new file mode 100644 index 0000000000000000000000000000000000000000..74b5c418283745d0aec6d69be11fc065fbbbcc93 GIT binary patch literal 421 zcmYLFOHKnZ49!eGKt=B{LK*@^f(=4QWzD8VLM#}iiAzKCQ{qy(X2-QS5(fZhN{f>` zKR-E+ozC}gaPj>0DA}Kt)MVEr33b060tDjZTqE6jvk zw#reyxQebZFh?BhqNraMh+PWTLSsdq{X_bskUu1diN9)VH*x`v-$7cU4}9#S17n)e z+4*HnaMetJx>DpUB!sxn7_S1CskYkbna4U9fz+twVS@|rYMKDzTu9*XE^IJRCmD6X f#F6SqZ>@0Zl#&mroonmW%D_$jqm;)O6ub2c9^-3S literal 0 HcmV?d00001 diff --git a/python-interface/src/received/cup_minibot_prepend.pyc b/python-interface/src/received/cup_minibot_prepend.pyc index a4341ad8d7d0b138039312cd003a24eec1bb49c3..d8ad73a926381bc8f8cc086e846bb1a848b92d4a 100644 GIT binary patch delta 1293 zcmbtTJ#5oJ6n^J8{%d}mq@-yH{|u2*B>^Fossrr;3PJ=NA%PcU;uAO|ab%k!rVIgz zh3SOE&ceWgBC#@bWM?W2tk9_o8{9j$WK5%4_IK}|?!No{y>~mSuP%%d`)T9b>)rbu zICx|}Zt^dD!@=b*fgXSz#}dYU0ycrZ1hxc(66i|MO#lTE$cI4^+ysmXxH60-3<#1X zp{GD!1zU~hB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CNe`IP?qF-p%S|1-v|5{NaK)Y>30A7&XP}tgrtQK~c30^c8$KIb?Qy)4&U1 z3B2?ESgBY`AOBeo&VHKQw1nfvZC&0Rp$GS_#?`qBqEUocEzA&1qzEL`{YaY&GarKk zLk)2Sze*lG+DQ@Vh3o$cCGgGEc(EFpI%Wt}jKBy(WIX0fm&d14MkDrl5$%lsYYf}x z$U$fmK7JZ?kEaiC{3LjUBj@m}(a=R0!xOtC^lfODw3J(=gTQyf3)BCWb%x zq9)fYS5=;)AsgQ)QgcFp{G{qx+NR+s`G~Gn$1R&FQc_}~L~*pL zW2N#snlY5@m^r7M0PKUFE4W*pTUDY)^JktZ=0TRW%TzxU;Fum+3S2TwPKWpWc%p2w z#)dlQ$jR7tU~E2e#4^#mfhJ2rov&5KM(fOyfX)2elma4xDVWhaahm#xnsWkP#x#il z3*H+Zcr@uR&^qOSz%_6YAU1@LAs}Oa;E4O(l8kHLpBE3{+SokcOCF?X*( zAXY3q$2Cz%KyPXIl9aCX_6#Ak$769=o#2Ut#L8fU-$2P}~lv;Y7A diff --git a/python-interface/src/tcp.pyc b/python-interface/src/tcp.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9d6354a01fcbd9d949d41abf1c10cdc04370b393 GIT binary patch literal 4328 zcma)9&2JmW6@Rn*kVuh|Y}rwirZHUyC~c^c-5in>hFiyxKiWn$Rsv)QF^Cm+M6X2d zQah^;8`2?gd+WVlK<~Zx(nIe32YS!ZJ@nLGdTM{aH>4y71u9A$zIpRz=6%06rGGZ- zzxnsyo^@sPso?h~__}{!i1BZvFS1T3kiL;kqgcR!YzAYvB%7r%T$au97_P`>Md1?n z4yv+Q6~nX2(w~sQq-;+5d4=ZG2IEAfm1m&9I{cvf};$^S0)k`#4$ZN#K1+gkfFBu@T= zPul=0INVzG@C4wedDgYgc|;Y6^%uE~Vn3(aT;JMZ!IdJ)d$uUb00Ft=O-V#G%rgUg zAK>e*V1Rn5SCN6piKs5t+Mt%zbDT_Kp4+ZX4y?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Ud(du;2VN?4W^%&-99pY4;@ zG_6B^jtdLcYY#3Y(szZPxvK+MqFc^cYVW zbUsI`imMy6Kx|;}plOix9W)(+nykGMS;kSP0(~v$=DERV5`WU(*Mk3zy+4gSf(doi zar8N`rR}qgeVx_h&bs9bDjx@*SwupT_F552Ay;O<4+Aid-udCjOSkcNM;*z%3)DuG z6r|lo{p@CGYP&^}rS7_$!{UQeL@Vlc@k+9Bcm?=`L8N`F2J$7K!cQ=0CFt8Uq%UbH z!aM5V%mYIns`&MM-}-u!b$9XRqTAnp*m<(LvW^x5qW1`< zTmk1M=vmTbl;;D*#gIL=npO0PqSY>Z2x@&rIh!BY{Aq^g2OZK+*E|c_a`@-fnIcAO zbmb_HbLDfCXD*zexOosI=@D2PE6dsH+L(uNYt~z WcS^N#ZK_tOeOhbQrfcstO8*5i>oQyb literal 0 HcmV?d00001 From 2a970bfc0204611d2f20005a80b201dadd58f916 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Fri, 14 Apr 2017 22:57:53 -0400 Subject: [PATCH 3/3] janitor #15 --- .gitignore | 1 + script.py | 163 ------------------ src/main/java/minibot/BaseHTTPInterface.java | 12 +- src/main/java/simulator/simbot/SimBot.java | 10 +- .../simulator/simbot/SimBotCommandCenter.java | 17 +- 5 files changed, 18 insertions(+), 185 deletions(-) delete mode 100644 script.py diff --git a/.gitignore b/.gitignore index 274c5a6..2c5673f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ target/ out/ __pycache__/ received.py +temp.py diff --git a/script.py b/script.py deleted file mode 100644 index 1c4d39d..0000000 --- a/script.py +++ /dev/null @@ -1,163 +0,0 @@ -import socket -import sys -import time - -HOST = "localhost" -PORT = 11111 - -sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - -class BaseMiniBot: - """ - Abstract class defining the base functions of the MiniBot. More customized MiniBots may - subclass this. - """ - def __init__(self): - server_address = (HOST, PORT) - sock.connect(server_address) - - def move_forward(self, power): - """ - Moves the bot forward at a percentage of its full power - - :param power The percentage of the bot's power to use from 0-100 - :return True if the action is supported - """ - message = "FORWARD:" + str(power) + '\n' - sock.sendall(message) - return - - def move_backward(self, power): - """ - Moves the bot backward at a percentage of its full power - - :param power The percentage of the bot's power to use from 0-100 - :return True if the action is supported - """ - # print("Unimplemented: Moving backward "+str(power)) - message = "BACKWARD:" + str(power) + '\n' - sock.sendall(message) - return - - def turn_clockwise(self, power): - """ - Moves the bot clockwise at a percentage of its full power - - :param power The percentage of the bot's power to use from 0-100 - :return True if the action is supported - """ - # print("Unimplemented: Turning clockwise "+str(power)) - message = "RIGHT:" + str(power) + '\n' - sock.sendall(message) - return - - def turn_counter_clockwise(self, power): - """ - Moves the bot counter-clockwise at a percentage of its full power - - :param power The percentage of the bot's power to use from 0-100 - :return True if the action is supported - """ - # print("Unimplemented: Turning counter clockwise "+str(power)) - message = "LEFT:" + str(power) + '\n' - sock.sendall(message) - return - - def set_wheel_power(self, front_left, front_right, back_left, back_right): - """ - Sets the power of the bot's wheels as a percentage from -100 to 100. If a wheel - specified does not exist, the power for that wheel is ignored. - :param front_left power to deliver to the front_left wheel - :param front_right power to deliver to the front_right wheel - :param back_left power to deliver to the back_left wheel - :param back_right power to deliver to the back_right wheel - :return True if the action is supported - """ - # print("Unimplemented: Setting wheel power to %d,%d,%d,%d" % (front_left, front_right, back_left, back_right)) - message = "WHEELS:" + str(front_left) + ',' + str(front_right) + ',' + str(back_left) + ',' \ - + str(back_right) + '\n'; - sock.sendall(message) - return - - def wait(self, t): - """ - Waits for a duration in seconds. - :param t The duration in seconds - """ - message = "WAIT:" + str(t) + '\n' - sock.sendall(message) - time.sleep(t) - return - - def stop(self): - """ - Waits for a duration in seconds. - :param t The duration in seconds - """ - message = "STOP:0" + '\n' - sock.sendall(message) - return - - # def getSensorData(self): - # message = "GET:1" + '\n' - # sock.sendall(message) - # with open('output.txt', 'a') as file: - # file.write("Got: " + sock.recv(1024) + "\n") - # file.close() - # return - - def register_sensor(self, name): - message = "REGISTER:" + name + '\n' - sock.sendall(message) - return - - def kill(self): - """ - Kills TCP connection - """ - message = "KILL:-1" + '\n' - sock.sendall(message) - sock.close() - return - - -class Sensor: - def __init__(self, bot, name): - self.name = name - bot.register_sensor(name) - - def read(self): - return "Invalid: Abstract Sensor Class Reading" - - -class GPIOSensor(Sensor): - def __init__(self, bot, name, pin_number): - Sensor.__init__(self, bot, name) - self.pin_number = pin_number - - def readAll(self): - """ - Get Sensor Data - """ - message = "GET:ALL" + '\n' - sock.sendall(message) - with open('output.txt', 'a') as file: - file.write("Got: " + sock.recv(1024) + "\n") - file.close() - return - - def read(self, name): - """ - Get Sensor Data - """ - message = "GET:" + name + '\n' - sock.sendall(message) - with open('output.txt', 'a') as file: - file.write("Got: " + sock.recv(1024) + "\n") - file.close() - return - -bot = BaseMiniBot() -bot.turn_clockwise(50) -bot.wait(2) -bot.move_forward(100) \ No newline at end of file diff --git a/src/main/java/minibot/BaseHTTPInterface.java b/src/main/java/minibot/BaseHTTPInterface.java index f20eae3..314f42f 100644 --- a/src/main/java/minibot/BaseHTTPInterface.java +++ b/src/main/java/minibot/BaseHTTPInterface.java @@ -92,18 +92,18 @@ public static void main(String[] args) { else { SimBotConnection sbc = new SimBotConnection(); PhysicalObject po = new PhysicalObject("TESTBOT", 50, simvs.getWorld(), 0.4f, 0.0f, 1f, 1f, true); - SimBot simba; - simba = new SimBot(sbc, name, po); - newBot = simba; + SimBot smbot; + smbot = new SimBot(sbc, name, po); + newBot = smbot; ArrayList pObjs = new ArrayList<>(); pObjs.add(po); simvs.processPhysicalObjects(pObjs); // Color sensor TODO put somewhere nice - ColorIntensitySensor colorSensorL = new ColorIntensitySensor((SimBotSensorCenter) simba.getSensorCenter(),"right",simba, 7); - ColorIntensitySensor colorSensorR = new ColorIntensitySensor((SimBotSensorCenter) simba.getSensorCenter(),"left",simba, -7); - ColorIntensitySensor colorSensorM = new ColorIntensitySensor((SimBotSensorCenter) simba.getSensorCenter(),"center",simba, 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); } diff --git a/src/main/java/simulator/simbot/SimBot.java b/src/main/java/simulator/simbot/SimBot.java index 0419004..7ec86ea 100644 --- a/src/main/java/simulator/simbot/SimBot.java +++ b/src/main/java/simulator/simbot/SimBot.java @@ -112,6 +112,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 @@ -142,7 +143,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 { @@ -156,11 +156,8 @@ 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]), @@ -168,7 +165,6 @@ public void run() { Double.parseDouble(wheel_cmds[3]) ); break; - } } } diff --git a/src/main/java/simulator/simbot/SimBotCommandCenter.java b/src/main/java/simulator/simbot/SimBotCommandCenter.java index 28c10ff..ff126d5 100644 --- a/src/main/java/simulator/simbot/SimBotCommandCenter.java +++ b/src/main/java/simulator/simbot/SimBotCommandCenter.java @@ -78,20 +78,19 @@ 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())); - int ret; String line; - while ((line = in.readLine()) != null) { - ret = new Integer(line).intValue(); + while ((line = scriptFeedbackInStream.readLine()) != null) { + int ret = new Integer(line).intValue(); System.out.println("" + ret); } }catch(Exception e){