Skip to content

Commit

Permalink
Refactor naming of type of mission tasks for the case of return to home
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed Mar 4, 2024
1 parent 083456a commit 3751a6f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/api/Database/Models/MissionRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ var inspection in task.Inspections.Where(inspection => !inspection.IsCompleted)

public bool IsLocalizationMission() { return Tasks is [{ Type: MissionTaskType.Localization }]; }

public bool IsDriveToMission() { return Tasks is [{ Type: MissionTaskType.DriveTo }]; }
public bool IsReturnHomeMission() { return Tasks is [{ Type: MissionTaskType.ReturnHome }]; }
}

public enum MissionStatus
Expand Down
8 changes: 4 additions & 4 deletions backend/api/Database/Models/MissionTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public MissionTask(Pose robotPose, MissionTaskType type)
Status = TaskStatus.NotStarted;
Inspections = new List<Inspection>();
break;
case MissionTaskType.DriveTo:
case MissionTaskType.ReturnHome:
Type = type;
Description = "Return to home";
RobotPose = robotPose;
Expand All @@ -65,7 +65,7 @@ public MissionTask(Pose robotPose, MissionTaskType type)
Inspections = new List<Inspection>();
break;
default:
throw new MissionTaskNotFoundException("MissionTaskType should be Localization or DriveTo");
throw new MissionTaskNotFoundException("MissionTaskType should be Localization or ReturnHome");
}
}

Expand Down Expand Up @@ -175,7 +175,7 @@ public void UpdateStatus(IsarTaskStatus isarStatus)

public static string ConvertMissionTaskTypeToIsarTaskType(MissionTaskType missionTaskType)
{
if (missionTaskType == MissionTaskType.DriveTo) { return "drive_to"; }
if (missionTaskType == MissionTaskType.ReturnHome) { return "drive_to"; }
else { return missionTaskType.ToString().ToLower(CultureInfo.CurrentCulture); }
}
}
Expand All @@ -195,6 +195,6 @@ public enum MissionTaskType
{
Inspection,
Localization,
DriveTo
ReturnHome
}
}
6 changes: 3 additions & 3 deletions backend/api/Services/MissionRunService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ public async Task<bool> PendingOrOngoingReturnToHomeMissionRunExists(string robo
var pendingMissionRuns = await ReadMissionRunQueue(robotId);
foreach (var pendingMissionRun in pendingMissionRuns)
{
if (pendingMissionRun.IsDriveToMission()) { return true; }
if (pendingMissionRun.IsReturnHomeMission()) { return true; }
}
var ongoingMissionRuns = await GetMissionRunsWithSubModels()
.Where(missionRun => missionRun.Robot.Id == robotId && missionRun.Status == MissionStatus.Ongoing)
.OrderBy(missionRun => missionRun.DesiredStartTime)
.ToListAsync();
foreach (var ongoingMissionRun in ongoingMissionRuns)
{
if (ongoingMissionRun.IsDriveToMission()) { return true; }
if (ongoingMissionRun.IsReturnHomeMission()) { return true; }
}
return false;

Expand Down Expand Up @@ -398,7 +398,7 @@ MissionRunQueryStringParameters parameters

Expression<Func<MissionRun, bool>> returnTohomeFilter = !parameters.ExcludeReturnToHome
? missionRun => true
: missionRun => !(missionRun.Tasks.Count() == 1 && missionRun.Tasks.All(task => task.Type == MissionTaskType.DriveTo));
: missionRun => !(missionRun.Tasks.Count() == 1 && missionRun.Tasks.All(task => task.Type == MissionTaskType.ReturnHome));

var minStartTime = DateTimeUtilities.UnixTimeStampToDateTime(parameters.MinStartTime);
var maxStartTime = DateTimeUtilities.UnixTimeStampToDateTime(parameters.MaxStartTime);
Expand Down
4 changes: 2 additions & 2 deletions backend/api/Services/ReturnToHomeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private async Task<bool> IsRobotHome(string robotId)
return false;
}

return lastExecutedMissionRun.IsDriveToMission();
return lastExecutedMissionRun.IsReturnHomeMission();
}
private async Task<bool> IsReturnToHomeMissionAlreadyScheduled(string robotId)
{
Expand Down Expand Up @@ -98,7 +98,7 @@ private async Task<MissionRun> ScheduleReturnToHomeMissionRun(string robotId)
DesiredStartTime = DateTime.UtcNow,
Tasks = new List<MissionTask>
{
new(new Pose(robot.CurrentArea.Deck.DefaultLocalizationPose.Pose), MissionTaskType.DriveTo)
new(new Pose(robot.CurrentArea.Deck.DefaultLocalizationPose.Pose), MissionTaskType.ReturnHome)
},
Map = new MapMetadata()
};
Expand Down

0 comments on commit 3751a6f

Please sign in to comment.