Skip to content

Commit 5c83b69

Browse files
authored
Added MoveFromMouth Actions (#80)
* Added MoveFromMouth actions * Added MoveFromMouth dummy actions * Update setup.py
1 parent 7d5e40e commit 5c83b69

File tree

8 files changed

+102
-4
lines changed

8 files changed

+102
-4
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
from ada_feeding_msgs.action import MoveTo
3+
from feeding_web_app_ros2_test.MoveToDummy import MoveToDummy
4+
import rclpy
5+
from rclpy.executors import MultiThreadedExecutor
6+
7+
8+
def main(args=None):
9+
rclpy.init(args=args)
10+
11+
move_above_plate = MoveToDummy("MoveFromMouthToAbovePlate", MoveTo)
12+
13+
# Use a MultiThreadedExecutor to enable processing goals concurrently
14+
executor = MultiThreadedExecutor()
15+
16+
rclpy.spin(move_above_plate, executor=executor)
17+
18+
19+
if __name__ == "__main__":
20+
main()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
from ada_feeding_msgs.action import MoveTo
3+
from feeding_web_app_ros2_test.MoveToDummy import MoveToDummy
4+
import rclpy
5+
from rclpy.executors import MultiThreadedExecutor
6+
7+
8+
def main(args=None):
9+
rclpy.init(args=args)
10+
11+
move_to_resting_position = MoveToDummy("MoveFromMouthToRestingPosition", MoveTo)
12+
13+
# Use a MultiThreadedExecutor to enable processing goals concurrently
14+
executor = MultiThreadedExecutor()
15+
16+
rclpy.spin(move_to_resting_position, executor=executor)
17+
18+
19+
if __name__ == "__main__":
20+
main()

feeding_web_app_ros2_test/launch/feeding_web_app_dummy_nodes_launch.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
<node pkg="feeding_web_app_ros2_test" exec="MoveToRestingPosition" name="MoveToRestingPosition"/>
4949
<!-- Motion: The MoveToMouth action -->
5050
<node pkg="feeding_web_app_ros2_test" exec="MoveToMouth" name="MoveToMouth"/>
51+
<!-- Motion: The MoveFromMouthToAbovePlate action -->
52+
<node pkg="feeding_web_app_ros2_test" exec="MoveFromMouthToAbovePlate" name="MoveFromMouthToAbovePlate"/>
53+
<!-- Motion: The MoveFromMouthToRestingPosition action -->
54+
<node pkg="feeding_web_app_ros2_test" exec="MoveFromMouthToRestingPosition" name="MoveFromMouthToRestingPosition"/>
5155
<!-- Motion: The MoveToStowLocation action -->
5256
<node pkg="feeding_web_app_ros2_test" exec="MoveToStowLocation" name="MoveToStowLocation"/>
5357
</group>

feeding_web_app_ros2_test/setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"MoveAbovePlate = feeding_web_app_ros2_test.MoveAbovePlate:main",
4040
"MoveToRestingPosition = feeding_web_app_ros2_test.MoveToRestingPosition:main",
4141
"MoveToMouth = feeding_web_app_ros2_test.MoveToMouth:main",
42+
"MoveFromMouthToAbovePlate = feeding_web_app_ros2_test.MoveFromMouthToAbovePlate:main",
43+
"MoveFromMouthToRestingPosition = feeding_web_app_ros2_test.MoveFromMouthToRestingPosition:main",
4244
"MoveToStowLocation = feeding_web_app_ros2_test.MoveToStowLocation:main",
4345
"SegmentFromPoint = feeding_web_app_ros2_test.SegmentFromPoint:main",
4446
# Scripts for the "TestROS" component

feedingwebapp/src/Pages/Constants.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export const TIME_TO_RESET_MS = 3600000 // 1 hour in milliseconds
2323
*/
2424
let MOVING_STATE_ICON_DICT = {}
2525
MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingAbovePlate] = '/robot_state_imgs/move_above_plate_position.svg'
26+
MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingFromMouthToAbovePlate] = '/robot_state_imgs/move_above_plate_position.svg'
2627
MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingToRestingPosition] = '/robot_state_imgs/move_to_resting_position.svg'
28+
MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingFromMouthToRestingPosition] = '/robot_state_imgs/move_to_resting_position.svg'
2729
MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingToMouth] = '/robot_state_imgs/move_to_mouth_position.svg'
2830
MOVING_STATE_ICON_DICT[MEAL_STATE.R_StowingArm] = '/robot_state_imgs/stowing_arm_position.svg'
2931
export { MOVING_STATE_ICON_DICT }
@@ -54,6 +56,10 @@ ROS_ACTIONS_NAMES[MEAL_STATE.R_MovingAbovePlate] = {
5456
actionName: 'MoveAbovePlate',
5557
messageType: 'ada_feeding_msgs/action/MoveTo'
5658
}
59+
ROS_ACTIONS_NAMES[MEAL_STATE.R_MovingFromMouthToAbovePlate] = {
60+
actionName: 'MoveFromMouthToAbovePlate',
61+
messageType: 'ada_feeding_msgs/action/MoveTo'
62+
}
5763
ROS_ACTIONS_NAMES[MEAL_STATE.U_BiteSelection] = {
5864
actionName: 'SegmentFromPoint',
5965
messageType: 'ada_feeding_msgs/action/SegmentFromPoint'
@@ -66,6 +72,10 @@ ROS_ACTIONS_NAMES[MEAL_STATE.R_MovingToRestingPosition] = {
6672
actionName: 'MoveToRestingPosition',
6773
messageType: 'ada_feeding_msgs/action/MoveTo'
6874
}
75+
ROS_ACTIONS_NAMES[MEAL_STATE.R_MovingFromMouthToRestingPosition] = {
76+
actionName: 'MoveFromMouthToRestingPosition',
77+
messageType: 'ada_feeding_msgs/action/MoveTo'
78+
}
6979
ROS_ACTIONS_NAMES[MEAL_STATE.R_MovingToMouth] = {
7080
actionName: 'MoveToMouth',
7181
messageType: 'ada_feeding_msgs/action/MoveTo'

feedingwebapp/src/Pages/GlobalState.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ export const APP_PAGE = {
3636
* bite acquisition was succesful or not.
3737
* - R_MovingToMouth: Waiting for the robot to finish moving to the user's
3838
* mouth.
39+
* - R_MovingFromMouthToAbovePlate: Waiting for the robot to move from the
40+
* user's mouth to above the plate. This is a separate action from
41+
* R_MovingAbovePlate to allow us to customize the departure from the mouth
42+
* (e.g., a slower speed).
43+
* - R_MovingFromMouthToRestingPosition: Waiting for the robot to move from
44+
* the user's mouth to resting position. This is a separate action from
45+
* R_MovingToRestingPosition to allow us to customize the departure from
46+
* the mouth (e.g., a slower speed).
3947
* - U_BiteDone: Waiting for the user to indicate that they are done eating
4048
* the bite.
4149
* - R_StowingArm: Waiting for the robot to stow the arm.
@@ -50,6 +58,8 @@ export const MEAL_STATE = {
5058
R_MovingToRestingPosition: 'R_MovingToRestingPosition',
5159
U_BiteAcquisitionCheck: 'U_BiteAcquisitionCheck',
5260
R_MovingToMouth: 'R_MovingToMouth',
61+
R_MovingFromMouthToAbovePlate: 'R_MovingFromMouthToAbovePlate',
62+
R_MovingFromMouthToRestingPosition: 'R_MovingFromMouthToRestingPosition',
5363
U_BiteDone: 'U_BiteDone',
5464
R_StowingArm: 'R_StowingArm',
5565
U_PostMeal: 'U_PostMeal'

feedingwebapp/src/Pages/Home/Home.jsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,38 @@ function Home(props) {
145145
/>
146146
)
147147
}
148+
case MEAL_STATE.R_MovingFromMouthToAbovePlate: {
149+
/**
150+
* We recreate currentMealState due to a race condition where sometimes
151+
* the app is performing a re-rendering and *then* the state is updated.
152+
*/
153+
let currentMealState = MEAL_STATE.R_MovingFromMouthToAbovePlate
154+
let nextMealState = MEAL_STATE.U_BiteSelection
155+
let waitingText = 'Waiting to move above the plate...'
156+
return (
157+
<RobotMotion
158+
debug={props.debug}
159+
mealState={currentMealState}
160+
nextMealState={nextMealState}
161+
actionInput={moveAbovePlateActionInput}
162+
waitingText={waitingText}
163+
/>
164+
)
165+
}
166+
case MEAL_STATE.R_MovingFromMouthToRestingPosition: {
167+
let currentMealState = MEAL_STATE.R_MovingFromMouthToRestingPosition
168+
let nextMealState = MEAL_STATE.U_BiteAcquisitionCheck
169+
let waitingText = 'Waiting to move to the resting position...'
170+
return (
171+
<RobotMotion
172+
debug={props.debug}
173+
mealState={currentMealState}
174+
nextMealState={nextMealState}
175+
actionInput={moveToRestingPositionActionInput}
176+
waitingText={waitingText}
177+
/>
178+
)
179+
}
148180
case MEAL_STATE.U_BiteDone: {
149181
return <BiteDone debug={props.debug} />
150182
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const BiteDone = () => {
1818
// Get the relevant global variables
1919
const setMealState = useGlobalState((state) => state.setMealState)
2020
// Get icon image for move above plate
21-
let moveAbovePlateImage = MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingAbovePlate]
21+
let moveAbovePlateImage = MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingFromMouthToAbovePlate]
2222
// Get icon image for move to resting position
23-
let moveToRestingPositionImage = MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingToRestingPosition]
23+
let moveToRestingPositionImage = MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingFromMouthToRestingPosition]
2424
// Flag to check if the current orientation is portrait
2525
const isPortrait = useMediaQuery({ query: '(orientation: portrait)' })
2626
// Indicator of how to arrange screen elements based on orientation
@@ -36,14 +36,14 @@ const BiteDone = () => {
3636
* Callback function for when the user wants to move above plate.
3737
*/
3838
const moveAbovePlate = useCallback(() => {
39-
setMealState(MEAL_STATE.R_MovingAbovePlate)
39+
setMealState(MEAL_STATE.R_MovingFromMouthToAbovePlate)
4040
}, [setMealState])
4141

4242
/**
4343
* Callback function for when the user wants to move to resting position.
4444
*/
4545
const moveToRestingPosition = useCallback(() => {
46-
setMealState(MEAL_STATE.R_MovingToRestingPosition)
46+
setMealState(MEAL_STATE.R_MovingFromMouthToRestingPosition)
4747
}, [setMealState])
4848

4949
/**

0 commit comments

Comments
 (0)