-
Notifications
You must be signed in to change notification settings - Fork 37
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
Inspect return to home #1988
Merged
mrica-equinor
merged 1 commit into
equinor:main
from
mrica-equinor:inspect-return-to-home
Jan 28, 2025
Merged
Inspect return to home #1988
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,7 +5,10 @@ namespace Api.Services | |||||
{ | ||||||
public interface IReturnToHomeService | ||||||
{ | ||||||
public Task<MissionRun?> ScheduleReturnToHomeMissionRunIfNotAlreadyScheduled(Robot robot); | ||||||
public Task<MissionRun?> ScheduleReturnToHomeMissionRunIfNotAlreadyScheduled( | ||||||
Robot robot, | ||||||
bool shouldTriggerMissionCreatedEvent = false | ||||||
oysand marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
); | ||||||
public Task<MissionRun?> GetActiveReturnToHomeMissionRun( | ||||||
string robotId, | ||||||
bool readOnly = true | ||||||
|
@@ -18,18 +21,21 @@ IMissionRunService missionRunService | |||||
) : IReturnToHomeService | ||||||
{ | ||||||
public async Task<MissionRun?> ScheduleReturnToHomeMissionRunIfNotAlreadyScheduled( | ||||||
Robot robot | ||||||
Robot robot, | ||||||
bool shouldTriggerMissionCreatedEvent = false | ||||||
) | ||||||
{ | ||||||
logger.LogInformation( | ||||||
"Scheduling return home mission if not already scheduled or the robot is home for robot {RobotId}", | ||||||
"Scheduling return home mission if not already scheduled and the robot is not home for Robot {RobotName} with Id {RobotId}", | ||||||
robot.Name, | ||||||
robot.Id | ||||||
); | ||||||
|
||||||
if (await IsReturnToHomeMissionAlreadyScheduled(robot.Id)) | ||||||
{ | ||||||
logger.LogInformation( | ||||||
"ReturnToHomeMission is already scheduled for Robot {RobotId}", | ||||||
"Return Home Mission already scheduled for Robot {RobotName} with Id {RobotId}", | ||||||
robot.Name, | ||||||
robot.Id | ||||||
); | ||||||
return null; | ||||||
|
@@ -38,7 +44,10 @@ Robot robot | |||||
MissionRun missionRun; | ||||||
try | ||||||
{ | ||||||
missionRun = await ScheduleReturnToHomeMissionRun(robot); | ||||||
missionRun = await ScheduleReturnToHomeMissionRun( | ||||||
robot, | ||||||
shouldTriggerMissionCreatedEvent | ||||||
); | ||||||
} | ||||||
catch (Exception ex) | ||||||
when (ex | ||||||
|
@@ -61,9 +70,12 @@ private async Task<bool> IsReturnToHomeMissionAlreadyScheduled(string robotId) | |||||
return await missionRunService.PendingOrOngoingReturnToHomeMissionRunExists(robotId); | ||||||
} | ||||||
|
||||||
private async Task<MissionRun> ScheduleReturnToHomeMissionRun(Robot robot) | ||||||
private async Task<MissionRun> ScheduleReturnToHomeMissionRun( | ||||||
Robot robot, | ||||||
bool shouldTriggerMissionCreatedEvent = false | ||||||
) | ||||||
{ | ||||||
Pose? return_to_home_pose; | ||||||
Pose? returnToHomePose; | ||||||
InspectionArea? currentInspectionArea; | ||||||
if ( | ||||||
robot.RobotCapabilities is not null | ||||||
|
@@ -75,15 +87,15 @@ robot.RobotCapabilities is not null | |||||
readOnly: true | ||||||
); | ||||||
currentInspectionArea = previousMissionRun?.InspectionArea; | ||||||
return_to_home_pose = | ||||||
returnToHomePose = | ||||||
previousMissionRun?.InspectionArea?.DefaultLocalizationPose?.Pose == null | ||||||
? new Pose() | ||||||
: new Pose(previousMissionRun.InspectionArea.DefaultLocalizationPose.Pose); | ||||||
} | ||||||
else | ||||||
{ | ||||||
currentInspectionArea = robot.CurrentInspectionArea; | ||||||
return_to_home_pose = | ||||||
returnToHomePose = | ||||||
robot.CurrentInspectionArea?.DefaultLocalizationPose?.Pose == null | ||||||
? new Pose() | ||||||
: new Pose(robot.CurrentInspectionArea.DefaultLocalizationPose.Pose); | ||||||
|
@@ -92,26 +104,29 @@ robot.RobotCapabilities is not null | |||||
if (currentInspectionArea == null) | ||||||
{ | ||||||
string errorMessage = | ||||||
$"Robot with ID {robot.Id} could return home as it did not have an inspection area"; | ||||||
logger.LogError("{Message}", errorMessage); | ||||||
$"Robot with ID {robot.Id} could not return to home because it does not have an inspection area"; | ||||||
logger.LogError("Message: {Message}", errorMessage); | ||||||
throw new InspectionAreaNotFoundException(errorMessage); | ||||||
} | ||||||
|
||||||
var returnToHomeMissionRun = new MissionRun | ||||||
{ | ||||||
Name = "Return home", | ||||||
Name = "Return Home", | ||||||
Robot = robot, | ||||||
InstallationCode = robot.CurrentInstallation.InstallationCode, | ||||||
MissionRunType = MissionRunType.ReturnHome, | ||||||
InspectionArea = currentInspectionArea!, | ||||||
Status = MissionStatus.Pending, | ||||||
DesiredStartTime = DateTime.UtcNow, | ||||||
Tasks = [new(return_to_home_pose, MissionTaskType.ReturnHome)], | ||||||
Tasks = [new(returnToHomePose, MissionTaskType.ReturnHome)], | ||||||
}; | ||||||
|
||||||
var missionRun = await missionRunService.Create(returnToHomeMissionRun, false); | ||||||
var missionRun = await missionRunService.Create( | ||||||
returnToHomeMissionRun, | ||||||
shouldTriggerMissionCreatedEvent | ||||||
); | ||||||
logger.LogInformation( | ||||||
"Scheduled a mission for the robot {RobotName} to return to home location on inspection area {InspectionAreaName}", | ||||||
"Scheduled Return to Home mission for robot {RobotName} on Inspection Area {InspectionAreaName}", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
robot.Name, | ||||||
currentInspectionArea?.Name | ||||||
); | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we ensure that this is not null?