-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
logic files - helmsman, ship_data, and calc; no captain
- Loading branch information
1 parent
33bec07
commit 0c8ad5c
Showing
6 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__author__ = 'jbs' | ||
|
||
|