Skip to content

Commit b65a9ef

Browse files
authored
Added staging configuration customization (#136)
* Added staging configuration customization * [WIP] fixes from in-person testing * Added another food pic * Remove unnecessary comment * Remove unnecessary comments * Update comments * Removed unnecessary and expensive log * Ignore build folder when formatting * Fixes from in-person testing * Renamed settingsPageAtFace to settingsPageAtMouth
1 parent b5ddf35 commit b65a9ef

16 files changed

+425
-222
lines changed
Loading
Loading

feedingwebapp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"test": "react-scripts test",
4848
"eject": "react-scripts eject",
4949
"lint:fix": "eslint \"{,!(node_modules)/**/}*.{js,jsx}\" --fix",
50-
"prettier:fix": "prettier \"{,!(node_modules)/**/}*.{js,jsx,css}\" --write --config ./.prettierrc",
50+
"prettier:fix": "prettier \"{,!(node_modules)/**/}*.{js,jsx,css}\" --write --config ./.prettierrc --ignore-path ./.gitignore",
5151
"format": "npm run prettier:fix && npm run lint:fix"
5252
},
5353
"eslintConfig": {

feedingwebapp/src/Pages/Constants.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ export const CLEAR_OCTOMAP_SERVICE_NAME = 'clear_octomap'
118118
export const CLEAR_OCTOMAP_SERVICE_TYPE = 'std_srvs/srv/Empty'
119119
export const ACQUISITION_REPORT_SERVICE_NAME = 'ada_feeding_action_select/action_report'
120120
export const ACQUISITION_REPORT_SERVICE_TYPE = 'ada_feeding_msgs/srv/AcquisitionReport'
121-
export const GET_JOINT_STATE_SERVICE_NAME = 'get_joint_state'
122-
export const GET_JOINT_STATE_SERVICE_TYPE = 'ada_feeding_msgs/srv/GetJointState'
121+
export const GET_ROBOT_STATE_SERVICE_NAME = 'get_robot_state'
122+
export const GET_ROBOT_STATE_SERVICE_TYPE = 'ada_feeding_msgs/srv/GetRobotState'
123123
export const GET_PARAMETERS_SERVICE_NAME = 'ada_feeding_action_servers/get_parameters'
124124
export const GET_PARAMETERS_SERVICE_TYPE = 'rcl_interfaces/srv/GetParameters'
125-
export const SET_PARAMETERS_SERVICE_NAME = 'ada_feeding_action_servers/set_parameters'
126-
export const SET_PARAMETERS_SERVICE_TYPE = 'rcl_interfaces/srv/SetParameters'
125+
export const SET_PARAMETERS_SERVICE_NAME = 'ada_feeding_action_servers/set_parameters_atomically'
126+
export const SET_PARAMETERS_SERVICE_TYPE = 'rcl_interfaces/srv/SetParametersAtomically'
127127

128128
// The names of parameters users can change in the settings menu
129129
export const DISTANCE_TO_MOUTH_PARAM = 'MoveToMouth.tree_kwargs.plan_distance_from_mouth'
@@ -139,6 +139,7 @@ export const RESTING_PARAM_JOINTS_2 = 'MoveToRestingPosition.tree_kwargs.goal_co
139139

140140
// Robot link names
141141
export const ROBOT_BASE_LINK = 'j2n6s200_link_base'
142+
export const ROBOT_END_EFFECTOR = 'forkTip'
142143
export const ROBOT_JOINTS = [
143144
'j2n6s200_joint_1',
144145
'j2n6s200_joint_2',

feedingwebapp/src/Pages/GlobalState.jsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ export const SETTINGS_STATE = {
8383
MAIN: 'MAIN',
8484
BITE_TRANSFER: 'BITE_TRANSFER',
8585
ABOVE_PLATE: 'ABOVE_PLATE',
86-
RESTING_CONFIGURATION: 'RESTING_CONFIGURATION'
86+
RESTING_CONFIGURATION: 'RESTING_CONFIGURATION',
87+
STAGING_CONFIGURATION: 'STAGING_CONFIGURATION'
8788
}
8889

8990
// The name of the default parameter namespace
@@ -140,11 +141,11 @@ export const useGlobalState = create(
140141
biteAcquisitionCheckAutoContinueSecs: 3.0,
141142
biteAcquisitionCheckAutoContinueProbThreshLower: 0.25,
142143
biteAcquisitionCheckAutoContinueProbThreshUpper: 0.75,
143-
// Whether the settings bite transfer page is currently at the user's face
144+
// Whether any of the settings pages is currently at the user's mouth
144145
// or not. This is in the off-chance that the mealState is not at the user's
145-
// face, the settings page is, and the user refreshes -- the page should
146-
// call MoveFromMouthToStaging instead of just MoveToStaging.
147-
biteTransferPageAtFace: false,
146+
// mouth, the settings page is, and the user refreshes -- the page should
147+
// call MoveFromMouth instead of just MoveToStaging.
148+
settingsPageAtMouth: false,
148149
// The button the user most recently clicked on the BiteDone page. In practice,
149150
// this is the state we transition to after R_MovingFromMouth. In practice,
150151
// it is either R_MovingAbovePlate, R_MovingToRestingPosition, or R_DetectingFace.
@@ -168,7 +169,7 @@ export const useGlobalState = create(
168169
let retval = {
169170
mealState: mealState,
170171
mealStateTransitionTime: Date.now(),
171-
biteTransferPageAtFace: false // Reset this flag when the meal state changes
172+
settingsPageAtMouth: false // Reset this flag when the meal state changes
172173
}
173174
// Only update the previous state if it is not a self-transition (to
174175
// account for cases where a MoveTo action result message is reveived twice)
@@ -211,9 +212,12 @@ export const useGlobalState = create(
211212
lastMotionActionResponse: lastMotionActionResponse
212213
})),
213214
setMoveToMouthActionGoal: (moveToMouthActionGoal) =>
214-
set(() => ({
215-
moveToMouthActionGoal: moveToMouthActionGoal
216-
})),
215+
set(() => {
216+
console.log('setMoveToMouthActionGoal called with', moveToMouthActionGoal)
217+
return {
218+
moveToMouthActionGoal: moveToMouthActionGoal
219+
}
220+
}),
217221
setPaused: (paused) =>
218222
set(() => {
219223
let retval = { paused: paused }
@@ -276,9 +280,9 @@ export const useGlobalState = create(
276280
set(() => ({
277281
biteAcquisitionCheckAutoContinueProbThreshUpper: biteAcquisitionCheckAutoContinueProbThreshUpper
278282
})),
279-
setBiteTransferPageAtFace: (biteTransferPageAtFace) =>
283+
setSettingsPageAtMouth: (settingsPageAtMouth) =>
280284
set(() => ({
281-
biteTransferPageAtFace: biteTransferPageAtFace
285+
settingsPageAtMouth: settingsPageAtMouth
282286
})),
283287
setBiteSelectionZoom: (biteSelectionZoom) =>
284288
set(() => ({

feedingwebapp/src/Pages/Home/MealStates/BiteSelection.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ const BiteSelection = (props) => {
243243
// Create a service request
244244
let request = createROSServiceRequest({ data: false })
245245
// Call the service
246-
service.callService(request, (response) => console.log('Got toggle face detection service response', response))
246+
service.callService(request, (response) => console.log('Got toggle table detection service response', response))
247247
// Destroy the action client
248248
destroyActionClient(action)
249249
}

feedingwebapp/src/Pages/Home/MealStates/DetectingFace.jsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const DetectingFace = (props) => {
2626
const prevMealState = useGlobalState((state) => state.prevMealState)
2727
const setInNonMovingState = useGlobalState((state) => state.setInNonMovingState)
2828
const setMealState = useGlobalState((state) => state.setMealState)
29-
const setMoveToMouthActionGoal = useGlobalState((state) => state.setMoveToMouthActionGoal)
3029
const faceDetectionAutoContinue = useGlobalState((state) => state.faceDetectionAutoContinue)
3130
const setFaceDetectionAutoContinue = useGlobalState((state) => state.setFaceDetectionAutoContinue)
3231
// Get icon image for move to mouth
@@ -105,20 +104,13 @@ const DetectingFace = (props) => {
105104
/**
106105
* Callback for when a face is detected within the correct range.
107106
*/
108-
const faceDetectedCallback = useCallback(
109-
(message) => {
110-
console.log('Face detected callback')
111-
setMouthDetected(true)
112-
setMoveToMouthActionGoal({
113-
face_detection: message
114-
})
115-
// If auto-continue is enabled, move to the mouth position
116-
if (autoContinueIsEnabled()) {
117-
moveToMouthCallback()
118-
}
119-
},
120-
[autoContinueIsEnabled, moveToMouthCallback, setMoveToMouthActionGoal]
121-
)
107+
const faceDetectedCallback = useCallback(() => {
108+
setMouthDetected(true)
109+
// If auto-continue is enabled, move to the mouth position
110+
if (autoContinueIsEnabled()) {
111+
moveToMouthCallback()
112+
}
113+
}, [autoContinueIsEnabled, moveToMouthCallback])
122114

123115
/** Get the full page view
124116
*

feedingwebapp/src/Pages/Home/MealStates/DetectingFaceSubcomponent.jsx

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@ import { useMediaQuery } from 'react-responsive'
55
import { View } from 'react-native'
66

77
// Local Imports
8-
import { useROS, createROSService, createROSServiceRequest, subscribeToROSTopic, unsubscribeFromROSTopic } from '../../../ros/ros_helpers'
8+
import { useROS, subscribeToROSTopic, unsubscribeFromROSTopic } from '../../../ros/ros_helpers'
99
import '../Home.css'
10-
import { MEAL_STATE } from '../../GlobalState'
11-
import { FACE_DETECTION_IMG_TOPIC, FACE_DETECTION_TOPIC, FACE_DETECTION_TOPIC_MSG, ROS_SERVICE_NAMES } from '../../Constants'
10+
import { FACE_DETECTION_IMG_TOPIC, FACE_DETECTION_TOPIC, FACE_DETECTION_TOPIC_MSG } from '../../Constants'
1211
import VideoFeed from '../VideoFeed'
12+
import { useGlobalState } from '../../GlobalState'
1313

1414
/**
1515
* The DetectingFace component appears after the robot has moved to the staging
1616
* configuration. It displays the output of face detection, and automatically
1717
* moves on to `R_MovingToMouth` when a face is detected.
1818
*/
1919
const DetectingFaceSubcomponent = (props) => {
20+
// Get the relevant global variables
21+
const setMoveToMouthActionGoal = useGlobalState((state) => state.setMoveToMouthActionGoal)
22+
2023
// Keep track of whether a mouth has been detected or not
2124
const [mouthDetected, setMouthDetected] = useState(false)
2225
// Flag to check if the current orientation is portrait
@@ -51,11 +54,14 @@ const DetectingFaceSubcomponent = (props) => {
5154
0.5
5255
if (distance > min_face_distance && distance < max_face_distance) {
5356
setMouthDetected(true)
57+
setMoveToMouthActionGoal({
58+
face_detection: message
59+
})
5460
faceDetectedCallback()
5561
}
5662
}
5763
},
58-
[props.faceDetectedCallback, setMouthDetected]
64+
[props.faceDetectedCallback, setMouthDetected, setMoveToMouthActionGoal]
5965
)
6066
useEffect(() => {
6167
let topic = subscribeToROSTopic(ros.current, FACE_DETECTION_TOPIC, FACE_DETECTION_TOPIC_MSG, faceDetectionCallback)
@@ -69,38 +75,6 @@ const DetectingFaceSubcomponent = (props) => {
6975
}
7076
}, [faceDetectionCallback])
7177

72-
/**
73-
* Create the ROS Service. This is created in local state to avoid re-creating
74-
* it upon every re-render.
75-
*/
76-
let { serviceName, messageType } = ROS_SERVICE_NAMES[MEAL_STATE.R_DetectingFace]
77-
let toggleFaceDetectionService = useRef(createROSService(ros.current, serviceName, messageType))
78-
79-
/**
80-
* Toggles face detection on the first time this component is rendered, but
81-
* not upon additional re-renders. See here for more details on how `useEffect`
82-
* achieves this goal: https://stackoverflow.com/a/69264685
83-
*/
84-
useEffect(() => {
85-
// Create a service request
86-
let request = createROSServiceRequest({ data: true })
87-
// Call the service
88-
let service = toggleFaceDetectionService.current
89-
service.callService(request, (response) => console.log('Got toggle face detection service response', response))
90-
91-
/**
92-
* In practice, because the values passed in in the second argument of
93-
* useEffect will not change on re-renders, this return statement will
94-
* only be called when the component unmounts.
95-
*/
96-
return () => {
97-
// Create a service request
98-
let request = createROSServiceRequest({ data: false })
99-
// Call the service
100-
service.callService(request, (response) => console.log('Got toggle face detection service response', response))
101-
}
102-
}, [toggleFaceDetectionService])
103-
10478
// Render the component
10579
return (
10680
<>
@@ -125,7 +99,7 @@ const DetectingFaceSubcomponent = (props) => {
12599
height: '100%'
126100
}}
127101
>
128-
<VideoFeed topic={FACE_DETECTION_IMG_TOPIC} webrtcURL={props.webrtcURL} />
102+
<VideoFeed topic={FACE_DETECTION_IMG_TOPIC} webrtcURL={props.webrtcURL} toggleFaceDetection={true} />
129103
</View>
130104
</>
131105
)

0 commit comments

Comments
 (0)