simple amends + templates stuff
parent
15c86974e4
commit
3f60dfa460
|
@ -41,7 +41,7 @@ class CannonController :
|
|||
def set_position(self, point):
|
||||
self.position = point
|
||||
|
||||
def translate_yaw(yaw):
|
||||
def translate_yaw(self, yaw):
|
||||
return yaw
|
||||
|
||||
def fire(self):
|
||||
|
@ -115,9 +115,9 @@ class CannonController :
|
|||
class HackWAWCannonController(CannonController):
|
||||
AXIS_DISTANCE = 20
|
||||
ARM_LENGTH = 1
|
||||
def translate_yaw(yaw):
|
||||
def translate_yaw(self, yaw):
|
||||
turret_angle = (yaw * math.pi) / 256 - (math.pi / 2)
|
||||
servo_angle = math.asin((ARM_LENGTH * math.tan(turret_angle)) / (AXIS_DISTANCE - ARM_LENGTH))
|
||||
servo_angle = math.asin((self.ARM_LENGTH * math.tan(turret_angle)) / (self.AXIS_DISTANCE - self.ARM_LENGTH))
|
||||
return int(((servo_angle + (math.pi / 2)) * 256) / math.pi)
|
||||
|
||||
class Gunpoint :
|
||||
|
@ -125,7 +125,7 @@ class Gunpoint :
|
|||
self.vertical_angle = point3[1] - point1[1]
|
||||
self.horizontal_angle = point2[0] - point1[0]
|
||||
self.beginnig_horizontal = point1[0]
|
||||
self.beginnig_vertical = point1[1]
|
||||
self.beginnig_vertical = point1[1]
|
||||
|
||||
def calibrate(self, point1, point2, point3):
|
||||
self.vertical_angle = point3[1] - point1[1]
|
||||
|
|
Binary file not shown.
|
@ -12,7 +12,7 @@ import os
|
|||
import signal
|
||||
import json
|
||||
from pygame.locals import *
|
||||
from Cannon import CannonController
|
||||
from Cannon import HackWAWCannonController
|
||||
from Cannon import Gunpoint
|
||||
|
||||
app = flask.Flask(__name__)
|
||||
|
@ -21,22 +21,22 @@ pygame.init()
|
|||
|
||||
cannon = None
|
||||
|
||||
@app.route("/left/<int:amount>")
|
||||
@app.route("/left/<int:amount>", methods=["POST"])
|
||||
def move_left(amount):
|
||||
cannon.move_left(amount)
|
||||
return "OK"
|
||||
|
||||
@app.route("/right/<int:amount>")
|
||||
@app.route("/right/<int:amount>", methods=["POST"])
|
||||
def move_right(amount):
|
||||
cannon.move_right(amount)
|
||||
return "OK"
|
||||
|
||||
@app.route("/up/<int:amount>")
|
||||
@app.route("/up/<int:amount>", methods=["POST"])
|
||||
def move_up(amount):
|
||||
cannon.move_up(amount)
|
||||
return "OK"
|
||||
|
||||
@app.route("/down/<int:amount>")
|
||||
@app.route("/down/<int:amount>", methods=["POST"])
|
||||
def move_down(amount):
|
||||
cannon.move_down(amount)
|
||||
return "OK"
|
||||
|
@ -47,20 +47,8 @@ def status():
|
|||
|
||||
@app.route("/")
|
||||
def root():
|
||||
return """<html>
|
||||
<head>
|
||||
<title>Turret!</title>
|
||||
</head>
|
||||
<body>
|
||||
<div style="width: 400px; height: 400px; margin-top: -200px; margin-left: -200px; position: absolute; top: 50%; left: 50%;">
|
||||
<a href="/up/20">Up</a>
|
||||
<a href="/down/20">Down</a>
|
||||
<a href="/left/20">Left</a>
|
||||
<a href="/right/20">Right</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>"""
|
||||
|
||||
|
||||
return flask.render_template("status.html", data=cannon.get_data())
|
||||
def main():
|
||||
#create the screen
|
||||
window = pygame.display.set_mode((800, 600))
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,13 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Turret!</title>
|
||||
</head>
|
||||
<body>
|
||||
<div style="width: 400px; height: 400px; margin-top: -200px; margin-left: -200px; position: absolute; top: 50%; left: 50%;">
|
||||
<a href="/up/20">Up</a>
|
||||
<a href="/down/20">Down</a>
|
||||
<a href="/left/20">Left</a>
|
||||
<a href="/right/20">Right</a>
|
||||
<h2>Status</h2> <p>""" + json.dumps(cannon.get_data()) + """ </p></div>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,7 @@
|
|||
<!doctype html>
|
||||
<title>Turret</title>
|
||||
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
|
||||
<div class=page>
|
||||
|
||||
{% block body %}{% endblock %}
|
||||
</div>
|
|
@ -0,0 +1,6 @@
|
|||
{% extends "layout.html" %}
|
||||
{% block body %}
|
||||
|
||||
<h2>Status</h2> <p>{{data}}</p>
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,34 @@
|
|||
{% extends "layout.html" %}
|
||||
{% block body %}
|
||||
<script type=text/javascript src="{{url_for('static', filename='jquery.min.js') }}"> </script>
|
||||
<script type=text/javascript>
|
||||
$(document).ready(function(){
|
||||
//
|
||||
$('#dupa').text("I like bananas");
|
||||
});
|
||||
|
||||
function pop_banana() {
|
||||
$('#banana').html('<a href="http://ranchochilamate.com/wp/wp-content/uploads/2010/10/banana.jpg">Click</a>');
|
||||
}
|
||||
|
||||
$.post("/right/20", function(data) {
|
||||
$('#dupa').html(data);
|
||||
});
|
||||
|
||||
function move_up() {
|
||||
$.post("{{url_for('move_up', amount="20")}}", function(data) {
|
||||
$('#dupa').html(data);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<div style="width: 400px; height: 400px; margin-top: -200px; margin-left: -200px; position: absolute; top: 50%; left: 50%;">
|
||||
<a onclick="move_up()">Up</a>
|
||||
<a href="/down/20">Down</a>
|
||||
<a href="/left/20">Left</a>
|
||||
<a href ="/right/20"" onclick="move_right()">Right</a>
|
||||
<p id="dupa" onclick="move_right()"></p>
|
||||
<p id="banana"></p>
|
||||
<h2>Status</h2> <p>{{data}}</p></div>
|
||||
</body>
|
||||
|
||||
{% endblock %}
|
Loading…
Reference in New Issue