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

Allow mission scheduling when battery is low #1961

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions backend/api/Controllers/MissionSchedulingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ [FromBody] ScheduleMissionQuery scheduledMissionQuery
Robot robot;
try
{
robot = await robotService.GetRobotWithPreCheck(
robot = await robotService.GetRobotWithSchedulingPreCheck(
scheduledMissionQuery.RobotId,
readOnly: true
);
Expand Down Expand Up @@ -141,7 +141,7 @@ [FromBody] ScheduleMissionQuery scheduledMissionQuery
Robot robot;
try
{
robot = await robotService.GetRobotWithPreCheck(
robot = await robotService.GetRobotWithSchedulingPreCheck(
scheduledMissionQuery.RobotId,
readOnly: true
);
Expand Down Expand Up @@ -261,7 +261,7 @@ [FromBody] ScheduledMissionQuery scheduledMissionQuery
Robot robot;
try
{
robot = await robotService.GetRobotWithPreCheck(
robot = await robotService.GetRobotWithSchedulingPreCheck(
scheduledMissionQuery.RobotId,
readOnly: true
);
Expand Down Expand Up @@ -484,7 +484,7 @@ [FromBody] CustomMissionQuery customMissionQuery
Robot robot;
try
{
robot = await robotService.GetRobotWithPreCheck(
robot = await robotService.GetRobotWithSchedulingPreCheck(
customMissionQuery.RobotId,
readOnly: true
);
Expand Down
31 changes: 5 additions & 26 deletions backend/api/Services/RobotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface IRobotService
{
public Task<Robot> Create(Robot newRobot);
public Task<Robot> CreateFromQuery(CreateRobotQuery robotQuery);
public Task<Robot> GetRobotWithPreCheck(string robotId, bool readOnly = true);
public Task<Robot> GetRobotWithSchedulingPreCheck(string robotId, bool readOnly = true);
public Task<IEnumerable<Robot>> ReadAll(bool readOnly = true);
public Task<IEnumerable<string>> ReadAllActivePlants(bool readOnly = true);
public Task<Robot?> ReadById(string id, bool readOnly = true);
Expand Down Expand Up @@ -136,7 +136,10 @@ public async Task<Robot> CreateFromQuery(CreateRobotQuery robotQuery)
);
}

public async Task<Robot> GetRobotWithPreCheck(string robotId, bool readOnly = true)
public async Task<Robot> GetRobotWithSchedulingPreCheck(
string robotId,
bool readOnly = true
)
{
var robot = await ReadById(robotId, readOnly: readOnly);

Expand All @@ -162,30 +165,6 @@ public async Task<Robot> GetRobotWithPreCheck(string robotId, bool readOnly = tr
throw new RobotPreCheckFailedException(errorMessage);
}

if (robot.IsRobotPressureTooLow())
{
string errorMessage =
$"The robot pressure on {robot.Name} is too low to start a mission";
logger.LogError("{Message}", errorMessage);
throw new RobotPreCheckFailedException(errorMessage);
}

if (robot.IsRobotPressureTooHigh())
{
string errorMessage =
$"The robot pressure on {robot.Name} is too high to start a mission";
logger.LogError("{Message}", errorMessage);
throw new RobotPreCheckFailedException(errorMessage);
}

if (robot.IsRobotBatteryTooLow())
{
string errorMessage =
$"The robot battery level on {robot.Name} is too low to start a mission";
logger.LogError("{Message}", errorMessage);
throw new RobotPreCheckFailedException(errorMessage);
}

return robot;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { Robot, RobotCapabilitiesEnum } from 'models/Robot'
import { useEffect, useState } from 'react'
import { useRobotContext } from 'components/Contexts/RobotContext'
import {
InsufficientBatteryDialog,
InsufficientPressureDialog,
} from 'components/Displays/ConfirmScheduleDialogs/InsufficientValueDialogs'
import { ScheduleMissionWithLocalizationVerificationDialog } from './LocalizationVerification/ScheduleMissionWithLocalizationVerification'
import { isBatteryTooLow, isRobotPressureTooHigh, isRobotPressureTooLow } from 'utils/IsRobotReadyToRunMissions'

interface ConfirmScheduleDialogProps {
scheduleMissions: () => void
Expand Down Expand Up @@ -38,10 +33,6 @@ export const ScheduleMissionWithConfirmDialogs = ({

if (!robot) {
return <></>
} else if (isBatteryTooLow(robot)) {
return <InsufficientBatteryDialog robot={robot} cancel={closeDialog} />
} else if (isRobotPressureTooLow(robot) || isRobotPressureTooHigh(robot)) {
return <InsufficientPressureDialog robot={robot} cancel={closeDialog} />
} else {
// Auto-localizing robots don't need to confirmation localization. Localization dialog can be skipped
if (
Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions frontend/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,6 @@
"No predefined missions available": "No predefined missions available",
"No robot available": "No robot available",
"Failed to schedule mission": "Failed to schedule mission",
"Current pressure value for": "Current pressure value for",
"Current battery value for": "Current battery value for",
"is": "is",
"This is below recommended lower limit of": "This is below recommended lower limit of",
"This is above recommended upper limit of": "This is above recommended upper limit of",
"pressure warning": "Pressure warning",
"battery warning": "Battery warning",
"Please charge the robot": "Please charge the robot",
"Please pressurize the robot": "Please pressurize the robot",
"Please de-pressurize the robot": "Please release some pressure from the robot",
"Return robot to home": "Return robot to home",
"Dock failure": "Dock failure",
"Failure to schedule": "Failure to schedule",
Expand Down
10 changes: 0 additions & 10 deletions frontend/src/language/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,6 @@
"No predefined missions available": "Ingen tilgjengelige forhåndsdefinerte oppdrag",
"No robot available": "Ingen robot tilgjengelig",
"Failed to schedule mission": "Kunne ikke planlegge oppdrag",
"Current pressure value for": "Nåværende trykk for",
"Current battery value for": "Nåværende batteri for",
"is": "er",
"This is below recommended lower limit of": "Dette er under anbefalt nedre grense på",
"This is above recommended upper limit of": "Dette er over anbefalt øvre grense på",
"pressure warning": "Advarsel: Trykk",
"battery warning": "Advarsel: Batteri",
"Please charge the robot": "Vennligst lad roboten",
"Please pressurize the robot": "Vennligst trykk opp roboten",
"Please de-pressurize the robot": "Vennligst slipp ut litt trykk fra roboten",
"Return robot to home": "Send roboten hjem",
"Dock failure": "Ladestasjon feilet",
"Failure to schedule": "Kunne ikke planlegge oppdrag",
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/utils/IsRobotReadyToRunMissions.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { Robot, RobotFlotillaStatus } from 'models/Robot'

export const isBatteryTooLow = (robot: Robot): boolean => {
const isBatteryTooLow = (robot: Robot): boolean => {
if (robot.batteryLevel === undefined || robot.batteryLevel === null) return false

if (robot.model.batteryWarningThreshold && robot.batteryLevel < robot.model.batteryWarningThreshold) {
Expand All @@ -16,14 +16,14 @@ export const isBatteryTooLow = (robot: Robot): boolean => {
return false
}

export const isRobotPressureTooHigh = (robot: Robot): boolean => {
const isRobotPressureTooHigh = (robot: Robot): boolean => {
if (robot.model.upperPressureWarningThreshold && robot.pressureLevel) {
return robot.pressureLevel > robot.model.upperPressureWarningThreshold
}
return false
}

export const isRobotPressureTooLow = (robot: Robot): boolean => {
const isRobotPressureTooLow = (robot: Robot): boolean => {
if (robot.model.lowerPressureWarningThreshold && robot.pressureLevel) {
return robot.pressureLevel < robot.model.lowerPressureWarningThreshold
}
Expand Down
Loading