From fd098c05805d9f4262438695e55cf634963c68b0 Mon Sep 17 00:00:00 2001
From: "Brutzman, Don" <brutzman@nps.edu>
Date: Thu, 13 Aug 2020 15:10:58 -0700
Subject: [PATCH] confirmed correct during weekly call

---
 .../SailorOverboardMission8State.cl           | 31 ++++++++++++-------
 .../SailorOverboardMission8State.cl.log.txt   | 26 ++++------------
 2 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/missions/lisp/SailorOverboard/SailorOverboardMission8State.cl b/missions/lisp/SailorOverboard/SailorOverboardMission8State.cl
index 8e4b133..89b71d9 100644
--- a/missions/lisp/SailorOverboard/SailorOverboardMission8State.cl
+++ b/missions/lisp/SailorOverboard/SailorOverboardMission8State.cl
@@ -1,6 +1,6 @@
 ;This code written in ANSI Common Lisp, Allegro 10.1 enhancement, from Franz, Inc., by
 ;Prof. Robert B. McGhee (robertbmcghee@gmail.com) at the Naval Postgraduate School,
-;Monterey, CA 93943. Date of latest update: 4 January 2020.
+;Monterey, CA 93943. Date of latest update: 10 August 2020.
 
 ;Comment1: As of the time of this writing, the default Allegro IDE editor window print
 ;font is oversized, and does not print a full-width copy of the IDE Debug or Editor
@@ -25,7 +25,8 @@
 ;evolution of RBM software. The "mission controller" is usually assumed to be electronic,
 ;but could be a human "executive officer" in the case of a manned vehicle. The mission
 ;agent is always a vehicle. If the vehicle has an onboard computer incorporating the
-;mission controller, then the vehicle is a robot. If not, it is an "ROV" or a "drone".
+;mission controller, then the vehicle is a robot. If not, it is an "ROV" or a 
+;remotely operated "drone".
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;Begin Universal Mission Execution Engine;;;;;;;;;;;;;;;;;;;;;;;
@@ -36,6 +37,7 @@
 
 (defclass mission-execution-engine ()
   ((external-agent-response :accessor external-agent-response :initform nil)
+   (previous-execution-phase :accessor previous-execution-phase :initform nil)
    (current-execution-phase :accessor current-execution-phase :initform 'phase1)
    (successor-list-index :accessor successor-list-index :initform 0)))
 
@@ -57,15 +59,13 @@
          (new-successor-list (successor-list (eval phase)))
          (new-index (successor-list-index MEE))
          (next-phase (second (nth new-index new-successor-list))))
-    (setf (current-execution-phase MEE) next-phase)))
+    (setf (previous-execution-phase MEE) phase (current-execution-phase MEE) next-phase)))
 
 (defmethod set-successor-list-index ((MEE mission-execution-engine))
   (let* ((index (convert-outcome-to-index (external-agent-response MEE))))
     (setf (successor-list-index MEE) index)))
 
-(defvar mission-controller (make-instance 'mission-execution-engine)) ; instantiate the class as an object
-
-; discussion for future work: naming conventions
+(defvar mission-controller (make-instance 'mission-execution-engine))
 
 (defun execute-phase ()
   (issue-command mission-controller)
@@ -95,7 +95,6 @@
   (create-mission-orders)
   (execute-mission))
 
-; execute starting at a new phase, also enables testing and refinement resuming in the middle of a mission
 (defun rerun (new-start-phase)
   (setf (current-execution-phase mission-controller) new-start-phase)
   (execute-mission))
@@ -111,8 +110,19 @@
   (cond ((member (current-execution-phase mission-controller) terminal-phase-list) (execute-terminal-phase))
         (t (execute-phase)(execute-mission))))
 
+(defun repeat ()
+  (rerun (previous-execution-phase mission-controller)))
+
+(defun refine-last-command ()
+  (let* ((previous-phase (previous-execution-phase mission-controller)))
+    (cond ((equal previous-phase 'phase1) (rerun 'phase1.1)))))
+
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;End Universal Mission Execution Engine;;;;;;;;;;;;;;;;;;;;;;;
 
+
+
+
 ;;;;;;;;;;;;;;;;;;;;;;Begin 8-phase Sailor Overboard Mission Orders;;;;;;;;;;;;;;;;;;;;
 
 (defvar phase1 (make-instance 'mission-phase))
@@ -143,7 +153,7 @@
                     '(("Success." phase2) ("Failed." phase8) ("Exception." phase8)))
 
   (initialize-phase phase2 "Rendezvous with Sailor!"
-                    '(("Success." phase4) ("Failed." phase3) ("Exception." phase8)))
+                    '(("Success." phase4) ("Failed." phase3) ("Exception." phase8))) ; deviation from phase4/phase3/phase5
 
   (initialize-phase phase3 "Search for Sailor!"  
                     '(("Success." phase4) ("Failed." phase8) ("Exception." phase8)))
@@ -158,7 +168,6 @@
 
   (initialize-phase phase7 "Halt and deploy recovery beacon!" nil)
 
-  (initialize-phase phase8 "Halt and await further orders!" nil)
-)
+  (initialize-phase phase8 "Halt and await further orders!" nil))
  
-;;;;;;;;;;;;;;;;;;;;;;End 8-phase Sailor Overboard Mission Orders;;;;;;;;;;;;;;;;;;;;;;;;;
\ No newline at end of file
+;;;;;;;;;;;;;;;;;;;;;;End 8-phase Sailor Overboard Mission Orders;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/missions/lisp/SailorOverboard/SailorOverboardMission8State.cl.log.txt b/missions/lisp/SailorOverboard/SailorOverboardMission8State.cl.log.txt
index 6a5669a..1d8149c 100644
--- a/missions/lisp/SailorOverboard/SailorOverboardMission8State.cl.log.txt
+++ b/missions/lisp/SailorOverboard/SailorOverboardMission8State.cl.log.txt
@@ -1,4 +1,5 @@
-; Fast loading C:\x-nps-gitlab\NetworkOptionalWarfare\ethicalcontrol\missions\lisp\SailorOverboard\SailorOverboardMission8State.fasl
+RESULTS
+
 CG-USER(1): (run)
 Deploy!
 Did goal succeed (s), fail (f), or abort (x)?s
@@ -12,30 +13,15 @@ Halt and prepare for recovery!
 NIL
 CG-USER(2): (run)
 Deploy!
-Did goal succeed (s), fail (f), or abort (x)?s
-Rendezvous with Sailor!
-Did goal succeed (s), fail (f), or abort (x)?f
-Search for Sailor!
-Did goal succeed (s), fail (f), or abort (x)?s
-Track Sailor Afloat Until Safe!
 Did goal succeed (s), fail (f), or abort (x)?x
 Halt and await further orders!
 NIL
-CG-USER(3): (rerun phase3)
-Search for Sailor!
-Did goal succeed (s), fail (f), or abort (x)?s
-Track Sailor Afloat Until Safe!
-Did goal succeed (s), fail (f), or abort (x)?s
-Proceed to recovery!
-Did goal succeed (s), fail (f), or abort (x)?s
-Halt and prepare for recovery!
-NIL
-CG-USER(4): (run)
+CG-USER(3): (repeat)
 Deploy!
-Did goal succeed (s), fail (f), or abort (x)?x
+Did goal succeed (s), fail (f), or abort (x)?f
 Halt and await further orders!
 NIL
-CG-USER(5): (rerun phase1.1)
+CG-USER(4): (refine-last-command)
 Choose Tube and Launch!
 Did goal succeed (s), fail (f), or abort (x)?s
 Enter Water and Get GPS Fix!
@@ -49,4 +35,4 @@ Did goal succeed (s), fail (f), or abort (x)?s
 Proceed to recovery!
 Did goal succeed (s), fail (f), or abort (x)?s
 Halt and prepare for recovery!
-NIL
+NIL
\ No newline at end of file
-- 
GitLab