Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry button for error page #85

Merged
merged 5 commits into from
Sep 15, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 51 additions & 23 deletions feedingwebapp/src/Pages/Home/MealStates/RobotMotion.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,16 @@ const RobotMotion = (props) => {
* @param {flexSizeOuter} - flexbox percentage for parent element rendering everything
* @param {flexSizeTextInner} - flexbox percentage for child element rendering text
* @param {flexSizeVisualInner} - flexbox percentage for child element rendering visual
* @param {progress} - progress proportion; if null progress bar not shown
* @param {text} - action status text
* @param {showTime} - indicates if elapsed time needs to be shown
* @param {time} - calculated elapsed time, 0 if time not available
* @param {progress} - progress proportion; if null progress bar not shown
* @param {retry} - indicates if retry needed for error
*
* @returns {JSX.Element} the action status text, progress bar or blank view
*/
const actionStatusTextAndVisual = useCallback(
(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress) => {
(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress, retry) => {
Raidakarim marked this conversation as resolved.
Show resolved Hide resolved
return (
<>
<View style={{ flex: flexSizeOuter, flexDirection: dimension, alignItems: 'center', justifyContent: 'center', width: '100%' }}>
Expand All @@ -260,6 +261,22 @@ const RobotMotion = (props) => {
</p>
<p style={{ fontSize: motionTextFontSize }}>{text}</p>
{showTime ? <p style={{ fontSize: motionTextFontSize }}>&nbsp;&nbsp;Elapsed Time: {time} sec</p> : <></>}
{retry ? (
<Button
variant='warning'
className='mx-2 btn-huge'
size='lg'
onClick={resumeCallback}
style={{
width: '90%',
height: '20%'
}}
>
<h5 style={{ textAlign: 'center', fontSize: motionTextFontSize }}>Retry</h5>
</Button>
) : (
<></>
)}
</View>
<View
style={{
Expand All @@ -276,7 +293,7 @@ const RobotMotion = (props) => {
</>
)
},
[dimension, props.waitingText, motionTextFontSize, waitingTextFontSize]
[dimension, props.waitingText, motionTextFontSize, waitingTextFontSize, resumeCallback]
)

/**
Expand All @@ -289,38 +306,48 @@ const RobotMotion = (props) => {
let flexSizeTextInner = 1
let flexSizeVisualInner = 1
let text
let time
let showTime
let showTime = false
let time = 0
let progress = null
let retry = false
amalnanavati marked this conversation as resolved.
Show resolved Hide resolved
switch (actionStatus.actionStatus) {
case ROS_ACTION_STATUS_EXECUTE:
if (actionStatus.feedback) {
let progress = 1 - actionStatus.feedback.motion_curr_distance / actionStatus.feedback.motion_initial_distance
if (!actionStatus.feedback.is_planning) {
let moving_elapsed_time = actionStatus.feedback.motion_time.sec + actionStatus.feedback.motion_time.nanosec / 10 ** 9
text = 'Robot is moving...'
time = Math.round(moving_elapsed_time * 100) / 100
showTime = true
progress = 1 - actionStatus.feedback.motion_curr_distance / actionStatus.feedback.motion_initial_distance
// Calling CircleProgessBar component to visualize robot motion of moving
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress)}</>
return (
<>
{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress, retry)}
</>
)
} else {
let planning_elapsed_time = actionStatus.feedback.planning_time.sec + actionStatus.feedback.planning_time.nanosec / 10 ** 9
text = 'Robot is thinking...'
time = Math.round(planning_elapsed_time * 100) / 100
showTime = true
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, null)}</>
return (
<>
{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress, retry)}
</>
)
}
} else {
// If you haven't gotten feedback yet, assume the robot is planning
text = 'Robot is thinking...'
time = 0
showTime = false
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, null)}</>
return (
<>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress, retry)}</>
)
}
case ROS_ACTION_STATUS_SUCCEED:
text = 'Robot has finished'
time = 0
showTime = false
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, null)}</>
return (
<>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress, retry)}</>
)
case ROS_ACTION_STATUS_ABORT:
/**
* TODO: Just displaying that the robot faced an error is not useful
Expand All @@ -329,20 +356,21 @@ const RobotMotion = (props) => {
* users on how to troubleshoot/fix it.
*/
text = 'Robot encountered an error'
time = 0
showTime = false
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, null)}</>
retry = true
return (
<>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress, retry)}</>
)
case ROS_ACTION_STATUS_CANCELED:
text = 'Robot is paused'
time = 0
showTime = false
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, null)}</>
return (
<>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress, retry)}</>
)
default:
if (paused) {
text = 'Robot is paused'
time = 0
showTime = false
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, null)}</>
return (
<>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress, retry)}</>
)
} else {
return (
<View
Expand Down