Class: SGS::MissionStatus

Inherits:
RedisBase show all
Defined in:
lib/sgs/mission_status.rb

Overview

Handle a specific mission.

Constant Summary collapse

STATE_AWAITING =
0
STATE_READY_TO_START =
1
STATE_START_TEST =
2
STATE_RADIO_CONTROL =
3
STATE_COMPASS_FOLLOW =
4
STATE_WIND_FOLLOW =
5
STATE_COMPLETE =
6
STATE_TERMINATED =
7
STATE_FAILURE =
8
STATE_NAMES =
[
  ["Awaiting Instructions", STATE_AWAITING],
  ["Ready to Start", STATE_READY_TO_START],
  ["Initial Testing", STATE_START_TEST],
  ["On-Mission - Radio Control", STATE_RADIO_CONTROL],
  ["On-Mission - Track Compass Heading", STATE_COMPASS_FOLLOW],
  ["On-Mission - Track Wind Direction", STATE_WIND_FOLLOW],
  ["Mission Completed!", STATE_COMPLETE],
  ["Mission Terminated", STATE_TERMINATED],
  ["Mission Failure", STATE_FAILURE]
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RedisBase

#count, #count_name, #load, load, #make_redis_name, #publish, redis, redis_handle, #redis_read_var, #save, #save_and_publish, setup, subscribe, to_redis, var_init

Constructor Details

#initializeMissionStatus

Create the attractors and repellors as well as the track array and other items. @where is our current TrackPoint, @current_wpt is the waypoint we’re working (-1 if none), @course is the heading/speed the boat is on.



82
83
84
85
86
87
88
# File 'lib/sgs/mission_status.rb', line 82

def initialize
  @state = STATE_AWAITING
  @current_waypoint = -1
  @where = nil
  @distance = 0
  @track = nil
end

Instance Attribute Details

#courseObject

Returns the value of attribute course.



53
54
55
# File 'lib/sgs/mission_status.rb', line 53

def course
  @course
end

#current_waypointObject

Returns the value of attribute current_waypoint.



53
54
55
# File 'lib/sgs/mission_status.rb', line 53

def current_waypoint
  @current_waypoint
end

#distanceObject

Returns the value of attribute distance.



53
54
55
# File 'lib/sgs/mission_status.rb', line 53

def distance
  @distance
end

#end_timeObject

Returns the value of attribute end_time.



53
54
55
# File 'lib/sgs/mission_status.rb', line 53

def end_time
  @end_time
end

#start_timeObject

Returns the value of attribute start_time.



53
54
55
# File 'lib/sgs/mission_status.rb', line 53

def start_time
  @start_time
end

#stateObject

Returns the value of attribute state.



53
54
55
# File 'lib/sgs/mission_status.rb', line 53

def state
  @state
end

Instance Method Details

#active?Boolean

Are we actively on-mission?

Returns:

  • (Boolean)


98
99
100
# File 'lib/sgs/mission_status.rb', line 98

def active?
  @state >= STATE_START_TEST && @state < STATE_COMPLETE
end

#completed!(time = nil) ⇒ Object

Terminate a mission.



114
115
116
117
118
119
# File 'lib/sgs/mission_status.rb', line 114

def completed!(time = nil)
  @end_time = time || Time.now
  @state = STATE_COMPLETE
  save_and_publish
  puts "***** Mission completed! *****"
end

#failure!(time = nil) ⇒ Object

Terminate a mission.



132
133
134
135
136
137
# File 'lib/sgs/mission_status.rb', line 132

def failure!(time = nil)
  @end_time = time || Time.now
  @state = STATE_FAILURE
  save_and_publish
  puts "***** Mission failure! *****"
end

#start_test!(time = nil) ⇒ Object

Commence a mission…



104
105
106
107
108
109
110
# File 'lib/sgs/mission_status.rb', line 104

def start_test!(time = nil)
  puts "***** Starting test phase *****"
  @start_time = time || Time.now
  @state = STATE_START_TEST
  @current_waypoint = 0
  save_and_publish
end

#state_nameObject

Print a user-friendly label for the state



92
93
94
# File 'lib/sgs/mission_status.rb', line 92

def state_name
  STATE_NAMES[@state][0]
end

#terminate!(time = nil) ⇒ Object

Terminate a mission.



123
124
125
126
127
128
# File 'lib/sgs/mission_status.rb', line 123

def terminate!(time = nil)
  @end_time = time || Time.now
  @state = STATE_TERMINATED
  save_and_publish
  puts "***** Mission terminated! *****"
end