@@ -9,6 +9,7 @@ import { useGlobalState, MEAL_STATE } from '../GlobalState'
9
9
import BiteAcquisitionCheck from './MealStates/BiteAcquisitionCheck'
10
10
import BiteDone from './MealStates/BiteDone'
11
11
import BiteSelection from './MealStates/BiteSelection'
12
+ import DetectingFace from './MealStates/DetectingFace'
12
13
import PlateLocator from './MealStates/PlateLocator'
13
14
import PostMeal from './MealStates/PostMeal'
14
15
import PreMeal from './MealStates/PreMeal'
@@ -28,6 +29,8 @@ function Home(props) {
28
29
// Get the relevant values from global state
29
30
const mealState = useGlobalState ( ( state ) => state . mealState )
30
31
const mealStateTransitionTime = useGlobalState ( ( state ) => state . mealStateTransitionTime )
32
+ const setBiteAcquisitionActionGoal = useGlobalState ( ( state ) => state . setBiteAcquisitionActionGoal )
33
+ const setMoveToMouthActionGoal = useGlobalState ( ( state ) => state . setMoveToMouthActionGoal )
31
34
const setMealState = useGlobalState ( ( state ) => state . setMealState )
32
35
const setPaused = useGlobalState ( ( state ) => state . setPaused )
33
36
@@ -40,23 +43,27 @@ function Home(props) {
40
43
useEffect ( ( ) => {
41
44
if ( Date . now ( ) - mealStateTransitionTime >= TIME_TO_RESET_MS ) {
42
45
console . log ( 'Reverting to PreMeal due to too much elapsed time in one state.' )
46
+ setBiteAcquisitionActionGoal ( null )
47
+ setMoveToMouthActionGoal ( null )
43
48
setMealState ( MEAL_STATE . U_PreMeal )
44
49
setPaused ( false )
45
50
}
46
- } , [ mealStateTransitionTime , setMealState , setPaused ] )
51
+ } , [ mealStateTransitionTime , setMealState , setPaused , setMoveToMouthActionGoal , setBiteAcquisitionActionGoal ] )
47
52
48
53
// Get the relevant global variables
49
- const desiredFoodItem = useGlobalState ( ( state ) => state . desiredFoodItem )
54
+ const biteAcquisitionActionGoal = useGlobalState ( ( state ) => state . biteAcquisitionActionGoal )
55
+ const moveToMouthActionGoal = useGlobalState ( ( state ) => state . moveToMouthActionGoal )
50
56
51
57
/**
52
58
* All action inputs are constant. Note that we must be cautious if making
53
59
* them non-constant, because the robot will re-execute an action every time
54
60
* the action input changes (even on re-renders).
55
61
*/
56
62
const moveAbovePlateActionInput = useMemo ( ( ) => ( { } ) , [ ] )
57
- const biteAcquisitionActionInput = useMemo ( ( ) => desiredFoodItem , [ desiredFoodItem ] )
63
+ const biteAcquisitionActionInput = useMemo ( ( ) => biteAcquisitionActionGoal , [ biteAcquisitionActionGoal ] )
58
64
const moveToRestingPositionActionInput = useMemo ( ( ) => ( { } ) , [ ] )
59
- const moveToMouthActionInput = useMemo ( ( ) => ( { } ) , [ ] )
65
+ const moveToStagingConfigurationActionInput = useMemo ( ( ) => ( { } ) , [ ] )
66
+ const moveToMouthActionInput = useMemo ( ( ) => moveToMouthActionGoal , [ moveToMouthActionGoal ] )
60
67
const moveToStowPositionActionInput = useMemo ( ( ) => ( { } ) , [ ] )
61
68
62
69
/**
@@ -127,6 +134,27 @@ function Home(props) {
127
134
case MEAL_STATE . U_BiteAcquisitionCheck : {
128
135
return < BiteAcquisitionCheck debug = { props . debug } />
129
136
}
137
+ case MEAL_STATE . R_MovingToStagingConfiguration : {
138
+ /**
139
+ * We recreate currentMealState due to a race condition where sometimes
140
+ * the app is performing a re-rendering and *then* the state is updated.
141
+ */
142
+ let currentMealState = MEAL_STATE . R_MovingToStagingConfiguration
143
+ let nextMealState = MEAL_STATE . R_DetectingFace
144
+ let waitingText = 'Waiting to move in front of you...'
145
+ return (
146
+ < RobotMotion
147
+ debug = { props . debug }
148
+ mealState = { currentMealState }
149
+ nextMealState = { nextMealState }
150
+ actionInput = { moveToStagingConfigurationActionInput }
151
+ waitingText = { waitingText }
152
+ />
153
+ )
154
+ }
155
+ case MEAL_STATE . R_DetectingFace : {
156
+ return < DetectingFace debug = { props . debug } webVideoServerURL = { props . webVideoServerURL } />
157
+ }
130
158
case MEAL_STATE . R_MovingToMouth : {
131
159
/**
132
160
* We recreate currentMealState due to a race condition where sometimes
@@ -145,6 +173,24 @@ function Home(props) {
145
173
/>
146
174
)
147
175
}
176
+ case MEAL_STATE . R_MovingFromMouthToStagingConfiguration : {
177
+ /**
178
+ * We recreate currentMealState due to a race condition where sometimes
179
+ * the app is performing a re-rendering and *then* the state is updated.
180
+ */
181
+ let currentMealState = MEAL_STATE . R_MovingFromMouthToStagingConfiguration
182
+ let nextMealState = MEAL_STATE . R_DetectingFace
183
+ let waitingText = 'Waiting to move from your mouth to in front of you...'
184
+ return (
185
+ < RobotMotion
186
+ debug = { props . debug }
187
+ mealState = { currentMealState }
188
+ nextMealState = { nextMealState }
189
+ actionInput = { moveToStagingConfigurationActionInput }
190
+ waitingText = { waitingText }
191
+ />
192
+ )
193
+ }
148
194
case MEAL_STATE . R_MovingFromMouthToAbovePlate : {
149
195
/**
150
196
* We recreate currentMealState due to a race condition where sometimes
@@ -213,7 +259,8 @@ function Home(props) {
213
259
moveAbovePlateActionInput ,
214
260
moveToMouthActionInput ,
215
261
moveToRestingPositionActionInput ,
216
- moveToStowPositionActionInput
262
+ moveToStowPositionActionInput ,
263
+ moveToStagingConfigurationActionInput
217
264
] )
218
265
219
266
// Render the component
0 commit comments