summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergiusz Bazański <q3k@q3k.org>2012-11-11 14:14:23 +0100
committerSergiusz Bazański <q3k@q3k.org>2012-11-11 14:14:23 +0100
commit15c86974e4eb648e8d2a8db4e93ad17ad75aea86 (patch)
tree45c978d48b1d738484558fa731a05bd1e2552b45
parent1ab422118cfacee567725e0f1244a66f30350e6d (diff)
downloadlaserz_und_stuff-15c86974e4eb648e8d2a8db4e93ad17ad75aea86.tar.gz
laserz_und_stuff-15c86974e4eb648e8d2a8db4e93ad17ad75aea86.tar.bz2
laserz_und_stuff-15c86974e4eb648e8d2a8db4e93ad17ad75aea86.zip
Hackwaw cannon model.
-rw-r--r--Lasers_und_stuff/Cannon.py20
-rw-r--r--Lasers_und_stuff/main.py2
2 files changed, 17 insertions, 5 deletions
diff --git a/Lasers_und_stuff/Cannon.py b/Lasers_und_stuff/Cannon.py
index f124ce6..bda01ad 100644
--- a/Lasers_und_stuff/Cannon.py
+++ b/Lasers_und_stuff/Cannon.py
@@ -6,7 +6,7 @@ Created on Nov 11, 2012
import serial
import glob
import threading
-from math import ceil
+import math
def mutex(m):
def wrapper(self, *args, **kwargs):
@@ -40,6 +40,9 @@ class CannonController :
def set_position(self, point):
self.position = point
+
+ def translate_yaw(yaw):
+ return yaw
def fire(self):
self.fired = True
@@ -91,6 +94,7 @@ class CannonController :
def get_data_to_send(self):
data = self.get_data()
+ data[0] = self.translate_yaw(data[0])
return [chr(x) for x in data]
def send_data(self):
@@ -107,7 +111,15 @@ class CannonController :
self.ser.write(data[3])
else:
print "Cannot send data, not connected..."
-
+
+class HackWAWCannonController(CannonController):
+ AXIS_DISTANCE = 20
+ ARM_LENGTH = 1
+ def translate_yaw(yaw):
+ turret_angle = (yaw * math.pi) / 256 - (math.pi / 2)
+ servo_angle = math.asin((ARM_LENGTH * math.tan(turret_angle)) / (AXIS_DISTANCE - ARM_LENGTH))
+ return int(((servo_angle + (math.pi / 2)) * 256) / math.pi)
+
class Gunpoint :
def __init__(self, point1, point2, point3):
self.vertical_angle = point3[1] - point1[1]
@@ -122,6 +134,6 @@ class Gunpoint :
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])
+ horizontal = math.ceil(self.beginnig_horizontal + self.horizontal_angle*point[0])
+ vertical = math.ceil(self.beginnig_vertical + self.vertical_angle*point[1])
return [horizontal, vertical] \ No newline at end of file
diff --git a/Lasers_und_stuff/main.py b/Lasers_und_stuff/main.py
index 15ab4e3..df7cd7e 100644
--- a/Lasers_und_stuff/main.py
+++ b/Lasers_und_stuff/main.py
@@ -75,7 +75,7 @@ def main():
colors = [GRAY, VIOLET, RED, GREEN, BLUE, VERYLIGHT]
global cannon
- cannon = CannonController()
+ cannon = HackWAWCannonController()
screen = Screen(window, colors)