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

Only schedule return home if supported by robot #1680

Merged
merged 1 commit into from
Jul 24, 2024
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
3 changes: 2 additions & 1 deletion backend/api.test/Database/DatabaseUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ public async Task<Robot> NewRobot(RobotStatus status, Installation installation,
VideoStreams = new List<CreateVideoStreamQuery>(),
Host = "localhost",
Port = 3000,
Status = status
Status = status,
RobotCapabilities = [RobotCapabilitiesEnum.drive_to_pose, RobotCapabilitiesEnum.take_image, RobotCapabilitiesEnum.return_to_home, RobotCapabilitiesEnum.localize]
};

var robotModel = await _robotModelService.ReadByRobotType(createRobotQuery.RobotType);
Expand Down
37 changes: 37 additions & 0 deletions backend/api.test/EventHandlers/TestMissionEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,43 @@ public async Task ReturnToHomeMissionIsStartedIfQueueIsEmptyWhenRobotBecomesAvai
Assert.True(ongoingMission.Any());
}

[Fact]
public async Task ReturnToHomeMissionIsNotStartedIfReturnToHomeIsNotSupported()
{
// Arrange
var installation = await _databaseUtilities.NewInstallation();
var plant = await _databaseUtilities.NewPlant(installation.InstallationCode);
var deck = await _databaseUtilities.NewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.NewArea(installation.InstallationCode, plant.PlantCode, deck.Name);
var robot = await _databaseUtilities.NewRobot(RobotStatus.Busy, installation, area);
robot.RobotCapabilities!.Remove(RobotCapabilitiesEnum.return_to_home);

var mqttEventArgs = new MqttReceivedArgs(
new IsarStatusMessage
{
RobotName = robot.Name,
IsarId = robot.IsarId,
Status = RobotStatus.Available,
Timestamp = DateTime.UtcNow
});

// Act
_mqttService.RaiseEvent(nameof(MqttService.MqttIsarStatusReceived), mqttEventArgs);

// Assert
Thread.Sleep(1000);
var ongoingMission = await _missionRunService.ReadAll(
new MissionRunQueryStringParameters
{
Statuses = [
MissionStatus.Ongoing
],
OrderBy = "DesiredStartTime",
PageSize = 100
});
Assert.False(ongoingMission.Any());
}

[Fact]
public async Task MissionRunIsStartedForOtherAvailableRobotIfOneRobotHasAnOngoingMissionRun()
{
Expand Down
39 changes: 26 additions & 13 deletions backend/api/Services/MissionSchedulingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,37 @@ public async Task StartNextMissionRunIfSystemIsAvailable(string robotId)
return;
}

try { missionRun = await returnToHomeService.ScheduleReturnToHomeMissionRunIfNotAlreadyScheduledOrRobotIsHome(robot.Id); }
catch (ReturnToHomeMissionFailedToScheduleException)
if (robot.RobotCapabilities == null || !robot.RobotCapabilities.Contains(RobotCapabilitiesEnum.return_to_home))
{
signalRService.ReportGeneralFailToSignalR(robot, $"Failed to schedule return to home for robot {robot.Name}", "");
logger.LogError("Failed to schedule a return to home mission for robot {RobotId}", robot.Id);
await robotService.UpdateCurrentArea(robot.Id, null);
return;
}

if (missionRun == null) { return; } // The robot is already home

var postReturnToHomeMissionCreatedRobot = await robotService.ReadById(missionRun.Robot.Id);
if (postReturnToHomeMissionCreatedRobot == null)
else
{
logger.LogInformation("Could not find robot {Name}", missionRun.Robot.Name);
return;
try { missionRun = await returnToHomeService.ScheduleReturnToHomeMissionRunIfNotAlreadyScheduledOrRobotIsHome(robot.Id); }
catch (ReturnToHomeMissionFailedToScheduleException)
{
signalRService.ReportGeneralFailToSignalR(robot, $"Failed to schedule return to home for robot {robot.Name}", "");
logger.LogError("Failed to schedule a return to home mission for robot {RobotId}", robot.Id);
await robotService.UpdateCurrentArea(robot.Id, null);
}

if (missionRun == null) { return; } // The robot is already home

var postReturnToHomeMissionCreatedRobot = await robotService.ReadById(missionRun.Robot.Id);
if (postReturnToHomeMissionCreatedRobot == null)
{
logger.LogInformation("Could not find robot {Name}", missionRun.Robot.Name);
return;
}

logger.LogInformation(
"Post return to home mission created: Robot {robotName} has status {robotStatus} and current area {areaName}",
postReturnToHomeMissionCreatedRobot.Name,
postReturnToHomeMissionCreatedRobot.Status,
postReturnToHomeMissionCreatedRobot.CurrentArea?.Name
);
}

logger.LogInformation("Post return to home mission created: Robot {robotName} has status {robotStatus} and current area {areaName}", postReturnToHomeMissionCreatedRobot.Name, postReturnToHomeMissionCreatedRobot.Status, postReturnToHomeMissionCreatedRobot.CurrentArea?.Name);
}

if (!await TheSystemIsAvailableToRunAMission(robot.Id, missionRun.Id))
Expand Down
Loading