summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustyna Att Ilczuk <justyna.ilczuk@gmail.com>2012-11-11 13:38:53 +0100
committerJustyna Att Ilczuk <justyna.ilczuk@gmail.com>2012-11-11 13:38:53 +0100
commita562781ab72d5db5a32e367994ceb58cb43d4726 (patch)
tree23d1ceacf9d147bde9317003f836f207a433803c
parent4192ace6d9e6a570c32d72483dc4fc69f4aa46f1 (diff)
downloadlaserz_und_stuff-a562781ab72d5db5a32e367994ceb58cb43d4726.tar.gz
laserz_und_stuff-a562781ab72d5db5a32e367994ceb58cb43d4726.tar.bz2
laserz_und_stuff-a562781ab72d5db5a32e367994ceb58cb43d4726.tar.xz
laserz_und_stuff-a562781ab72d5db5a32e367994ceb58cb43d4726.zip
Lacking files added
-rw-r--r--Lasers_und_stuff/Cannon.py115
-rw-r--r--Lasers_und_stuff/Cannon.pycbin0 -> 5244 bytes
2 files changed, 115 insertions, 0 deletions
diff --git a/Lasers_und_stuff/Cannon.py b/Lasers_und_stuff/Cannon.py
new file mode 100644
index 0000000..8b009bd
--- /dev/null
+++ b/Lasers_und_stuff/Cannon.py
@@ -0,0 +1,115 @@
+'''
+Created on Nov 11, 2012
+
+@author: attero
+'''
+import serial
+import glob
+from math import ceil
+
+class CannonController :
+ def __init__(self):
+ print("cannon controller started")
+ self.position = [0, 0]
+ self.fired = False
+ self.laser = False
+ ports = glob.glob("/dev/ttyACM*")
+
+ if(len(ports) == 1):
+ self.ser = serial.Serial(ports[0], 115200, timeout=1)
+ self.connected_to_serial = True
+ else:
+ self.ser = False
+ self.connected_to_serial = False
+ if len(ports) > 1 :
+ raise "To many devices to handle"
+ elif len(ports) == 0 :
+ print "No device is connected"
+
+ def set_position(self, point):
+ self.position = point
+
+ def fire(self):
+ self.fired = True
+
+ def enable_laser(self):
+ self.laser = True
+
+ def disable_laser(self):
+ self.laser = False
+
+ def move_left(self, change):
+ if(self.position[0] >= change):
+ self.position[0] -= change
+
+ def move_right(self, change):
+ if(self.position[0] < 255 - change):
+ self.position[0] += change
+
+ def move_up(self, change):
+ if(self.position[1] < 255 - change):
+ self.position[1] += change
+
+ def move_down(self, change):
+ if(self.position[1] >= change):
+ self.position[1] -= change
+
+ def check_validity_of_data(self):
+ if(abs(self.position[0]) > 255):
+ return False
+ if (abs(self.position[1]) > 255):
+ return False
+ return True
+
+ def get_data(self):
+ if self.check_validity_of_data():
+ data = []
+ data.extend(self.position)
+ if(self.fired):
+ data.append(255)
+ else:
+ data.append(0)
+ if(self.laser):
+ data.append(255)
+ else:
+ data.append(0)
+ return data
+ else:
+ return [0, 0, 0, 0]
+
+ def get_data_to_send(self):
+ data = self.get_data()
+ return [chr(x) for x in data]
+
+ def send_data(self):
+ if(self.connected_to_serial):
+ data = self.get_data_to_send()
+ self.ser.write('a')
+ self.ser.write(data[0])
+ print "wrote %i" % ord(data[0])
+ self.ser.write('b')
+ self.ser.write(data[1])
+ self.ser.write('c')
+ self.ser.write(data[2])
+ self.ser.write('d')
+ self.ser.write(data[3])
+ else:
+ print "Cannot send data, not connected..."
+
+class Gunpoint :
+ def __init__(self, point1, point2, point3):
+ self.vertical_angle = point3[1] - point1[1]
+ self.horizontal_angle = point2[0] - point1[0]
+ self.beginnig_horizontal = point1[0]
+ self.beginnig_vertical = point1[1]
+
+ def calibrate(self, point1, point2, point3):
+ self.vertical_angle = point3[1] - point1[1]
+ self.horizontal_angle = point2[0] - point1[0]
+ self.beginnig_horizontal = point1[0]
+ self.beginnig_vertical = point1[1]
+
+ def aim(self, point):
+ horizontal = ceil(self.beginnig_horizontal + self.horizontal_angle*point[0])
+ vertical = ceil(self.beginnig_vertical + self.vertical_angle*point[1])
+ return [horizontal, vertical] \ No newline at end of file
diff --git a/Lasers_und_stuff/Cannon.pyc b/Lasers_und_stuff/Cannon.pyc
new file mode 100644
index 0000000..ada5c7d
--- /dev/null
+++ b/Lasers_und_stuff/Cannon.pyc
Binary files differ