Hackwaw cannon model.
parent
1ab422118c
commit
15c86974e4
|
@ -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]
|
|
@ -75,7 +75,7 @@ def main():
|
|||
colors = [GRAY, VIOLET, RED, GREEN, BLUE, VERYLIGHT]
|
||||
|
||||
global cannon
|
||||
cannon = CannonController()
|
||||
cannon = HackWAWCannonController()
|
||||
|
||||
|
||||
screen = Screen(window, colors)
|
||||
|
|
Loading…
Reference in New Issue