Class: SGS::Mission
- Inherits:
-
Object
- Object
- SGS::Mission
- Defined in:
- lib/sgs/mission.rb
Overview
Handle a specific mission.
Instance Attribute Summary collapse
-
#attractors ⇒ Object
Returns the value of attribute attractors.
-
#description ⇒ Object
Returns the value of attribute description.
-
#launch_location ⇒ Object
Returns the value of attribute launch_location.
-
#launch_site ⇒ Object
Returns the value of attribute launch_site.
-
#repellors ⇒ Object
Returns the value of attribute repellors.
-
#status ⇒ Object
Returns the value of attribute status.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
-
.daemon ⇒ Object
Main daemon function (called from executable).
-
.file_load(filename) ⇒ Object
Load a new mission from the missions directory.
-
.parse(data) ⇒ Object
Load a new mission from the missions directory.
Instance Method Summary collapse
-
#initialize ⇒ Mission
constructor
Create the attractors and repellors as well as the track array and other items.
-
#parse(data) ⇒ Object
Parse mission data from a hash.
-
#to_hash ⇒ Object
Convert the mission into a hash.
-
#to_yaml ⇒ Object
Return a YAML string from the mission data.
Constructor Details
#initialize ⇒ Mission
Create the attractors and repellors as well as the track array and other items.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/sgs/mission.rb', line 57 def initialize @title = nil @url = nil @description = nil @launch_site = nil @launch_location = nil @attractors = [] @repellors = [] @status = MissionStatus.load super end |
Instance Attribute Details
#attractors ⇒ Object
Returns the value of attribute attractors.
52 53 54 |
# File 'lib/sgs/mission.rb', line 52 def attractors @attractors end |
#description ⇒ Object
Returns the value of attribute description.
50 51 52 |
# File 'lib/sgs/mission.rb', line 50 def description @description end |
#launch_location ⇒ Object
Returns the value of attribute launch_location.
51 52 53 |
# File 'lib/sgs/mission.rb', line 51 def launch_location @launch_location end |
#launch_site ⇒ Object
Returns the value of attribute launch_site.
51 52 53 |
# File 'lib/sgs/mission.rb', line 51 def launch_site @launch_site end |
#repellors ⇒ Object
Returns the value of attribute repellors.
52 53 54 |
# File 'lib/sgs/mission.rb', line 52 def repellors @repellors end |
#status ⇒ Object
Returns the value of attribute status.
52 53 54 |
# File 'lib/sgs/mission.rb', line 52 def status @status end |
#title ⇒ Object
Returns the value of attribute title.
50 51 52 |
# File 'lib/sgs/mission.rb', line 50 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
50 51 52 |
# File 'lib/sgs/mission.rb', line 50 def url @url end |
Class Method Details
.daemon ⇒ Object
Main daemon function (called from executable)
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/sgs/mission.rb', line 71 def self.daemon puts "Mission management system starting up..." # # Load the mission data from Redis and augment it with the # contents of the mission file. config = Config.load mission = Mission.file_load config.mission_file nav = Navigate.new(mission) otto = Otto.load # # Keep running in our mission state, forever. while true do if mission.status.active? # # Listen for GPS data. When we have a new position, call the # navigation code to determine a new course to sail (currently # a compass course), and set the Otto register accordingly. # Repeat until we run out of waypoints. GPS.subscribe do |count| puts "Mission received new GPS count: #{count}" new_course = nav.navigate if new_course.nil? mission.status.completed! break end mission.status.save compass = Bearing.rtox(new_course.heading) otto.set_register(Otto::COMPASS_HEADING_REGISTER, compass) end else sleep 60 mission.status.load end end end |
.file_load(filename) ⇒ Object
Load a new mission from the missions directory.
109 110 111 |
# File 'lib/sgs/mission.rb', line 109 def self.file_load(filename) parse YAML.load(File.open(filename)) end |
.parse(data) ⇒ Object
Load a new mission from the missions directory.
115 116 117 118 119 |
# File 'lib/sgs/mission.rb', line 115 def self.parse(data) mission = new mission.parse(data) mission end |
Instance Method Details
#parse(data) ⇒ Object
Parse mission data from a hash.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/sgs/mission.rb', line 123 def parse(data) @title = data["title"] || "Untitled Mission" @url = data["url"] @description = data["description"] if data["launch"] @launch_site = data["launch"]["site"] || "Launch Site" @launch_location = Location.new @launch_location.parse_hash data["launch"] end if data["attractors"] data["attractors"].each do |waypt_data| waypt = Waypoint.parse(waypt_data) waypt.attractor = true @attractors << waypt end end if data["repellors"] data["repellors"].each do |waypt_data| waypt = Waypoint.parse(waypt_data) waypt.attractor = false @repellors << waypt end end end |
#to_hash ⇒ Object
Convert the mission into a hash
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/sgs/mission.rb', line 156 def to_hash hash = {"title" => @title} hash["url"] = @url if @url hash["description"] = @description if @description if @launch_location hash["launch"] = @launch_location.to_hash hash["launch"]["site"] = @launch_site end hash["attractors"] = [] @attractors.each do |waypt| hash["attractors"] << waypt.to_hash end hash["repellors"] = [] hash end |
#to_yaml ⇒ Object
Return a YAML string from the mission data
150 151 152 |
# File 'lib/sgs/mission.rb', line 150 def to_yaml to_hash.to_yaml end |