Skip to content

Commit

Permalink
Added MoveFromMouth Actions (#80)
Browse files Browse the repository at this point in the history
* Added MoveFromMouth actions

* Added MoveFromMouth dummy actions

* Update setup.py
  • Loading branch information
amalnanavati authored Sep 19, 2023
1 parent 7d5e40e commit 5c83b69
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
from ada_feeding_msgs.action import MoveTo
from feeding_web_app_ros2_test.MoveToDummy import MoveToDummy
import rclpy
from rclpy.executors import MultiThreadedExecutor


def main(args=None):
rclpy.init(args=args)

move_above_plate = MoveToDummy("MoveFromMouthToAbovePlate", MoveTo)

# Use a MultiThreadedExecutor to enable processing goals concurrently
executor = MultiThreadedExecutor()

rclpy.spin(move_above_plate, executor=executor)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
from ada_feeding_msgs.action import MoveTo
from feeding_web_app_ros2_test.MoveToDummy import MoveToDummy
import rclpy
from rclpy.executors import MultiThreadedExecutor


def main(args=None):
rclpy.init(args=args)

move_to_resting_position = MoveToDummy("MoveFromMouthToRestingPosition", MoveTo)

# Use a MultiThreadedExecutor to enable processing goals concurrently
executor = MultiThreadedExecutor()

rclpy.spin(move_to_resting_position, executor=executor)


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
<node pkg="feeding_web_app_ros2_test" exec="MoveToRestingPosition" name="MoveToRestingPosition"/>
<!-- Motion: The MoveToMouth action -->
<node pkg="feeding_web_app_ros2_test" exec="MoveToMouth" name="MoveToMouth"/>
<!-- Motion: The MoveFromMouthToAbovePlate action -->
<node pkg="feeding_web_app_ros2_test" exec="MoveFromMouthToAbovePlate" name="MoveFromMouthToAbovePlate"/>
<!-- Motion: The MoveFromMouthToRestingPosition action -->
<node pkg="feeding_web_app_ros2_test" exec="MoveFromMouthToRestingPosition" name="MoveFromMouthToRestingPosition"/>
<!-- Motion: The MoveToStowLocation action -->
<node pkg="feeding_web_app_ros2_test" exec="MoveToStowLocation" name="MoveToStowLocation"/>
</group>
Expand Down
2 changes: 2 additions & 0 deletions feeding_web_app_ros2_test/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"MoveAbovePlate = feeding_web_app_ros2_test.MoveAbovePlate:main",
"MoveToRestingPosition = feeding_web_app_ros2_test.MoveToRestingPosition:main",
"MoveToMouth = feeding_web_app_ros2_test.MoveToMouth:main",
"MoveFromMouthToAbovePlate = feeding_web_app_ros2_test.MoveFromMouthToAbovePlate:main",
"MoveFromMouthToRestingPosition = feeding_web_app_ros2_test.MoveFromMouthToRestingPosition:main",
"MoveToStowLocation = feeding_web_app_ros2_test.MoveToStowLocation:main",
"SegmentFromPoint = feeding_web_app_ros2_test.SegmentFromPoint:main",
# Scripts for the "TestROS" component
Expand Down
10 changes: 10 additions & 0 deletions feedingwebapp/src/Pages/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export const TIME_TO_RESET_MS = 3600000 // 1 hour in milliseconds
*/
let MOVING_STATE_ICON_DICT = {}
MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingAbovePlate] = '/robot_state_imgs/move_above_plate_position.svg'
MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingFromMouthToAbovePlate] = '/robot_state_imgs/move_above_plate_position.svg'
MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingToRestingPosition] = '/robot_state_imgs/move_to_resting_position.svg'
MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingFromMouthToRestingPosition] = '/robot_state_imgs/move_to_resting_position.svg'
MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingToMouth] = '/robot_state_imgs/move_to_mouth_position.svg'
MOVING_STATE_ICON_DICT[MEAL_STATE.R_StowingArm] = '/robot_state_imgs/stowing_arm_position.svg'
export { MOVING_STATE_ICON_DICT }
Expand Down Expand Up @@ -54,6 +56,10 @@ ROS_ACTIONS_NAMES[MEAL_STATE.R_MovingAbovePlate] = {
actionName: 'MoveAbovePlate',
messageType: 'ada_feeding_msgs/action/MoveTo'
}
ROS_ACTIONS_NAMES[MEAL_STATE.R_MovingFromMouthToAbovePlate] = {
actionName: 'MoveFromMouthToAbovePlate',
messageType: 'ada_feeding_msgs/action/MoveTo'
}
ROS_ACTIONS_NAMES[MEAL_STATE.U_BiteSelection] = {
actionName: 'SegmentFromPoint',
messageType: 'ada_feeding_msgs/action/SegmentFromPoint'
Expand All @@ -66,6 +72,10 @@ ROS_ACTIONS_NAMES[MEAL_STATE.R_MovingToRestingPosition] = {
actionName: 'MoveToRestingPosition',
messageType: 'ada_feeding_msgs/action/MoveTo'
}
ROS_ACTIONS_NAMES[MEAL_STATE.R_MovingFromMouthToRestingPosition] = {
actionName: 'MoveFromMouthToRestingPosition',
messageType: 'ada_feeding_msgs/action/MoveTo'
}
ROS_ACTIONS_NAMES[MEAL_STATE.R_MovingToMouth] = {
actionName: 'MoveToMouth',
messageType: 'ada_feeding_msgs/action/MoveTo'
Expand Down
10 changes: 10 additions & 0 deletions feedingwebapp/src/Pages/GlobalState.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ export const APP_PAGE = {
* bite acquisition was succesful or not.
* - R_MovingToMouth: Waiting for the robot to finish moving to the user's
* mouth.
* - R_MovingFromMouthToAbovePlate: Waiting for the robot to move from the
* user's mouth to above the plate. This is a separate action from
* R_MovingAbovePlate to allow us to customize the departure from the mouth
* (e.g., a slower speed).
* - R_MovingFromMouthToRestingPosition: Waiting for the robot to move from
* the user's mouth to resting position. This is a separate action from
* R_MovingToRestingPosition to allow us to customize the departure from
* the mouth (e.g., a slower speed).
* - U_BiteDone: Waiting for the user to indicate that they are done eating
* the bite.
* - R_StowingArm: Waiting for the robot to stow the arm.
Expand All @@ -50,6 +58,8 @@ export const MEAL_STATE = {
R_MovingToRestingPosition: 'R_MovingToRestingPosition',
U_BiteAcquisitionCheck: 'U_BiteAcquisitionCheck',
R_MovingToMouth: 'R_MovingToMouth',
R_MovingFromMouthToAbovePlate: 'R_MovingFromMouthToAbovePlate',
R_MovingFromMouthToRestingPosition: 'R_MovingFromMouthToRestingPosition',
U_BiteDone: 'U_BiteDone',
R_StowingArm: 'R_StowingArm',
U_PostMeal: 'U_PostMeal'
Expand Down
32 changes: 32 additions & 0 deletions feedingwebapp/src/Pages/Home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,38 @@ function Home(props) {
/>
)
}
case MEAL_STATE.R_MovingFromMouthToAbovePlate: {
/**
* We recreate currentMealState due to a race condition where sometimes
* the app is performing a re-rendering and *then* the state is updated.
*/
let currentMealState = MEAL_STATE.R_MovingFromMouthToAbovePlate
let nextMealState = MEAL_STATE.U_BiteSelection
let waitingText = 'Waiting to move above the plate...'
return (
<RobotMotion
debug={props.debug}
mealState={currentMealState}
nextMealState={nextMealState}
actionInput={moveAbovePlateActionInput}
waitingText={waitingText}
/>
)
}
case MEAL_STATE.R_MovingFromMouthToRestingPosition: {
let currentMealState = MEAL_STATE.R_MovingFromMouthToRestingPosition
let nextMealState = MEAL_STATE.U_BiteAcquisitionCheck
let waitingText = 'Waiting to move to the resting position...'
return (
<RobotMotion
debug={props.debug}
mealState={currentMealState}
nextMealState={nextMealState}
actionInput={moveToRestingPositionActionInput}
waitingText={waitingText}
/>
)
}
case MEAL_STATE.U_BiteDone: {
return <BiteDone debug={props.debug} />
}
Expand Down
8 changes: 4 additions & 4 deletions feedingwebapp/src/Pages/Home/MealStates/BiteDone.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const BiteDone = () => {
// Get the relevant global variables
const setMealState = useGlobalState((state) => state.setMealState)
// Get icon image for move above plate
let moveAbovePlateImage = MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingAbovePlate]
let moveAbovePlateImage = MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingFromMouthToAbovePlate]
// Get icon image for move to resting position
let moveToRestingPositionImage = MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingToRestingPosition]
let moveToRestingPositionImage = MOVING_STATE_ICON_DICT[MEAL_STATE.R_MovingFromMouthToRestingPosition]
// Flag to check if the current orientation is portrait
const isPortrait = useMediaQuery({ query: '(orientation: portrait)' })
// Indicator of how to arrange screen elements based on orientation
Expand All @@ -36,14 +36,14 @@ const BiteDone = () => {
* Callback function for when the user wants to move above plate.
*/
const moveAbovePlate = useCallback(() => {
setMealState(MEAL_STATE.R_MovingAbovePlate)
setMealState(MEAL_STATE.R_MovingFromMouthToAbovePlate)
}, [setMealState])

/**
* Callback function for when the user wants to move to resting position.
*/
const moveToRestingPosition = useCallback(() => {
setMealState(MEAL_STATE.R_MovingToRestingPosition)
setMealState(MEAL_STATE.R_MovingFromMouthToRestingPosition)
}, [setMealState])

/**
Expand Down

0 comments on commit 5c83b69

Please sign in to comment.