Skip to content

Commit 90c95e2

Browse files
authored
Call AcquisitionReport service after food-on-fork question (#121)
* Added Toast to check logic * Add AcquisitionReport service call * Fix response processing
1 parent 19b671d commit 90c95e2

File tree

6 files changed

+58
-7
lines changed

6 files changed

+58
-7
lines changed

feedingwebapp/package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

feedingwebapp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"axios": "^1.6.5",
1212
"body-parser": "^1.20.2",
1313
"bootstrap": "^5.1.3",
14+
"caniuse-lite": "^1.0.30001579",
1415
"cors": "^2.8.5",
1516
"express": "^4.18.2",
1617
"mdb-react-ui-kit": "^3.0.0",

feedingwebapp/src/Pages/Constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ ROS_SERVICE_NAMES[MEAL_STATE.R_DetectingFace] = {
109109
export { ROS_SERVICE_NAMES }
110110
export const CLEAR_OCTOMAP_SERVICE_NAME = 'clear_octomap'
111111
export const CLEAR_OCTOMAP_SERVICE_TYPE = 'std_srvs/srv/Empty'
112+
export const ACQUISITION_REPORT_SERVICE_NAME = 'ada_feeding_action_select/action_report'
113+
export const ACQUISITION_REPORT_SERVICE_TYPE = 'ada_feeding_msgs/srv/AcquisitionReport'
112114
export const GET_PARAMETERS_SERVICE_NAME = 'ada_feeding_action_servers/get_parameters'
113115
export const GET_PARAMETERS_SERVICE_TYPE = 'rcl_interfaces/srv/GetParameters'
114116
export const SET_PARAMETERS_SERVICE_NAME = 'ada_feeding_action_servers/set_parameters'

feedingwebapp/src/Pages/GlobalState.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ export const useGlobalState = create(
121121
// message received from the face detection node where a
122122
// face was detected and within the distance bounds of the camera.
123123
moveToMouthActionGoal: null,
124+
// Last RobotMotion action response
125+
lastMotionActionResponse: null,
124126
// Whether or not the currently-executing robot motion was paused by the user
125127
paused: false,
126128
// Flag to indicate robot motion trough teleoperation interface
@@ -171,6 +173,10 @@ export const useGlobalState = create(
171173
set(() => ({
172174
biteAcquisitionActionGoal: biteAcquisitionActionGoal
173175
})),
176+
setLastMotionActionResponse: (lastMotionActionResponse) =>
177+
set(() => ({
178+
lastMotionActionResponse: lastMotionActionResponse
179+
})),
174180
setMoveToMouthActionGoal: (moveToMouthActionGoal) =>
175181
set(() => ({
176182
moveToMouthActionGoal: moveToMouthActionGoal

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// React Imports
2-
import React, { useCallback } from 'react'
2+
import React, { useCallback, useRef } from 'react'
33
import Button from 'react-bootstrap/Button'
44
import { useMediaQuery } from 'react-responsive'
5+
import { toast } from 'react-toastify'
56
import { View } from 'react-native'
67

78
// Local Imports
89
import '../Home.css'
910
import { useGlobalState, MEAL_STATE } from '../../GlobalState'
1011
import { MOVING_STATE_ICON_DICT } from '../../Constants'
12+
import { useROS, createROSService, createROSServiceRequest } from '../../../ros/ros_helpers'
13+
import { ACQUISITION_REPORT_SERVICE_NAME, ACQUISITION_REPORT_SERVICE_TYPE } from '../../Constants'
1114

1215
/**
1316
* The BiteAcquisitionCheck component appears after the robot has attempted to
@@ -31,23 +34,57 @@ const BiteAcquisitionCheck = () => {
3134
let iconWidth = isPortrait ? '28vh' : '28vw'
3235
let iconHeight = isPortrait ? '18vh' : '18vw'
3336

37+
// Configure AcquisitionReport service
38+
const lastMotionActionResponse = useGlobalState((state) => state.lastMotionActionResponse)
39+
/**
40+
* Connect to ROS, if not already connected. Put this in useRef to avoid
41+
* re-connecting upon re-renders.
42+
*/
43+
const ros = useRef(useROS().ros)
44+
/**
45+
* Create the ROS Service Client for reporting success/failure
46+
*/
47+
let acquisitionReportService = useRef(createROSService(ros.current, ACQUISITION_REPORT_SERVICE_NAME, ACQUISITION_REPORT_SERVICE_TYPE))
48+
3449
/**
3550
* Callback function for when the user indicates that the bite acquisition
3651
* succeeded.
3752
*/
3853
const acquisitionSuccess = useCallback(() => {
3954
console.log('acquisitionSuccess')
55+
toast.info('Reporting Food Acquisition Success!')
56+
// Create a service request
57+
let request = createROSServiceRequest({
58+
loss: 0.0,
59+
action_index: lastMotionActionResponse.action_index,
60+
posthoc: lastMotionActionResponse.posthoc,
61+
id: lastMotionActionResponse.selection_id
62+
})
63+
// Call the service
64+
let service = acquisitionReportService.current
65+
service.callService(request, (response) => console.log('Got acquisition report response', response))
4066
setMealState(MEAL_STATE.R_MovingToStagingConfiguration)
41-
}, [setMealState])
67+
}, [lastMotionActionResponse, setMealState])
4268

4369
/**
4470
* Callback function for when the user indicates that the bite acquisition
4571
* failed.
4672
*/
4773
const acquisitionFailure = useCallback(() => {
4874
console.log('acquisitionFailure')
75+
toast.info('Reporting Food Acquisition Failure.')
76+
// Create a service request
77+
let request = createROSServiceRequest({
78+
loss: 1.0,
79+
action_index: lastMotionActionResponse.action_index,
80+
posthoc: lastMotionActionResponse.posthoc,
81+
id: lastMotionActionResponse.selection_id
82+
})
83+
// Call the service
84+
let service = acquisitionReportService.current
85+
service.callService(request, (response) => console.log('Got acquisition report response', response))
4986
setMealState(MEAL_STATE.R_MovingAbovePlate)
50-
}, [setMealState])
87+
}, [lastMotionActionResponse, setMealState])
5188

5289
/**
5390
* Get the ready for bite text to render.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ const RobotMotion = (props) => {
6363
const paused = useGlobalState((state) => state.paused)
6464
const setPaused = useGlobalState((state) => state.setPaused)
6565

66+
// Setter for last motion action response
67+
const setLastMotionActionResponse = useGlobalState((state) => state.setLastMotionActionResponse)
68+
6669
/**
6770
* Connect to ROS, if not already connected. Put this in useRef to avoid
6871
* re-connecting upon re-renders.
@@ -143,6 +146,7 @@ const RobotMotion = (props) => {
143146
setActionStatus({
144147
actionStatus: ROS_ACTION_STATUS_SUCCEED
145148
})
149+
setLastMotionActionResponse(response.values)
146150
robotMotionDone()
147151
} else {
148152
if (
@@ -163,7 +167,7 @@ const RobotMotion = (props) => {
163167
}
164168
}
165169
},
166-
[setActionStatus, setPaused, robotMotionDone]
170+
[setLastMotionActionResponse, setActionStatus, setPaused, robotMotionDone]
167171
)
168172

169173
/**

0 commit comments

Comments
 (0)