@@ -29,6 +29,7 @@ pub struct SessionView {
2929 pub gripper_opening : f64 ,
3030 pub estimated : bool ,
3131 pub can_recalibrate_joint : bool ,
32+ pub can_reopen_saved_review : bool ,
3233 pub recalibrating_joint : Option < usize > ,
3334 pub message : String ,
3435 pub configuration_path : String ,
@@ -43,6 +44,7 @@ impl Default for SessionView {
4344 gripper_opening : 0.5 ,
4445 estimated : false ,
4546 can_recalibrate_joint : false ,
47+ can_reopen_saved_review : false ,
4648 recalibrating_joint : None ,
4749 message : String :: new ( ) ,
4850 configuration_path : String :: new ( ) ,
@@ -75,6 +77,7 @@ impl ReviewSource {
7577enum State {
7678 Reference {
7779 message : String ,
80+ can_reopen_saved_review : bool ,
7881 } ,
7982 Sweep {
8083 recording : Sweep ,
@@ -88,6 +91,15 @@ enum State {
8891 Failed ( String ) ,
8992}
9093
94+ impl State {
95+ fn reference ( message : impl Into < String > ) -> Self {
96+ Self :: Reference {
97+ message : message. into ( ) ,
98+ can_reopen_saved_review : false ,
99+ }
100+ }
101+ }
102+
91103#[ derive( PartialEq , Eq ) ]
92104struct MotorSnapshot {
93105 offsets : [ i64 ; 6 ] ,
@@ -147,9 +159,7 @@ impl<Bus: SetupBus> Session<Bus> {
147159 setup,
148160 files,
149161 snapshot,
150- state : State :: Reference {
151- message : String :: new ( ) ,
152- } ,
162+ state : State :: reference ( "" ) ,
153163 positions,
154164 previous_positions : positions,
155165 moving_until : [ None ; 6 ] ,
@@ -160,35 +170,31 @@ impl<Bus: SetupBus> Session<Bus> {
160170
161171 fn initial_state ( & self ) -> Result < State > {
162172 if self . files . reset_incomplete ( ) ? {
163- return Ok ( State :: Reference {
164- message : "Retry the incomplete reset before calibrating." . into ( ) ,
165- } ) ;
173+ return Ok ( State :: reference (
174+ "Retry the incomplete reset before calibrating." ,
175+ ) ) ;
166176 }
167177 if self . files . calibration_incomplete ( ) ? {
168- return Ok ( State :: Reference {
169- message : "The previous save did not finish. Inspect the backups and capture a new calibration." . into ( ) ,
170- } ) ;
178+ return Ok ( State :: reference (
179+ "The previous save did not finish. Inspect the backups and capture a new calibration." ,
180+ ) ) ;
171181 }
172182 let path = self . files . calibration_path ( ) ;
173183 if !path. try_exists ( ) ? {
174- return Ok ( State :: Reference {
175- message : String :: new ( ) ,
176- } ) ;
184+ return Ok ( State :: reference ( "" ) ) ;
177185 }
178186 let calibration = match self . setup . motor_ids . load_named_calibration ( & path) {
179187 Ok ( calibration) => calibration,
180188 Err ( error) => {
181- return Ok ( State :: Reference {
182- message : format ! ( "Saved calibration could not be reused: {error:#}" ) ,
183- } ) ;
189+ return Ok ( State :: reference ( format ! (
190+ "Saved calibration could not be reused: {error:#}"
191+ ) ) ) ;
184192 }
185193 } ;
186194 if !self . snapshot . matches ( & calibration) {
187- return Ok ( State :: Reference {
188- message :
189- "Saved calibration differs from the motor registers. Capture a new reference."
190- . into ( ) ,
191- } ) ;
195+ return Ok ( State :: reference (
196+ "Saved calibration differs from the motor registers. Capture a new reference." ,
197+ ) ) ;
192198 }
193199 let source = if self . files . matches_setup ( & self . setup ) {
194200 ReviewSource :: Saved
@@ -212,6 +218,7 @@ impl<Bus: SetupBus> Session<Bus> {
212218 }
213219
214220 fn reload_baseline ( & mut self ) -> Result < CalibrationEntries > {
221+ self . files . require_completed_reset ( ) ?;
215222 let calibration = self
216223 . setup
217224 . motor_ids
@@ -265,12 +272,36 @@ impl<Bus: SetupBus> Session<Bus> {
265272 _ => {
266273 self . state = State :: Reference {
267274 message : String :: new ( ) ,
275+ can_reopen_saved_review : matches ! (
276+ self . initial_state( ) ?,
277+ State :: Review {
278+ source: ReviewSource :: Saved ,
279+ ..
280+ }
281+ ) ,
268282 }
269283 }
270284 }
271285 Ok ( ( ) )
272286 }
273287
288+ pub fn reopen_saved_review ( & mut self ) -> Result < ( ) > {
289+ ensure ! (
290+ matches!(
291+ self . state,
292+ State :: Reference {
293+ can_reopen_saved_review: true ,
294+ ..
295+ }
296+ ) ,
297+ "Start from a saved setup before returning to its review"
298+ ) ;
299+ let baseline = self . reload_baseline ( ) ?;
300+ self . sample ( ) ?;
301+ self . state = self . review_saved ( & baseline, ReviewSource :: Saved ) ?;
302+ Ok ( ( ) )
303+ }
304+
274305 pub fn sample ( & mut self ) -> Result < ( ) > {
275306 let ids = self . setup . motor_ids . ordered ( ) ;
276307 let positions = read_positions ( self . bus . as_mut ( ) . context ( "Reconnect the arm" ) ?, ids) ?;
@@ -490,8 +521,12 @@ impl<Bus: SetupBus> Session<Bus> {
490521 } )
491522 . collect ( ) ;
492523 }
493- State :: Reference { message } => {
524+ State :: Reference {
525+ message,
526+ can_reopen_saved_review,
527+ } => {
494528 view. message . clone_from ( message) ;
529+ view. can_reopen_saved_review = * can_reopen_saved_review;
495530 let ( signs, offsets) = alignment_arrays ( & self . setup . alignment ) ;
496531 view. joints = MOTOR_NAMES
497532 . into_iter ( )
0 commit comments