Skip to content

Commit

Permalink
Initial logic commit
Browse files Browse the repository at this point in the history
logic files - helmsman, ship_data, and calc; no captain
  • Loading branch information
james-simon committed Oct 29, 2015
1 parent 33bec07 commit 0c8ad5c
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/modules/Logic/ShipData.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
__author__ = 'jbs'

boat_heading = 0

relative_wind_heading = 0
wind_heading = 0

boat_roll = 0
boat_pitch = 0
boat_yaw = 0

boat_lat = 37.9
boat_lon = -78.1

target_lats = {1, 5, 7}
target_lons = {2, -9, 1}

current_distance_to_target = 10101

rudder_servo_angle = 90;
winch_servo_angle = 50;
38 changes: 38 additions & 0 deletions src/modules/Logic/calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import math
import ship_data

""" The file contains help methods to logic functions.
These are object independent; they only need the data given as parameters
to return a result.
"""



def direction_to_point(current_point, target_point):
a = math.radians(current_point['latitude'])
b = math.radians(target_point['latitude'])
d = math.radians(target_point['longitude'] - current_point['longitude'])

y = math.sin(d) * math.cos(b)
x = math.cos(a) * math.sin(b) - math.sin(a) * math.cos(b) * math.cos(d)

return (math.degrees(math.atan2(y, x)) + 360) % 360

def get_heading_angle(heading, current_point, target_point):
angle = direction_to_point(current_point, target_point)

return heading - angle

def within_radius_of_target(current_point, target_point):
return (distance(current_point, target_point) <= ship_data.point_proximity_radius)

def distance(point1, point2):
a = math.sin(math.radians(point1['latitude']))
b = math.sin(math.radians(point2['latitude']))
c = math.cos(math.radians(point1['latitude']))
d = math.cos(math.radians(point2['latitude']))

e = a * b + c * d * math.cos((math.radians(point2['longitude'] - point1['longitude'])))
f = math.acos(e)

return f * 6371 * 1000
31 changes: 31 additions & 0 deletions src/modules/Logic/helmsman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
__author__ = 'jbs'

import ship_data

#wind angles that make the sail fully-in and sail fully-out
sail_in_wind_angle = 60
sail_out_wind_angle = 120

#winch servo fully-in and fully-out values
winch_min = 40
winch_max = 85

def setRudderAngle(targetHeading):
current_heading = ship_data.boat_heading
angleToTurn = targetHeading - current_heading

ship_data.rudder_servo_angle = 90 - angleToTurn/10

socket_communicator.set_rudder_servo_angle(ship_data.rudder_servo_angle)

def setWinchAngle(targetHeading):
wind_angle_ratio = (ship_data.relative_wind_heading - sail_in_wind_angle)/(sail_out_wind_angle - sail_in_wind_angle)

if(wind_angle_ratio > 1):
wind_angle_ratio = 1
if(wind_angle_ratio < 0):
wind_angle_ratio = 0

ship_data.winch_servo_angle = winch_angle = (winch_min + winch_max)/2 + (winch_max - winch_min)*(wind_angle_ratio)

socket_communicator.set_winch_servo_angle(ship_data.winch_servo_angle)
10 changes: 10 additions & 0 deletions src/modules/Logic/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
__author__ = 'jbs'

import ship_data

def test():
print ship_data.boat_heading
ship_data.boat_heading = 7
print ship_data.boat_heading

test()
24 changes: 24 additions & 0 deletions src/modules/Logic/ship_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
__author__ = 'jbs'

boat_heading = 0

relative_wind_heading = 0
wind_heading = 0

boat_roll = 0
boat_pitch = 0
boat_yaw = 0

boat_lat = 37.9
boat_lon = -78.1

target_lats = {1, 5, 7}
target_lons = {2, -9, 1}

current_distance_to_target = 10101

rudder_servo_angle = 90
winch_servo_angle = 50

#how close the boat needs to approach targets
point_proximity_radius = 5
3 changes: 3 additions & 0 deletions src/modules/Logic/utlity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__author__ = 'jbs'


0 comments on commit 0c8ad5c

Please sign in to comment.