Class: SGS::Navigate

Inherits:
Object
  • Object
show all
Defined in:
lib/sgs/navigate.rb

Constant Summary collapse

MODE_SLEEP =
0
MODE_TEST =
1
MODE_MANUAL =
2
MODE_UPDOWN =
3
MODE_OLYMPIC =
4
MODE_PRE_MISSION =
5
MODE_MISSION =
6
MODE_MISSION_END =
7
MODE_MISSION_ABORT =
8
MODENAMES =
[
  "Sleeping...",
  "Test Mode",
  "Manual Steering",
  "Sail Up and Down",
  "Sail a Triangle",
  "Pre-Mission Wait",
  "On Mission",
  "Mission Ended",
  "** Mission Abort **"
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNavigate

Returns a new instance of Navigate.



64
65
66
67
68
69
# File 'lib/sgs/navigate.rb', line 64

def initialize
  @mode = MODE_SLEEP
  @waypoint = nil
  @curpos = nil
  super
end

Instance Attribute Details

#modeObject

Returns the value of attribute mode.



40
41
42
# File 'lib/sgs/navigate.rb', line 40

def mode
  @mode
end

Class Method Details

.daemonObject

Main daemon function (called from executable)



73
74
75
76
77
# File 'lib/sgs/navigate.rb', line 73

def self.daemon
  loop do
    sleep 300
  end
end

Instance Method Details

#curposObject

What is our current position?



147
148
149
# File 'lib/sgs/navigate.rb', line 147

def curpos
  @curpos ||= SGS::GPS.load
end

#missionObject

Navigate the mission. This is the main “meat and potatoes” navigation. It concerns itself with finding the best route to the next mark and sailing to that



132
133
# File 'lib/sgs/navigate.rb', line 132

def mission
end

#mission_abortObject

The mission is aborted. Determine what to do next



142
143
# File 'lib/sgs/navigate.rb', line 142

def mission_abort
end

#mission_endObject

The mission has ended - sail to the rendezvous point



137
138
# File 'lib/sgs/navigate.rb', line 137

def mission_end
end

#mode_nameObject

What is the mode name?



81
82
83
# File 'lib/sgs/navigate.rb', line 81

def mode_name
  MODENAMES[@mode]
end

#olympic_courseObject

Navigate around an olympic triangle. Sail one nautical mile upwind of the current position, then sail to a point to the left-side of the course which is at an angle of 120 degrees to the wind. From there, sail back to the start position



125
126
# File 'lib/sgs/navigate.rb', line 125

def olympic_course
end

#runObject

This is the main navigator function. It does several things;

  1. Look for the next waypoint and compute bearing and distance to it

  2. Decide if we have reached the waypoint (and adjust accordingly)

  3. Compute the boat heading (and adjust accordingly)



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/sgs/navigate.rb', line 95

def run
  puts "Navigator mode is #{mode_name}: Current Position:"
  p curpos
  p waypoint
  case @mode
  when MODE_UPDOWN
    upwind_downwind_course
  when MODE_OLYMPIC
    olympic_course
  when MODE_MISSION
    mission
  when MODE_MISSION_END
    mission_end
  when MODE_MISSION_ABORT
    mission_abort
  end
end

#upwind_downwind_courseObject

Navigate a course up to a windward mark which is one nautical mile upwind of the start position. From there, navigate downwind to the finish position



117
118
# File 'lib/sgs/navigate.rb', line 117

def upwind_downwind_course
end

#waypointObject

What is the next waypoint?



153
154
155
# File 'lib/sgs/navigate.rb', line 153

def waypoint
  @waypoint ||= SGS::Waypoint.load
end