@@ -39,18 +39,9 @@ export const APP_PAGE = {
39
39
* - R_DetectingFace: Waiting for the robot to detect a face.
40
40
* - R_MovingToMouth: Waiting for the robot to finish moving to the user's
41
41
* mouth.
42
- * - R_MovingFromMouthToStagingConfiguration : Waiting for the robot to move
42
+ * - R_MovingFromMouth : Waiting for the robot to move
43
43
* from the user's mouth to the staging configuration. This is a separate
44
- * action from R_MovingToStagingConfiguration to allow us to customize the
45
- * departure from the mouth (e.g., a slower speed).
46
- * - R_MovingFromMouthToAbovePlate: Waiting for the robot to move from the
47
- * user's mouth to above the plate. This is a separate action from
48
- * R_MovingAbovePlate to allow us to customize the departure from the mouth
49
- * (e.g., a slower speed).
50
- * - R_MovingFromMouthToRestingPosition: Waiting for the robot to move from
51
- * the user's mouth to resting position. This is a separate action from
52
- * R_MovingToRestingPosition to allow us to customize the departure from
53
- * the mouth (e.g., a slower speed).
44
+ * action from R_MovingToStagingConfiguration since it is cartesian.
54
45
* - U_BiteDone: Waiting for the user to indicate that they are done eating
55
46
* the bite.
56
47
* - R_StowingArm: Waiting for the robot to stow the arm.
@@ -67,14 +58,23 @@ export const MEAL_STATE = {
67
58
R_MovingToStagingConfiguration : 'R_MovingToStagingConfiguration' ,
68
59
R_DetectingFace : 'R_DetectingFace' ,
69
60
R_MovingToMouth : 'R_MovingToMouth' ,
70
- R_MovingFromMouthToStagingConfiguration : 'R_MovingFromMouthToStagingConfiguration' ,
71
- R_MovingFromMouthToAbovePlate : 'R_MovingFromMouthToAbovePlate' ,
72
- R_MovingFromMouthToRestingPosition : 'R_MovingFromMouthToRestingPosition' ,
61
+ R_MovingFromMouth : 'R_MovingFromMouth' ,
73
62
U_BiteDone : 'U_BiteDone' ,
74
63
R_StowingArm : 'R_StowingArm' ,
75
64
U_PostMeal : 'U_PostMeal'
76
65
}
77
66
67
+ /**
68
+ * SETTINGS_STATE controls which settings page to display.
69
+ * - MAIN: The main page, with options to navigate to the other pages.
70
+ * - BITE_TRANSFER: The bite transfer page, where the user can configure
71
+ * parameters for bite transfer.
72
+ */
73
+ export const SETTINGS_STATE = {
74
+ MAIN : 'MAIN' ,
75
+ BITE_TRANSFER : 'BITE_TRANSFER'
76
+ }
77
+
78
78
/**
79
79
* The parameters that users can set (keys) and a list of human-readable values
80
80
* they can take on.
@@ -90,11 +90,11 @@ export const MEAL_STATE = {
90
90
* TODO (amaln): When we connect this to ROS, each of these settings types and
91
91
* value options will have to have corresponding rosparam names and value options.
92
92
*/
93
- export const SETTINGS = {
94
- stagingPosition : [ 'In Front of Me' , 'On My Right Side' ] ,
95
- biteInitiation : [ 'Open Mouth' , 'Say "I am Ready"' , 'Press Button' ] ,
96
- biteSelection : [ 'Name of Food' , 'Click on Food' ]
97
- }
93
+ // export const SETTINGS = {
94
+ // stagingPosition: ['In Front of Me', 'On My Right Side'],
95
+ // biteInitiation: ['Open Mouth', 'Say "I am Ready"', 'Press Button'],
96
+ // biteSelection: ['Name of Food', 'Click on Food']
97
+ // }
98
98
99
99
/**
100
100
* useGlobalState is a hook to store and manipulate web app state that we want
@@ -104,12 +104,14 @@ export const SETTINGS = {
104
104
export const useGlobalState = create (
105
105
persist (
106
106
( set ) => ( {
107
+ // The current app page
108
+ appPage : APP_PAGE . Home ,
107
109
// The app's current meal state
108
110
mealState : MEAL_STATE . U_PreMeal ,
109
111
// The timestamp when the robot transitioned to its current meal state
110
112
mealStateTransitionTime : Date . now ( ) ,
111
- // The current app page
112
- appPage : APP_PAGE . Home ,
113
+ // The currently displayed settings page
114
+ settingsState : SETTINGS_STATE . MAIN ,
113
115
// The goal for the bite acquisition action, including the most recent
114
116
// food item that the user selected in "bite selection"
115
117
biteAcquisitionActionGoal : null ,
@@ -123,20 +125,44 @@ export const useGlobalState = create(
123
125
teleopIsMoving : false ,
124
126
// Flag to indicate whether to auto-continue after face detection
125
127
faceDetectionAutoContinue : false ,
128
+ // Whether the settings bite transfer page is currently at the user's face
129
+ // or not. This is in the off-chance that the mealState is not at the user's
130
+ // face, the settings page is, and the user refreshes -- the page should
131
+ // call MoveFromMouthToStaging instead of just MoveToStaging.
132
+ biteTransferPageAtFace : false ,
133
+ // The button the user most recently clicked on the BiteDone page. In practice,
134
+ // this is the state we transition to after R_MovingFromMouth. In practice,
135
+ // it is either R_MovingAbovePlate, R_MovingToRestingPosition, or R_DetectingFace.
136
+ mostRecentBiteDoneResponse : MEAL_STATE . R_DetectingFace ,
126
137
// Settings values
127
- stagingPosition : SETTINGS . stagingPosition [ 0 ] ,
128
- biteInitiation : SETTINGS . biteInitiation [ 0 ] ,
129
- biteSelection : SETTINGS . biteSelection [ 0 ] ,
138
+ // stagingPosition: SETTINGS.stagingPosition[0],
139
+ // biteInitiation: SETTINGS.biteInitiation[0],
140
+ // biteSelection: SETTINGS.biteSelection[0],
130
141
131
142
// Setters for global state
132
- setMealState : ( mealState ) =>
143
+ setAppPage : ( appPage ) =>
133
144
set ( ( ) => ( {
134
- mealState : mealState ,
135
- mealStateTransitionTime : Date . now ( )
145
+ appPage : appPage ,
146
+ settingsState : SETTINGS_STATE . MAIN ,
147
+ // Sometimes the settings menu leaves the robot in a paused state.
148
+ // Thus, we reset it to an unpaused state.
149
+ paused : false
136
150
} ) ) ,
137
- setAppPage : ( appPage ) =>
151
+ setMealState : ( mealState , mostRecentBiteDoneResponse = null ) =>
152
+ set ( ( ) => {
153
+ let retval = {
154
+ mealState : mealState ,
155
+ mealStateTransitionTime : Date . now ( ) ,
156
+ biteTransferPageAtFace : false // Reset this flag when the meal state changes
157
+ }
158
+ if ( mostRecentBiteDoneResponse ) {
159
+ retval . mostRecentBiteDoneResponse = mostRecentBiteDoneResponse
160
+ }
161
+ return retval
162
+ } ) ,
163
+ setSettingsState : ( settingsState ) =>
138
164
set ( ( ) => ( {
139
- appPage : appPage
165
+ settingsState : settingsState
140
166
} ) ) ,
141
167
setBiteAcquisitionActionGoal : ( biteAcquisitionActionGoal ) =>
142
168
set ( ( ) => ( {
@@ -158,18 +184,22 @@ export const useGlobalState = create(
158
184
set ( ( ) => ( {
159
185
faceDetectionAutoContinue : faceDetectionAutoContinue
160
186
} ) ) ,
161
- setStagingPosition : ( stagingPosition ) =>
162
- set ( ( ) => ( {
163
- stagingPosition : stagingPosition
164
- } ) ) ,
165
- setBiteInitiation : ( biteInitiation ) =>
166
- set ( ( ) => ( {
167
- biteInitiation : biteInitiation
168
- } ) ) ,
169
- setBiteSelection : ( biteSelection ) =>
187
+ setBiteTransferPageAtFace : ( biteTransferPageAtFace ) =>
170
188
set ( ( ) => ( {
171
- biteSelection : biteSelection
189
+ biteTransferPageAtFace : biteTransferPageAtFace
172
190
} ) )
191
+ // setStagingPosition: (stagingPosition) =>
192
+ // set(() => ({
193
+ // stagingPosition: stagingPosition
194
+ // })),
195
+ // setBiteInitiation: (biteInitiation) =>
196
+ // set(() => ({
197
+ // biteInitiation: biteInitiation
198
+ // })),
199
+ // setBiteSelection: (biteSelection) =>
200
+ // set(() => ({
201
+ // biteSelection: biteSelection
202
+ // }))
173
203
} ) ,
174
204
{ name : 'ada_web_app_global_state' }
175
205
)
0 commit comments