mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-23 18:39:26 +08:00
fb4eece24d
# Description
_Describe the changes here to communicate to the maintainers why they
should accept this pull request. By default - this will become the
Commit message after merging and thus define history._
Fix OpenUSD sample discovery and integrate artifact delivery with the
xRegistry companion model.
- Load xRegistry before OpenUSD in the sample node managers, mount
stages with `Organizes`, and align root-layer identifiers with served
`.usda` files.
- Bootstrap immutable logical Resources and exact Versions in
`Artifacts`. Stage `Assets` folders provide non-owning `Organizes`
views, and explicit container identifiers allow sharing.
- Update the binding model to draft 0.9.0 while preserving existing
NodeIds and the `HasAddIn` correction.
- Disambiguate default container identifiers by stage instance, publish
the required read-only capabilities map, and preserve standard and
xRegistry BrowseName namespaces.
- Add registry, file-delivery, sharing, collision, qualified-browse, and
live-discovery regressions. Update the OpenUSD documentation.
Review fixes are in 6ac47a5b82. All four
review threads have been answered and resolved.
**Local validation**
| Command | Result |
| --- | --- |
| `dotnet test tests/Opc.Ua.OpenUsd.Tests/Opc.Ua.OpenUsd.Tests.csproj
--no-restore -f net10.0 -p:CustomTestTarget=net10.0 --verbosity quiet` |
Passed: 1,178 tests. |
| `dotnet test tests/Opc.Ua.OpenUsd.Tests/Opc.Ua.OpenUsd.Tests.csproj -f
net48 -p:CustomTestTarget=net48 --filter
FullyQualifiedName~UsdAssetDeliveryTests --verbosity quiet` | Passed: 36
focused regressions, including build and dependency restore. |
| `dotnet test tests/Opc.Ua.OpenUsd.Tests/Opc.Ua.OpenUsd.Tests.csproj
--no-build --no-restore -f net48 -p:CustomTestTarget=net48 --verbosity
quiet` | Failed: 937 passed; five generator integration tests failed
during fixture setup because Mono does not implement
`ECDsa.Create(ECCurve)`. |
The full `UA.slnx` suite and coverage measurement were not run locally.
## Related Issues
_Reference all GitHub issues this PR addresses. If there is no issue
yet, open one and link it here._
_If this is a relatively large or complex change, a design must have
been discussed in the related tracking issue and signed off (which
becomes the Architectural Decision Record (ADR))._
No linked tracking issue.
## Checklist
_Put an `x` in the boxes that apply. You can complete these step by step
after opening the PR._
- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [ ] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [x] I have added all necessary documentation.
- [x] I have verified that my changes do not introduce (new) build or
analyzer warnings.
- [ ] I ran **all** tests locally using the **UA.slnx** solution against
at least .net **framework** and .net **10**, and all passed.
- [ ] I fixed **all** failing and flaky tests in the CI pipelines and
**all** CodeQL warnings.
- [x] I have addressed **all** PR feedback received.
192 lines
8.8 KiB
C#
192 lines
8.8 KiB
C#
/* ========================================================================
|
|
* Copyright (c) 2005-2026 The OPC Foundation, Inc. All rights reserved.
|
|
*
|
|
* OPC Foundation MIT License 1.00
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person
|
|
* obtaining a copy of this software and associated documentation
|
|
* files (the "Software"), to deal in the Software without
|
|
* restriction, including without limitation the rights to use,
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following
|
|
* conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* The complete license agreement can be found here:
|
|
* http://opcfoundation.org/License/MIT/1.00/
|
|
* ======================================================================*/
|
|
|
|
using System;
|
|
using System.IO;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Opc.Ua;
|
|
using Opc.Ua.Robotics.Server;
|
|
using Opc.Ua.Server;
|
|
using Opc.Ua.Vision.OpenUsd;
|
|
using Robotics.IntentEnabledRobot.Kinematics;
|
|
using Robotics.IntentEnabledRobot.Simulation;
|
|
using Vision.BinPickingCell;
|
|
|
|
BinPickingCellStage stage = new();
|
|
string stagePath = stage.Extract();
|
|
|
|
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
|
|
|
|
builder.Logging.ClearProviders();
|
|
builder.Logging.EnableOpcUaRedaction();
|
|
builder.Logging.AddConsole();
|
|
|
|
int port = int.TryParse(builder.Configuration["port"], out int configuredPort)
|
|
? configuredPort
|
|
: 62855;
|
|
string host = builder.Configuration["host"] is { Length: > 0 } configuredHost
|
|
? configuredHost
|
|
: "localhost";
|
|
bool captureOnStartup = !string.Equals(builder.Configuration["captureOnStartup"], "false",
|
|
StringComparison.OrdinalIgnoreCase);
|
|
string? artifactDirectory = builder.Configuration["artifactDirectory"];
|
|
BinPickingCellOptions cellOptions = BuildCellOptions(builder.Configuration);
|
|
bool offServer = cellOptions.InferenceLocation == BinPickingInferenceLocation.EdgeOffServer;
|
|
|
|
var sensorSpec = new BinPickingSensorSpec(
|
|
StageIdentifier: stagePath,
|
|
CameraPrimPath: BinPickingVisionCell.CameraPrimPath,
|
|
PixelFormat: BinPickingVisionCell.PixelFormat,
|
|
CaptureWidth: (int)BinPickingVisionCell.SensorWidth,
|
|
CaptureHeight: (int)BinPickingVisionCell.SensorHeight);
|
|
|
|
builder.Services.AddSingleton(stage);
|
|
builder.Services.AddSingleton(sensorSpec);
|
|
builder.Services.AddSingleton(cellOptions);
|
|
|
|
// The arm is bolted to the bench, so the bench is z = 0 in its own base frame. Telling
|
|
// the solver that stops it handing back configurations that reach through the work
|
|
// surface - several inverse-kinematic solutions for a target near the bench do exactly
|
|
// that, and taking the nearest one regardless renders an arm passing through its table.
|
|
//
|
|
// The height alone is not enough, though: it is a plane sampled at the joint origins, so a
|
|
// link can span it, and it says nothing about the bin or the fixture.
|
|
// BinPickingCellGeometry.CreateCollisionModel() describes the cell's furniture as solids
|
|
// and SimulatedArmKinematics.Collisions enforces it along every link, so a configuration
|
|
// that puts part of the arm inside the bench or through a bin wall is refused rather than
|
|
// rendered. The palletizer kinematics tests pin the remaining work envelope at every cell
|
|
// work position.
|
|
builder.Services.AddSingleton(_ => new BinPickingPalletizerKinematics
|
|
{
|
|
MinimumLinkHeight =
|
|
BinPickingCellGeometry.BenchTopMetres - BinPickingCellGeometry.RobotBaseHeightMetres,
|
|
Collisions = BinPickingCellGeometry.CreateCollisionModel()
|
|
});
|
|
builder.Services.AddSingleton<BinPickingRobotCell>();
|
|
builder.Services.TryAddEnumerable(
|
|
ServiceDescriptor.Singleton<IRobotIntentModelProvider, Robotics.IntentEnabledRobot.OpenUsdIntentModelProvider>());
|
|
builder.Services.AddSingleton<BinPickingWorldState>();
|
|
builder.Services.AddSingleton<IBinPickingTargetProvider, BinPickingTargetProvider>();
|
|
builder.Services.AddSingleton<BinPickingGroundTruthInferenceProvider>();
|
|
builder.Services.AddSingleton<BinPickingAgentInferenceProvider>();
|
|
builder.Services.AddSingleton<BinPickingVisionCell>();
|
|
builder.Services.AddSingleton<BinPickingMediaProvider>();
|
|
builder.Services.AddOpenUsdSceneCameraCaptureProvider();
|
|
builder.Services.AddHostedService(services =>
|
|
new BinPickingCaptureProof(
|
|
services.GetRequiredService<ISceneCameraCaptureProvider>(),
|
|
services.GetRequiredService<BinPickingCellStage>(),
|
|
services.GetRequiredService<ILogger<BinPickingCaptureProof>>(),
|
|
enabled: captureOnStartup,
|
|
artifactDirectory: artifactDirectory));
|
|
if (offServer)
|
|
{
|
|
builder.Services.AddHostedService(services =>
|
|
new BinPickingOffServerProof(
|
|
services.GetRequiredService<BinPickingAgentInferenceProvider>(),
|
|
services.GetRequiredService<ILogger<BinPickingOffServerProof>>()));
|
|
}
|
|
else
|
|
{
|
|
builder.Services.AddHostedService(services =>
|
|
new BinPickingInferenceProof(
|
|
services.GetRequiredService<BinPickingGroundTruthInferenceProvider>(),
|
|
services.GetRequiredService<BinPickingWorldState>(),
|
|
services.GetRequiredService<ILogger<BinPickingInferenceProof>>()));
|
|
}
|
|
|
|
builder.Services
|
|
.AddOpcUa()
|
|
.AddServer(options =>
|
|
{
|
|
options.ApplicationName = "BinPickingCell";
|
|
options.ApplicationUri = "urn:localhost:OPCFoundation:BinPickingCell";
|
|
options.ProductUri = "uri:opcfoundation.org:BinPickingCell";
|
|
options.AutoAcceptUntrustedCertificates = true;
|
|
|
|
// A rendered frame is a few hundred kilobytes and the response that carries it
|
|
// larger still, so leave the transport room for a busier scene rather than have
|
|
// GetClip refuse the cell's own camera output. Note the failure this originally
|
|
// chased was not a quota at all - the provider was embedding the encoded image in
|
|
// a String field - so none of these were ever the fix; see BinPickingMediaProvider.
|
|
options.MaxByteStringLength = 32 * 1024 * 1024;
|
|
options.MaxArrayLength = 32 * 1024 * 1024;
|
|
options.MaxMessageSize = 64 * 1024 * 1024;
|
|
options.EndpointUrls.Add($"opc.tcp://{host}:{port}/BinPickingCell");
|
|
})
|
|
.ConfigureRoles(options => options.Roles.Add(new RoleDefinitionOptions
|
|
{
|
|
Name = BrowseNames.WellKnownRole_Operator,
|
|
Identities =
|
|
{
|
|
new RoleIdentityMappingOptions
|
|
{
|
|
CriteriaType = IdentityCriteriaType.Anonymous
|
|
}
|
|
}
|
|
}))
|
|
.AddRobotIntent()
|
|
.AddRobotIntentExecutor<SimulatedArmExecutor>()
|
|
.ConfigureRobotIntent(async (context, cancellationToken) =>
|
|
await context.GetRequiredService<BinPickingRobotCell>()
|
|
.ConfigureAsync(context, cancellationToken).ConfigureAwait(false))
|
|
.AddVision(options => options.InstanceNamespaceUri = "urn:opcfoundation:BinPickingCell:vision:instances")
|
|
.AddVisionMediaProvider<BinPickingMediaProvider>(
|
|
BinPickingVisionCell.SensorTwinBrowseName)
|
|
.ConfigureVision(async (context, cancellationToken) =>
|
|
{
|
|
BinPickingVisionCell cell = context.GetRequiredService<BinPickingVisionCell>();
|
|
await cell.ConfigureAsync(context, cancellationToken).ConfigureAwait(false);
|
|
});
|
|
|
|
// AddRobotIntentExecutor registers the concrete executor so its IIntentExecutor and any
|
|
// observers share one instance. Replace that default-constructed UR executor after the
|
|
// fluent registration with the palletizer-backed instance for this cell only.
|
|
builder.Services.Replace(ServiceDescriptor.Singleton(
|
|
services => new SimulatedArmExecutor(
|
|
services.GetRequiredService<BinPickingPalletizerKinematics>())));
|
|
|
|
using IHost app = builder.Build();
|
|
await app.RunAsync().ConfigureAwait(false);
|
|
|
|
static BinPickingCellOptions BuildCellOptions(Microsoft.Extensions.Configuration.IConfiguration configuration)
|
|
{
|
|
string? raw = configuration["inferenceLocation"];
|
|
// A parse failure just means "use the OnServer default"; the out value is set for us
|
|
// and the caller does not need a separate error path for an unknown key.
|
|
_ = BinPickingCellOptions.TryParseLocation(raw, out BinPickingInferenceLocation location);
|
|
return new BinPickingCellOptions
|
|
{
|
|
InferenceLocation = location
|
|
};
|
|
}
|