Skip to content

Commit 5c7bbcd

Browse files
committed
Allow users to skip acquisition on error
1 parent 17e17ce commit 5c7bbcd

File tree

3 files changed

+71
-22
lines changed

3 files changed

+71
-22
lines changed

feedingwebapp/src/Pages/Constants.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ export const SERVO_CARTESIAN_TOPIC_MSG = 'geometry_msgs/msg/TwistStamped'
4343
export const SERVO_JOINT_TOPIC = '/web_app/servo_node/delta_joint_cmds'
4444
export const SERVO_JOINT_TOPIC_MSG = 'control_msgs/msg/JointJog'
4545

46-
// States from which, if they fail, it is NOT okay for the user to retry the
47-
// same action.
48-
let NON_RETRYABLE_STATES = new Set()
49-
NON_RETRYABLE_STATES.add(MEAL_STATE.R_BiteAcquisition)
50-
export { NON_RETRYABLE_STATES }
51-
5246
/**
5347
* For states that call ROS actions, this dictionary contains
5448
* the action name and the message type

feedingwebapp/src/Pages/Home/Home.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ function Home(props) {
118118
let currentMealState = MEAL_STATE.R_BiteAcquisition
119119
let nextMealState = MEAL_STATE.U_BiteAcquisitionCheck
120120
let backMealState = MEAL_STATE.R_MovingAbovePlate
121+
let errorMealState = MEAL_STATE.R_MovingToRestingPosition
122+
let errorMealStateDescription = 'Proceed'
121123
return (
122124
<RobotMotion
123125
debug={props.debug}
@@ -127,6 +129,9 @@ function Home(props) {
127129
backMealState={backMealState}
128130
actionInput={biteAcquisitionActionInput}
129131
waitingText={getRobotMotionText(currentMealState)}
132+
allowRetry={false} // Don't allow retrying bite acquisition
133+
errorMealState={errorMealState}
134+
errorMealStateDescription={errorMealStateDescription}
130135
/>
131136
)
132137
}

feedingwebapp/src/Pages/Home/MealStates/RobotMotion.jsx

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { useGlobalState } from '../../GlobalState'
2222
import {
2323
CLEAR_OCTOMAP_SERVICE_NAME,
2424
CLEAR_OCTOMAP_SERVICE_TYPE,
25-
NON_RETRYABLE_STATES,
2625
ROS_ACTIONS_NAMES,
2726
MOTION_STATUS_SUCCESS,
2827
ROS_ACTION_STATUS_CANCEL_GOAL,
@@ -124,15 +123,28 @@ const RobotMotion = (props) => {
124123
[setActionStatus]
125124
)
126125

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+
127141
/**
128142
* Callback function for when the robot has finished moving to its staging
129143
* location.
130144
*/
131145
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])
136148

137149
/**
138150
* Callback function for when the action sends a response. It updates the
@@ -264,10 +276,8 @@ const RobotMotion = (props) => {
264276
}, [clearOctomapService, resumeCallback])
265277

266278
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])
271281

272282
/**
273283
* Get the action status text and progress bar or blank view to render.
@@ -310,6 +320,22 @@ const RobotMotion = (props) => {
310320
) : (
311321
<></>
312322
)}
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+
)}
313339
</View>
314340
<View
315341
style={{
@@ -326,7 +352,16 @@ const RobotMotion = (props) => {
326352
</>
327353
)
328354
},
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+
]
330365
)
331366

332367
/**
@@ -342,7 +377,6 @@ const RobotMotion = (props) => {
342377
let showTime = false
343378
let time = 0
344379
let progress = null
345-
let retry = false
346380
switch (actionStatus.actionStatus) {
347381
case ROS_ACTION_STATUS_EXECUTE:
348382
if (actionStatus.feedback) {
@@ -377,9 +411,19 @@ const RobotMotion = (props) => {
377411
* users on how to troubleshoot/fix it.
378412
*/
379413
text = 'Robot encountered an error'
380-
retry = NON_RETRYABLE_STATES.has(props.mealState) ? false : true
381414
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+
</>
383427
)
384428
case ROS_ACTION_STATUS_CANCELED:
385429
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress)}</>
@@ -397,7 +441,7 @@ const RobotMotion = (props) => {
397441
}
398442
}
399443
},
400-
[paused, dimension, actionStatusTextAndVisual, props.mealState]
444+
[paused, dimension, actionStatusTextAndVisual, props.allowRetry]
401445
)
402446

403447
// Render the component
@@ -421,7 +465,7 @@ const RobotMotion = (props) => {
421465
pauseCallback={pauseCallback}
422466
backCallback={props.backMealState ? backCallback : null}
423467
backMealState={props.backMealState}
424-
resumeCallback={NON_RETRYABLE_STATES.has(props.mealState) ? null : resumeCallback}
468+
resumeCallback={props.allowRetry ? resumeCallback : null}
425469
paused={paused}
426470
/>
427471
</>
@@ -454,10 +498,16 @@ RobotMotion.propTypes = {
454498
// the action client, then calling it again, etc.)
455499
actionInput: PropTypes.object.isRequired,
456500
// 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
458507
}
459508

460509
RobotMotion.defaultProps = {
510+
allowRetry: true,
461511
debug: false
462512
}
463513

0 commit comments

Comments
 (0)