Skip to content

Commit

Permalink
Improve estimate for remainding time
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Jan 30, 2025
1 parent 58e4b19 commit 9d82759
Show file tree
Hide file tree
Showing 11 changed files with 1,340 additions and 63 deletions.
10 changes: 5 additions & 5 deletions backend/api/Controllers/MissionSchedulingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ [FromBody] ScheduleMissionQuery scheduledMissionQuery

if (newMissionRun.Tasks.Any())
{
newMissionRun.CalculateEstimatedDuration();
newMissionRun.SetEstimatedTaskDuration();
}

// Compare with GetTasksFromSource
Expand Down Expand Up @@ -221,7 +221,7 @@ await localizationService.EnsureRobotIsOnSameInstallationAsMission(

if (missionRun.Tasks.Any())
{
missionRun.CalculateEstimatedDuration();
missionRun.SetEstimatedTaskDuration();
}

MissionRun newMissionRun;
Expand Down Expand Up @@ -428,7 +428,7 @@ [.. missionInspectionAreaNames]

if (missionRun.Tasks.Any())
{
missionRun.CalculateEstimatedDuration();
missionRun.SetEstimatedTaskDuration();
}

if (existingMissionDefinition == null)
Expand Down Expand Up @@ -623,7 +623,7 @@ await localizationService.EnsureRobotIsOnSameInstallationAsMission(

if (scheduledMission.Tasks.Any())
{
scheduledMission.CalculateEstimatedDuration();
scheduledMission.SetEstimatedTaskDuration();
}
else if (
scheduledMission.Robot.CurrentInspectionArea != null
Expand All @@ -633,7 +633,7 @@ await localizationService.EnsureRobotIsOnSameInstallationAsMission(
)
)
{
scheduledMission.CalculateEstimatedDuration();
scheduledMission.SetEstimatedTaskDuration();
}

if (
Expand Down
4 changes: 2 additions & 2 deletions backend/api/Controllers/Models/MissionRunResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class MissionRunResponse

public DateTime? EndTime { get; private set; }

public uint? EstimatedDuration { get; set; }
public uint? EstimatedTaskDuration { get; set; }

public IList<MissionTask> Tasks { get; set; }

Expand Down Expand Up @@ -67,7 +67,7 @@ public MissionRunResponse(MissionRun mission)
DesiredStartTime = mission.DesiredStartTime;
StartTime = mission.StartTime;
EndTime = mission.EndTime;
EstimatedDuration = mission.EstimatedDuration;
EstimatedTaskDuration = mission.EstimatedTaskDuration;
Tasks = mission.Tasks;
MissionRunType = mission.MissionRunType;
}
Expand Down
39 changes: 4 additions & 35 deletions backend/api/Database/Models/MissionRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ or MissionStatus.PartiallySuccessful
public DateTime? EndTime { get; private set; }

/// <summary>
/// The estimated duration of the mission in seconds
/// The estimated duration of each task in the mission in seconds
/// </summary>
public uint? EstimatedDuration { get; set; }
public uint? EstimatedTaskDuration { get; set; }

[Required]
[MaxLength(200)]
Expand Down Expand Up @@ -129,42 +129,11 @@ public static MissionStatus GetMissionStatusFromString(string status)
};
}

public void CalculateEstimatedDuration()
public void SetEstimatedTaskDuration()
{
if (Robot.Model.AverageDurationPerTag is not null)
{
float totalInspectionDuration = Tasks.Sum(task =>
task.Inspection?.VideoDuration ?? 0
);
EstimatedDuration = (uint)(
(Robot.Model.AverageDurationPerTag * Tasks.Count) + totalInspectionDuration
);
}
else
{
const double RobotVelocity = 1.5 * 1000 / 60; // km/t => m/min
const double EfficiencyFactor = 0.20;
const double InspectionTime = 2; // min/tag
const int AssumedXyMetersFromFirst = 20;

double distance = 0;
var prevPosition = new Position(
Tasks.First().RobotPose.Position.X + AssumedXyMetersFromFirst,
Tasks.First().RobotPose.Position.Y + AssumedXyMetersFromFirst,
Tasks.First().RobotPose.Position.Z
);
foreach (var task in Tasks)
{
var currentPosition = task.RobotPose.Position;
distance +=
Math.Abs(currentPosition.X - prevPosition.X)
+ Math.Abs(currentPosition.Y - prevPosition.Y);
prevPosition = currentPosition;
}
int estimate = (int)(
(distance / (RobotVelocity * EfficiencyFactor)) + InspectionTime
);
EstimatedDuration = (uint)estimate * 60;
EstimatedTaskDuration = (uint)Robot.Model.AverageDurationPerTag;
}
}

Expand Down
Loading

0 comments on commit 9d82759

Please sign in to comment.