@@ -22,7 +22,6 @@ import { useGlobalState } from '../../GlobalState'
22
22
import {
23
23
CLEAR_OCTOMAP_SERVICE_NAME ,
24
24
CLEAR_OCTOMAP_SERVICE_TYPE ,
25
- NON_RETRYABLE_STATES ,
26
25
ROS_ACTIONS_NAMES ,
27
26
MOTION_STATUS_SUCCESS ,
28
27
ROS_ACTION_STATUS_CANCEL_GOAL ,
@@ -124,15 +123,28 @@ const RobotMotion = (props) => {
124
123
[ setActionStatus ]
125
124
)
126
125
126
+ /**
127
+ * Callback function to change the meal state.
128
+ */
129
+ const changeMealState = useCallback (
130
+ ( nextMealState , msg = null ) => {
131
+ if ( msg ) {
132
+ console . log ( msg )
133
+ }
134
+ setPaused ( false )
135
+ let setMealState = props . setMealState
136
+ setMealState ( nextMealState )
137
+ } ,
138
+ [ setPaused , props . setMealState ]
139
+ )
140
+
127
141
/**
128
142
* Callback function for when the robot has finished moving to its staging
129
143
* location.
130
144
*/
131
145
const robotMotionDone = useCallback ( ( ) => {
132
- console . log ( 'robotMotionDone' )
133
- let setMealState = props . setMealState
134
- setMealState ( props . nextMealState )
135
- } , [ props . nextMealState , props . setMealState ] )
146
+ changeMealState ( props . nextMealState , 'robotMotionDone' )
147
+ } , [ changeMealState , props . nextMealState ] )
136
148
137
149
/**
138
150
* Callback function for when the action sends a response. It updates the
@@ -264,10 +276,8 @@ const RobotMotion = (props) => {
264
276
} , [ clearOctomapService , resumeCallback ] )
265
277
266
278
const backCallback = useCallback ( ( ) => {
267
- setPaused ( false )
268
- let setMealState = props . setMealState
269
- setMealState ( props . backMealState )
270
- } , [ setPaused , props . backMealState , props . setMealState ] )
279
+ changeMealState ( props . backMealState , 'backCallback' )
280
+ } , [ changeMealState , props . backMealState ] )
271
281
272
282
/**
273
283
* Get the action status text and progress bar or blank view to render.
@@ -279,12 +289,12 @@ const RobotMotion = (props) => {
279
289
* @param {showTime } - indicates if elapsed time needs to be shown
280
290
* @param {time } - calculated elapsed time, 0 if time not available
281
291
* @param {progress } - progress proportion; if null progress bar not shown
282
- * @param {retry } - indicates if retry needed for error
292
+ * @param {error } - indicates if there was an error
283
293
*
284
294
* @returns {JSX.Element } the action status text, progress bar or blank view
285
295
*/
286
296
const actionStatusTextAndVisual = useCallback (
287
- ( flexSizeOuter , flexSizeTextInner , flexSizeVisualInner , text , showTime , time , progress , retry = false ) => {
297
+ ( flexSizeOuter , flexSizeTextInner , flexSizeVisualInner , text , showTime , time , progress , error = false ) => {
288
298
return (
289
299
< >
290
300
< View style = { { flex : flexSizeOuter , flexDirection : dimension , alignItems : 'center' , justifyContent : 'center' , width : '100%' } } >
@@ -294,19 +304,41 @@ const RobotMotion = (props) => {
294
304
</ p >
295
305
< p style = { { fontSize : motionTextFontSize } } > { text } </ p >
296
306
{ showTime ? < p style = { { fontSize : motionTextFontSize } } > Elapsed: { time } sec</ p > : < > </ > }
297
- { retry ? (
298
- < Button
299
- variant = 'warning'
300
- className = 'mx-2 btn-huge'
301
- size = 'lg'
302
- onClick = { retryCallback }
303
- style = { {
304
- width : '90%' ,
305
- height : '20%'
306
- } }
307
- >
308
- < h5 style = { { textAlign : 'center' , fontSize : motionTextFontSize } } > Retry</ h5 >
309
- </ Button >
307
+ { error ? (
308
+ < >
309
+ { props . allowRetry ? (
310
+ < Button
311
+ variant = 'warning'
312
+ className = 'mx-2 btn-huge'
313
+ size = 'lg'
314
+ onClick = { retryCallback }
315
+ style = { {
316
+ width : '90%' ,
317
+ height : '20%'
318
+ } }
319
+ >
320
+ < h5 style = { { textAlign : 'center' , fontSize : motionTextFontSize } } > Retry</ h5 >
321
+ </ Button >
322
+ ) : (
323
+ < > </ >
324
+ ) }
325
+ { props . errorMealState ? (
326
+ < Button
327
+ variant = 'warning'
328
+ className = 'mx-2 btn-huge'
329
+ size = 'lg'
330
+ onClick = { ( ) => changeMealState ( props . errorMealState , 'errorMealState' ) }
331
+ style = { {
332
+ width : '90%' ,
333
+ height : '20%'
334
+ } }
335
+ >
336
+ < h5 style = { { textAlign : 'center' , fontSize : motionTextFontSize } } > { props . errorMealStateDescription } </ h5 >
337
+ </ Button >
338
+ ) : (
339
+ < > </ >
340
+ ) }
341
+ </ >
310
342
) : (
311
343
< > </ >
312
344
) }
@@ -326,7 +358,17 @@ const RobotMotion = (props) => {
326
358
</ >
327
359
)
328
360
} ,
329
- [ dimension , props . waitingText , motionTextFontSize , waitingTextFontSize , retryCallback ]
361
+ [
362
+ dimension ,
363
+ props . waitingText ,
364
+ props . allowRetry ,
365
+ props . errorMealState ,
366
+ props . errorMealStateDescription ,
367
+ motionTextFontSize ,
368
+ waitingTextFontSize ,
369
+ retryCallback ,
370
+ changeMealState
371
+ ]
330
372
)
331
373
332
374
/**
@@ -342,7 +384,7 @@ const RobotMotion = (props) => {
342
384
let showTime = false
343
385
let time = 0
344
386
let progress = null
345
- let retry = false
387
+ let error = false
346
388
switch ( actionStatus . actionStatus ) {
347
389
case ROS_ACTION_STATUS_EXECUTE :
348
390
if ( actionStatus . feedback ) {
@@ -377,9 +419,9 @@ const RobotMotion = (props) => {
377
419
* users on how to troubleshoot/fix it.
378
420
*/
379
421
text = 'Robot encountered an error'
380
- retry = NON_RETRYABLE_STATES . has ( props . mealState ) ? false : true
422
+ error = true
381
423
return (
382
- < > { actionStatusTextAndVisual ( flexSizeOuter , flexSizeTextInner , flexSizeVisualInner , text , showTime , time , progress , retry ) } </ >
424
+ < > { actionStatusTextAndVisual ( flexSizeOuter , flexSizeTextInner , flexSizeVisualInner , text , showTime , time , progress , error ) } </ >
383
425
)
384
426
case ROS_ACTION_STATUS_CANCELED :
385
427
return < > { actionStatusTextAndVisual ( flexSizeOuter , flexSizeTextInner , flexSizeVisualInner , text , showTime , time , progress ) } </ >
@@ -397,7 +439,7 @@ const RobotMotion = (props) => {
397
439
}
398
440
}
399
441
} ,
400
- [ paused , dimension , actionStatusTextAndVisual , props . mealState ]
442
+ [ paused , dimension , actionStatusTextAndVisual ]
401
443
)
402
444
403
445
// Render the component
@@ -421,7 +463,7 @@ const RobotMotion = (props) => {
421
463
pauseCallback = { pauseCallback }
422
464
backCallback = { props . backMealState ? backCallback : null }
423
465
backMealState = { props . backMealState }
424
- resumeCallback = { NON_RETRYABLE_STATES . has ( props . mealState ) ? null : resumeCallback }
466
+ resumeCallback = { props . allowRetry ? resumeCallback : null }
425
467
paused = { paused }
426
468
/>
427
469
</ >
@@ -454,10 +496,16 @@ RobotMotion.propTypes = {
454
496
// the action client, then calling it again, etc.)
455
497
actionInput : PropTypes . object . isRequired ,
456
498
// The static text to display while the robot is executing the action
457
- waitingText : PropTypes . string . isRequired
499
+ waitingText : PropTypes . string . isRequired ,
500
+ // Whether to show the retry/resume option if the action fails
501
+ allowRetry : PropTypes . bool ,
502
+ // If error, show the user the option to transition to this meal state
503
+ errorMealState : PropTypes . string ,
504
+ errorMealStateDescription : PropTypes . string
458
505
}
459
506
460
507
RobotMotion . defaultProps = {
508
+ allowRetry : true ,
461
509
debug : false
462
510
}
463
511
0 commit comments