@@ -26,8 +26,6 @@ export const APP_PAGE = {
26
26
* - U_PreMeal: Waiting for the user to click "Start Feeding."
27
27
* - R_MovingAbovePlate: Waiting for the robot to move above the plate.
28
28
* - U_BiteSelection: Waiting for the user to select the food item they want.
29
- * - U_PlateLocator: Allows the user to teleoperate the robot to center the
30
- * the plate.
31
29
* - R_BiteAcquisition: Waiting for the robot to execute one bite acquisition
32
30
* attempt.
33
31
* - R_MovingToRestingPosition: Waiting for the robot to move to resting
@@ -51,7 +49,6 @@ export const MEAL_STATE = {
51
49
U_PreMeal : 'U_PreMeal' ,
52
50
R_MovingAbovePlate : 'R_MovingAbovePlate' ,
53
51
U_BiteSelection : 'U_BiteSelection' ,
54
- U_PlateLocator : 'U_PlateLocator' ,
55
52
R_BiteAcquisition : 'R_BiteAcquisition' ,
56
53
R_MovingToRestingPosition : 'R_MovingToRestingPosition' ,
57
54
U_BiteAcquisitionCheck : 'U_BiteAcquisitionCheck' ,
@@ -64,6 +61,18 @@ export const MEAL_STATE = {
64
61
U_PostMeal : 'U_PostMeal'
65
62
}
66
63
64
+ /**
65
+ * A set containing the states where the robot does not move.
66
+ */
67
+ let NON_MOVING_STATES = new Set ( )
68
+ NON_MOVING_STATES . add ( MEAL_STATE . U_PreMeal )
69
+ NON_MOVING_STATES . add ( MEAL_STATE . U_BiteSelection )
70
+ NON_MOVING_STATES . add ( MEAL_STATE . U_BiteAcquisitionCheck )
71
+ NON_MOVING_STATES . add ( MEAL_STATE . R_DetectingFace )
72
+ NON_MOVING_STATES . add ( MEAL_STATE . U_BiteDone )
73
+ NON_MOVING_STATES . add ( MEAL_STATE . U_PostMeal )
74
+ export { NON_MOVING_STATES }
75
+
67
76
/**
68
77
* SETTINGS_STATE controls which settings page to display.
69
78
* - MAIN: The main page, with options to navigate to the other pages.
@@ -72,7 +81,8 @@ export const MEAL_STATE = {
72
81
*/
73
82
export const SETTINGS_STATE = {
74
83
MAIN : 'MAIN' ,
75
- BITE_TRANSFER : 'BITE_TRANSFER'
84
+ BITE_TRANSFER : 'BITE_TRANSFER' ,
85
+ ABOVE_PLATE : 'ABOVE_PLATE'
76
86
}
77
87
78
88
// The name of the default parameter namespace
@@ -92,6 +102,9 @@ export const useGlobalState = create(
92
102
mealState : MEAL_STATE . U_PreMeal ,
93
103
// The app's previous meal state
94
104
prevMealState : null ,
105
+ // Whether the app is currently in a non-moving state (i.e., the robot will
106
+ // not move unless the user initiates it)
107
+ inNonMovingState : true ,
95
108
// The timestamp when the robot transitioned to its current meal state
96
109
mealStateTransitionTime : Date . now ( ) ,
97
110
// The currently displayed settings page
@@ -106,10 +119,14 @@ export const useGlobalState = create(
106
119
moveToMouthActionGoal : null ,
107
120
// Last RobotMotion action response
108
121
lastMotionActionResponse : null ,
109
- // Whether or not the currently-executing robot motion was paused by the user
122
+ // Whether or not the currently-executing robot motion was paused by the user.
123
+ // NOTE: `paused` may no longer need to be in global state now that we have
124
+ // the `inNonMovingState` flag.
110
125
paused : false ,
111
- // Flag to indicate robot motion trough teleoperation interface
112
- teleopIsMoving : false ,
126
+ // Store the user;s current settings for teleop speeds
127
+ teleopLinearSpeed : 0.1 , // m/s
128
+ teleopAngularSpeed : 0.15 , // rad/s
129
+ teleopJointSpeed : 0.2 , // rad/s
113
130
// Flag to indicate whether to auto-continue after face detection
114
131
faceDetectionAutoContinue : true ,
115
132
// Flag to indicate whether to auto-continue in bite done after food-on-fork detection
@@ -145,17 +162,37 @@ export const useGlobalState = create(
145
162
} ) ) ,
146
163
setMealState : ( mealState , mostRecentBiteDoneResponse = null ) =>
147
164
set ( ( ) => {
165
+ let prevMealState = get ( ) . mealState
166
+ console . log ( 'Setting meal state to' , mealState , 'from' , prevMealState )
148
167
let retval = {
149
168
mealState : mealState ,
150
- prevMealState : get ( ) . mealState ,
151
169
mealStateTransitionTime : Date . now ( ) ,
152
170
biteTransferPageAtFace : false // Reset this flag when the meal state changes
153
171
}
172
+ // Only update the previous state if it is not a self-transition (to
173
+ // account for cases where a MoveTo action result message is reveived twice)
174
+ if ( prevMealState !== mealState ) {
175
+ retval . prevMealState = prevMealState
176
+ }
154
177
if ( mostRecentBiteDoneResponse ) {
155
178
retval . mostRecentBiteDoneResponse = mostRecentBiteDoneResponse
156
179
}
180
+ if ( NON_MOVING_STATES . has ( mealState ) ) {
181
+ retval . inNonMovingState = true
182
+ console . log ( 'Setting inNonMovingState to true through setMealState' )
183
+ } else {
184
+ retval . inNonMovingState = false
185
+ console . log ( 'Setting inNonMovingState to false through setMealState' )
186
+ }
157
187
return retval
158
188
} ) ,
189
+ setInNonMovingState : ( inNonMovingState ) =>
190
+ set ( ( ) => {
191
+ console . log ( 'Setting inNonMovingState to' , inNonMovingState , 'through setInNonMovingState' )
192
+ return {
193
+ inNonMovingState : inNonMovingState
194
+ }
195
+ } ) ,
159
196
setSettingsState : ( settingsState ) =>
160
197
set ( ( ) => ( {
161
198
settingsState : settingsState
@@ -177,12 +214,34 @@ export const useGlobalState = create(
177
214
moveToMouthActionGoal : moveToMouthActionGoal
178
215
} ) ) ,
179
216
setPaused : ( paused ) =>
217
+ set ( ( ) => {
218
+ let retval = { paused : paused }
219
+ if ( paused ) {
220
+ // If the robot is paused, we should store this as a non-moving state
221
+ retval . inNonMovingState = true
222
+ } else {
223
+ // If the robot is unpaused, we should check if the meal state is moving
224
+ if ( ! NON_MOVING_STATES . has ( get ( ) . mealState ) ) {
225
+ retval . inNonMovingState = false
226
+ console . log ( 'Setting inNonMovingState to false through setPaused' )
227
+ } else {
228
+ retval . inNonMovingState = true
229
+ console . log ( 'Setting inNonMovingState to true through setPaused' )
230
+ }
231
+ }
232
+ return retval
233
+ } ) ,
234
+ setTeleopLinearSpeed : ( teleopLinearSpeed ) =>
235
+ set ( ( ) => ( {
236
+ teleopLinearSpeed : teleopLinearSpeed
237
+ } ) ) ,
238
+ setTeleopAngularSpeed : ( teleopAngularSpeed ) =>
180
239
set ( ( ) => ( {
181
- paused : paused
240
+ teleopAngularSpeed : teleopAngularSpeed
182
241
} ) ) ,
183
- setTeleopIsMoving : ( teleopIsMoving ) =>
242
+ setTeleopJointSpeed : ( teleopJointSpeed ) =>
184
243
set ( ( ) => ( {
185
- teleopIsMoving : teleopIsMoving
244
+ teleopJointSpeed : teleopJointSpeed
186
245
} ) ) ,
187
246
setFaceDetectionAutoContinue : ( faceDetectionAutoContinue ) =>
188
247
set ( ( ) => ( {
0 commit comments