Skip to content

Commit

Permalink
Add support for scheduling custom json missions
Browse files Browse the repository at this point in the history
  • Loading branch information
GodVenn committed Apr 25, 2023
1 parent 95a3340 commit 65f79de
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
47 changes: 47 additions & 0 deletions backend/api/Controllers/MissionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public async Task<ActionResult<byte[]>> GetMap([FromRoute] string id)
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<Mission>> Create(
[FromBody] ScheduledMissionQuery scheduledMissionQuery
Expand Down Expand Up @@ -234,6 +235,52 @@ [FromBody] ScheduledMissionQuery scheduledMissionQuery
return CreatedAtAction(nameof(GetMissionById), new { id = newMission.Id }, newMission);
}

/// <summary>
/// Schedule a custom mission
/// </summary>
/// <remarks>
/// <para> This query schedules a custom mission defined in the incoming json </para>
/// </remarks>
[HttpPost]
[Route("custom")]
[ProducesResponseType(typeof(Mission), StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<Mission>> Create(
[FromBody] CustomMissionQuery customMissionQuery
)
{
var robot = await _robotService.ReadById(customMissionQuery.RobotId);
if (robot is null)
return NotFound($"Could not find robot with id {customMissionQuery.RobotId}");

var missionTasks = customMissionQuery.Tasks.Select(task => new MissionTask(task)).ToList();

var scheduledMission = new Mission
{
Name = customMissionQuery.Name,
Robot = robot,
EchoMissionId = 0,
Status = MissionStatus.Pending,
DesiredStartTime = customMissionQuery.DesiredStartTime,
Tasks = missionTasks,
AssetCode = customMissionQuery.AssetCode,
Map = new MissionMap()
};

await _mapService.AssignMapToMission(scheduledMission);

if (scheduledMission.Tasks.Any())
scheduledMission.CalculateEstimatedDuration();

var newMission = await _missionService.Create(scheduledMission);

return CreatedAtAction(nameof(GetMissionById), new { id = newMission.Id }, newMission);
}

/// <summary>
/// Deletes the mission with the specified id from the database.
/// </summary>
Expand Down
41 changes: 41 additions & 0 deletions backend/api/Controllers/Models/CustomMissionQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Api.Database.Models;

namespace Api.Controllers.Models
{
public struct CustomInspectionQuery
{
public InspectionType InspectionType { get; set; }

public float? VideoDuration { get; set; }

public string? AnalysisTypes { get; set; }
}

public struct CustomTaskQuery
{
public int TaskOrder { get; set; }

public Position InspectionTarget { get; set; }

public Pose RobotPose { get; set; }

public List<CustomInspectionQuery> Inspections { get; set; }
}

public struct CustomMissionQuery
{
public string RobotId { get; set; }

public DateTimeOffset DesiredStartTime { get; set; }

public string AssetCode { get; set; }

public string Name { get; set; }

public string? Description { get; set; }

public string? Comment { get; set; }

public List<CustomTaskQuery> Tasks { get; set; }
}
}
8 changes: 8 additions & 0 deletions backend/api/Database/Models/Inspection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public Inspection(EchoInspection echoInspection)
Status = InspectionStatus.NotStarted;
}

public Inspection(CustomInspectionQuery inspectionQuery)
{
InspectionType = inspectionQuery.InspectionType;
VideoDuration = inspectionQuery.VideoDuration;
AnalysisTypes = inspectionQuery.AnalysisTypes;
Status = InspectionStatus.NotStarted;
}

public void UpdateWithIsarInfo(IsarStep isarStep)
{
UpdateStatus(isarStep.StepStatus);
Expand Down
12 changes: 12 additions & 0 deletions backend/api/Database/Models/MissionTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ public MissionTask(EchoTag echoTag, Position tagPosition)
Status = TaskStatus.NotStarted;
}

// ReSharper disable once NotNullOrRequiredMemberIsNotInitialized
public MissionTask(CustomTaskQuery taskQuery)
{
Inspections = taskQuery.Inspections
.Select(inspection => new Inspection(inspection))
.ToList();
InspectionTarget = taskQuery.InspectionTarget;
RobotPose = taskQuery.RobotPose;
TaskOrder = taskQuery.TaskOrder;
Status = TaskStatus.NotStarted;
}

public void UpdateWithIsarInfo(IsarTask isarTask)
{
UpdateStatus(isarTask.TaskStatus);
Expand Down

0 comments on commit 65f79de

Please sign in to comment.