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

Implement undocking #1652

Merged
merged 1 commit into from
Jul 16, 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
31 changes: 17 additions & 14 deletions backend/api.test/Client/AreaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,23 @@ public async Task UpdateDefaultLocalizationPoseOnDeck()
string deckId = deck.Id;

string url = $"/decks/{deckId}/update-default-localization-pose";
var query = new Pose
var query = new CreateDefaultLocalizationPose
{
Position = new Position
Pose = new Pose
{
X = 1,
Y = 2,
Z = 3
},
Orientation = new Orientation
{
X = 0,
Y = 0,
Z = 0,
W = 1
Position = new Position
{
X = 1,
Y = 2,
Z = 3
},
Orientation = new Orientation
{
X = 0,
Y = 0,
Z = 0,
W = 1
}
}
};
var content = new StringContent(
Expand All @@ -313,8 +316,8 @@ public async Task UpdateDefaultLocalizationPoseOnDeck()
var putDeck = await putResponse.Content.ReadFromJsonAsync<DeckResponse>(_serializerOptions);
Assert.True(putDeck != null);
Assert.True(putDeck.DefaultLocalizationPose != null);
Assert.True(putDeck.DefaultLocalizationPose.Position.Z.Equals(query.Position.Z));
Assert.True(putDeck.DefaultLocalizationPose.Orientation.W.Equals(query.Orientation.W));
Assert.True(putDeck.DefaultLocalizationPose.Position.Z.Equals(query.Pose.Position.Z));
Assert.True(putDeck.DefaultLocalizationPose.Orientation.W.Equals(query.Pose.Orientation.W));
}
}
}
6 changes: 5 additions & 1 deletion backend/api.test/Client/MissionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ private static (StringContent installationContent, StringContent plantContent, S
InstallationCode = installationCode,
PlantCode = plantCode,
Name = deckName,
DefaultLocalizationPose = testPose
DefaultLocalizationPose = new CreateDefaultLocalizationPose()
{
Pose = testPose,
IsDockingStation = false
}
};

var areaQuery = new CreateAreaQuery
Expand Down
5 changes: 4 additions & 1 deletion backend/api.test/Database/DatabaseUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ public async Task<Deck> NewDeck(string installationCode, string plantCode, strin
InstallationCode = installationCode,
PlantCode = plantCode,
Name = deckName,
DefaultLocalizationPose = new Pose()
DefaultLocalizationPose = new CreateDefaultLocalizationPose()
{
Pose = new Pose()
}
};

return await _deckService.Create(createDeckQuery);
Expand Down
8 changes: 4 additions & 4 deletions backend/api/Controllers/DeckController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public async Task<ActionResult<DeckResponse>> Create([FromBody] CreateDeckQuery
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<DeckResponse>> UpdateDefaultLocalizationPose([FromRoute] string deckId, [FromBody] Pose newDefaultLocalizationPose)
public async Task<ActionResult<DeckResponse>> UpdateDefaultLocalizationPose([FromRoute] string deckId, [FromBody] CreateDefaultLocalizationPose newDefaultLocalizationPose)
{
logger.LogInformation("Updating default localization pose on deck '{deckId}'", deckId);
try
Expand All @@ -213,16 +213,16 @@ public async Task<ActionResult<DeckResponse>> UpdateDefaultLocalizationPose([Fro

if (deck.DefaultLocalizationPose != null)
{
deck.DefaultLocalizationPose.Pose = newDefaultLocalizationPose;
deck.DefaultLocalizationPose.Pose = newDefaultLocalizationPose.Pose;
deck.DefaultLocalizationPose.DockingEnabled = newDefaultLocalizationPose.IsDockingStation;
_ = await defaultLocalizationPoseService.Update(deck.DefaultLocalizationPose);
}
else
{
deck.DefaultLocalizationPose = new DefaultLocalizationPose(newDefaultLocalizationPose);
deck.DefaultLocalizationPose = new DefaultLocalizationPose(newDefaultLocalizationPose.Pose, newDefaultLocalizationPose.IsDockingStation);
deck = await deckService.Update(deck);
}


return Ok(new DeckResponse(deck));
}
catch (Exception e)
Expand Down
6 changes: 2 additions & 4 deletions backend/api/Controllers/Models/CreateDeckQuery.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using Api.Database.Models;

namespace Api.Controllers.Models
namespace Api.Controllers.Models
{
public struct CreateDeckQuery
{
public string InstallationCode { get; set; }
public string PlantCode { get; set; }
public string Name { get; set; }

public Pose? DefaultLocalizationPose { get; set; }
public CreateDefaultLocalizationPose? DefaultLocalizationPose { get; set; }
}
}
15 changes: 15 additions & 0 deletions backend/api/Controllers/Models/CreateDefaultLocalizationPose.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Api.Database.Models;

namespace Api.Controllers.Models
{
public struct CreateDefaultLocalizationPose
{
public CreateDefaultLocalizationPose()
{
Pose = new Pose();
}

public Pose Pose { get; set; }
public bool IsDockingStation { get; set; } = false;
}
}
9 changes: 9 additions & 0 deletions backend/api/Database/Models/DefaultLocalizationPose.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class DefaultLocalizationPose
[Required]
public Pose Pose { get; set; }

[Required]
public bool DockingEnabled { get; set; } = false;

public DefaultLocalizationPose()
{
Pose = new Pose();
Expand All @@ -22,5 +25,11 @@ public DefaultLocalizationPose(Pose pose)
{
Pose = pose;
}

public DefaultLocalizationPose(Pose pose, bool dockingEnabled)
{
Pose = pose;
DockingEnabled = dockingEnabled;
}
}
}
2 changes: 1 addition & 1 deletion backend/api/Services/DeckService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public async Task<Deck> Create(CreateDeckQuery newDeckQuery)
DefaultLocalizationPose? defaultLocalizationPose = null;
if (newDeckQuery.DefaultLocalizationPose != null)
{
defaultLocalizationPose = await defaultLocalizationPoseService.Create(new DefaultLocalizationPose(newDeckQuery.DefaultLocalizationPose));
defaultLocalizationPose = await defaultLocalizationPoseService.Create(new DefaultLocalizationPose(newDeckQuery.DefaultLocalizationPose.Value.Pose, newDeckQuery.DefaultLocalizationPose.Value.IsDockingStation));
}

var deck = new Deck
Expand Down
8 changes: 8 additions & 0 deletions backend/api/Services/Models/IsarMissionDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public struct IsarMissionDefinition
[JsonPropertyName("start_pose")]
public IsarPose? StartPose { get; set; } = null;

[JsonPropertyName("dock")]
public bool? Dock { get; set; } = null;

[JsonPropertyName("undock")]
public bool? Undock { get; set; } = null;

public IsarMissionDefinition(List<IsarTaskDefinition> tasks)
{
Id = null;
Expand All @@ -33,6 +39,8 @@ public IsarMissionDefinition(MissionRun missionRun, bool includeStartPose = fals
Name = missionRun.Name;
Tasks = missionRun.Tasks.Select(task => new IsarTaskDefinition(task, missionRun)).ToList();
StartPose = includeStartPose && missionRun.Area.Deck.DefaultLocalizationPose != null ? new IsarPose(missionRun.Area.Deck.DefaultLocalizationPose.Pose) : null;
Undock = includeStartPose && missionRun.Area.Deck.DefaultLocalizationPose != null && missionRun.Area.Deck.DefaultLocalizationPose.DockingEnabled;
Dock = missionRun.Area.Deck.DefaultLocalizationPose != null && missionRun.Area.Deck.DefaultLocalizationPose.DockingEnabled && missionRun.IsReturnHomeMission();
}
}

Expand Down
Loading