Skip to content

Commit d4c344c

Browse files
committed
Prevent RobotMotion modal from starting in pause when customizing
1 parent 1d295fc commit d4c344c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ const RobotMotion = (props) => {
5959
actionStatus: null
6060
})
6161

62+
// Track the number of times the action has been called, to ensure that we do not
63+
// process responses that are received before the action is called.
64+
const actionCallCount = useRef(0)
65+
6266
// Get the relevant global variables
6367
const paused = useGlobalState((state) => state.paused)
6468
const setPaused = useGlobalState((state) => state.setPaused)
@@ -147,6 +151,10 @@ const RobotMotion = (props) => {
147151
*/
148152
const responseCallback = useCallback(
149153
(response) => {
154+
if (actionCallCount.current === 0) {
155+
console.log('Ignoring response message because an action has not yet been called', response)
156+
return
157+
}
150158
console.log('Got response message', response)
151159
if (response.response_type === 'result' && response.values.status === MOTION_STATUS_SUCCESS) {
152160
setActionStatus({
@@ -173,7 +181,7 @@ const RobotMotion = (props) => {
173181
}
174182
}
175183
},
176-
[setLastMotionActionResponse, setActionStatus, setPaused, robotMotionDone]
184+
[actionCallCount, setLastMotionActionResponse, setActionStatus, setPaused, robotMotionDone]
177185
)
178186

179187
/**
@@ -203,14 +211,15 @@ const RobotMotion = (props) => {
203211
const callRobotMotionAction = useCallback(
204212
(feedbackCb, responseCb) => {
205213
if (!paused) {
214+
actionCallCount.current += 1
206215
setActionStatus({
207216
actionStatus: ROS_ACTION_STATUS_EXECUTE
208217
})
209218
console.log('Calling action with input', props.actionInput)
210219
callROSAction(robotMotionAction, props.actionInput, feedbackCb, responseCb)
211220
}
212221
},
213-
[paused, robotMotionAction, props.actionInput]
222+
[actionCallCount, paused, robotMotionAction, props.actionInput]
214223
)
215224

216225
/**

0 commit comments

Comments
 (0)