@@ -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.
@@ -310,6 +320,22 @@ const RobotMotion = (props) => {
310
320
) : (
311
321
< > </ >
312
322
) }
323
+ { props . errorMealState ? (
324
+ < Button
325
+ variant = 'warning'
326
+ className = 'mx-2 btn-huge'
327
+ size = 'lg'
328
+ onClick = { ( ) => changeMealState ( props . errorMealState , 'errorMealState' ) }
329
+ style = { {
330
+ width : '90%' ,
331
+ height : '20%'
332
+ } }
333
+ >
334
+ < h5 style = { { textAlign : 'center' , fontSize : motionTextFontSize } } > { props . errorMealStateDescription } </ h5 >
335
+ </ Button >
336
+ ) : (
337
+ < > </ >
338
+ ) }
313
339
</ View >
314
340
< View
315
341
style = { {
@@ -326,7 +352,16 @@ const RobotMotion = (props) => {
326
352
</ >
327
353
)
328
354
} ,
329
- [ dimension , props . waitingText , motionTextFontSize , waitingTextFontSize , retryCallback ]
355
+ [
356
+ dimension ,
357
+ props . waitingText ,
358
+ props . errorMealState ,
359
+ props . errorMealStateDescription ,
360
+ motionTextFontSize ,
361
+ waitingTextFontSize ,
362
+ retryCallback ,
363
+ changeMealState
364
+ ]
330
365
)
331
366
332
367
/**
@@ -342,7 +377,6 @@ const RobotMotion = (props) => {
342
377
let showTime = false
343
378
let time = 0
344
379
let progress = null
345
- let retry = false
346
380
switch ( actionStatus . actionStatus ) {
347
381
case ROS_ACTION_STATUS_EXECUTE :
348
382
if ( actionStatus . feedback ) {
@@ -377,9 +411,19 @@ const RobotMotion = (props) => {
377
411
* users on how to troubleshoot/fix it.
378
412
*/
379
413
text = 'Robot encountered an error'
380
- retry = NON_RETRYABLE_STATES . has ( props . mealState ) ? false : true
381
414
return (
382
- < > { actionStatusTextAndVisual ( flexSizeOuter , flexSizeTextInner , flexSizeVisualInner , text , showTime , time , progress , retry ) } </ >
415
+ < >
416
+ { actionStatusTextAndVisual (
417
+ flexSizeOuter ,
418
+ flexSizeTextInner ,
419
+ flexSizeVisualInner ,
420
+ text ,
421
+ showTime ,
422
+ time ,
423
+ progress ,
424
+ props . allowRetry
425
+ ) }
426
+ </ >
383
427
)
384
428
case ROS_ACTION_STATUS_CANCELED :
385
429
return < > { actionStatusTextAndVisual ( flexSizeOuter , flexSizeTextInner , flexSizeVisualInner , text , showTime , time , progress ) } </ >
@@ -397,7 +441,7 @@ const RobotMotion = (props) => {
397
441
}
398
442
}
399
443
} ,
400
- [ paused , dimension , actionStatusTextAndVisual , props . mealState ]
444
+ [ paused , dimension , actionStatusTextAndVisual , props . allowRetry ]
401
445
)
402
446
403
447
// Render the component
@@ -421,7 +465,7 @@ const RobotMotion = (props) => {
421
465
pauseCallback = { pauseCallback }
422
466
backCallback = { props . backMealState ? backCallback : null }
423
467
backMealState = { props . backMealState }
424
- resumeCallback = { NON_RETRYABLE_STATES . has ( props . mealState ) ? null : resumeCallback }
468
+ resumeCallback = { props . allowRetry ? resumeCallback : null }
425
469
paused = { paused }
426
470
/>
427
471
</ >
@@ -454,10 +498,16 @@ RobotMotion.propTypes = {
454
498
// the action client, then calling it again, etc.)
455
499
actionInput : PropTypes . object . isRequired ,
456
500
// The static text to display while the robot is executing the action
457
- waitingText : PropTypes . string . isRequired
501
+ waitingText : PropTypes . string . isRequired ,
502
+ // Whether to show the retry/resume option if the action fails
503
+ allowRetry : PropTypes . bool ,
504
+ // If error, show the user the option to transition to this meal state
505
+ errorMealState : PropTypes . string ,
506
+ errorMealStateDescription : PropTypes . string
458
507
}
459
508
460
509
RobotMotion . defaultProps = {
510
+ allowRetry : true ,
461
511
debug : false
462
512
}
463
513
0 commit comments