@@ -59,6 +59,10 @@ const RobotMotion = (props) => {
59
59
actionStatus : null
60
60
} )
61
61
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
+
62
66
// Get the relevant global variables
63
67
const paused = useGlobalState ( ( state ) => state . paused )
64
68
const setPaused = useGlobalState ( ( state ) => state . setPaused )
@@ -147,6 +151,10 @@ const RobotMotion = (props) => {
147
151
*/
148
152
const responseCallback = useCallback (
149
153
( response ) => {
154
+ if ( actionCallCount . current === 0 ) {
155
+ console . log ( 'Ignoring response message because an action has not yet been called' , response )
156
+ return
157
+ }
150
158
console . log ( 'Got response message' , response )
151
159
if ( response . response_type === 'result' && response . values . status === MOTION_STATUS_SUCCESS ) {
152
160
setActionStatus ( {
@@ -173,7 +181,7 @@ const RobotMotion = (props) => {
173
181
}
174
182
}
175
183
} ,
176
- [ setLastMotionActionResponse , setActionStatus , setPaused , robotMotionDone ]
184
+ [ actionCallCount , setLastMotionActionResponse , setActionStatus , setPaused , robotMotionDone ]
177
185
)
178
186
179
187
/**
@@ -203,14 +211,15 @@ const RobotMotion = (props) => {
203
211
const callRobotMotionAction = useCallback (
204
212
( feedbackCb , responseCb ) => {
205
213
if ( ! paused ) {
214
+ actionCallCount . current += 1
206
215
setActionStatus ( {
207
216
actionStatus : ROS_ACTION_STATUS_EXECUTE
208
217
} )
209
218
console . log ( 'Calling action with input' , props . actionInput )
210
219
callROSAction ( robotMotionAction , props . actionInput , feedbackCb , responseCb )
211
220
}
212
221
} ,
213
- [ paused , robotMotionAction , props . actionInput ]
222
+ [ actionCallCount , paused , robotMotionAction , props . actionInput ]
214
223
)
215
224
216
225
/**
0 commit comments