Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Prevent RobotMotion modal from starting in pause when customizing #143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions feedingwebapp/src/Pages/Home/MealStates/RobotMotion.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const RobotMotion = (props) => {
actionStatus: null
})

// Track the number of times the action has been called, to ensure that we do not
// process responses that are received before the action is called.
const actionCallCount = useRef(0)

// Get the relevant global variables
const paused = useGlobalState((state) => state.paused)
const setPaused = useGlobalState((state) => state.setPaused)
Expand Down Expand Up @@ -147,6 +151,10 @@ const RobotMotion = (props) => {
*/
const responseCallback = useCallback(
(response) => {
if (actionCallCount.current === 0) {
console.log('Ignoring response message because an action has not yet been called', response)
return
}
console.log('Got response message', response)
if (response.response_type === 'result' && response.values.status === MOTION_STATUS_SUCCESS) {
setActionStatus({
Expand All @@ -173,7 +181,7 @@ const RobotMotion = (props) => {
}
}
},
[setLastMotionActionResponse, setActionStatus, setPaused, robotMotionDone]
[actionCallCount, setLastMotionActionResponse, setActionStatus, setPaused, robotMotionDone]
)

/**
Expand Down Expand Up @@ -203,14 +211,15 @@ const RobotMotion = (props) => {
const callRobotMotionAction = useCallback(
(feedbackCb, responseCb) => {
if (!paused) {
actionCallCount.current += 1
setActionStatus({
actionStatus: ROS_ACTION_STATUS_EXECUTE
})
console.log('Calling action with input', props.actionInput)
callROSAction(robotMotionAction, props.actionInput, feedbackCb, responseCb)
}
},
[paused, robotMotionAction, props.actionInput]
[actionCallCount, paused, robotMotionAction, props.actionInput]
)

/**
Expand Down
Loading