86 lines
3.5 KiB
C#
86 lines
3.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using MultiWheelC.TrajectoryPlanning.CoarsePath;
|
|
using MultiWheelC.TrajectoryPlanning.Mapping;
|
|
|
|
namespace MultiWheelC.TrajectoryPlanning.PathSmoothing;
|
|
|
|
/// <summary>路径平滑所需的原始粗路径、复核上下文和配置。</summary>
|
|
public sealed class PathSmoothingRequest
|
|
{
|
|
/// <summary>创建路径平滑请求,并复制粗路径和方向分段集合。</summary>
|
|
public PathSmoothingRequest(
|
|
IReadOnlyList<CoarsePathPoint> coarsePath,
|
|
IReadOnlyList<PathSegment> segments,
|
|
PlanningGridMap map,
|
|
VehicleParameters vehicle,
|
|
PathSmoothingConfiguration configuration)
|
|
{
|
|
CoarsePath = CopyReadOnly(coarsePath);
|
|
Segments = CopyReadOnly(segments);
|
|
Map = map;
|
|
Vehicle = CopyVehicle(vehicle);
|
|
Configuration = CopyConfiguration(configuration);
|
|
}
|
|
|
|
/// <summary>原始粗路径的不可变快照。</summary>
|
|
public IReadOnlyList<CoarsePathPoint> CoarsePath { get; }
|
|
|
|
/// <summary>原始粗路径方向分段的不可变快照。</summary>
|
|
public IReadOnlyList<PathSegment> Segments { get; }
|
|
|
|
/// <summary>用于平滑后完整车体复核的规划栅格地图。</summary>
|
|
public PlanningGridMap Map { get; }
|
|
|
|
/// <summary>车辆几何与最大曲率约束。</summary>
|
|
public VehicleParameters Vehicle { get; }
|
|
|
|
/// <summary>本次平滑的配置。</summary>
|
|
public PathSmoothingConfiguration Configuration { get; }
|
|
|
|
private static IReadOnlyList<T> CopyReadOnly<T>(IReadOnlyList<T> source)
|
|
{
|
|
var copy = new List<T>(source == null ? 0 : source.Count);
|
|
if (source != null)
|
|
{
|
|
for (int index = 0; index < source.Count; index++)
|
|
copy.Add(source[index]);
|
|
}
|
|
return new ReadOnlyCollection<T>(copy);
|
|
}
|
|
|
|
private static VehicleParameters CopyVehicle(VehicleParameters source)
|
|
{
|
|
if (source == null) return null;
|
|
return new VehicleParameters
|
|
{
|
|
LengthMeters = source.LengthMeters,
|
|
WidthMeters = source.WidthMeters,
|
|
SafetyMarginMeters = source.SafetyMarginMeters,
|
|
MaximumCurvaturePerMeter = source.MaximumCurvaturePerMeter,
|
|
MinimumTurningRadiusMeters = source.MinimumTurningRadiusMeters,
|
|
};
|
|
}
|
|
|
|
private static PathSmoothingConfiguration CopyConfiguration(PathSmoothingConfiguration source)
|
|
{
|
|
if (source == null) return null;
|
|
var copy = new PathSmoothingConfiguration
|
|
{
|
|
Method = source.Method,
|
|
OutputSpacingMeters = source.OutputSpacingMeters,
|
|
MaximumCollisionCheckStepMeters = source.MaximumCollisionCheckStepMeters,
|
|
MinimumClearanceReserveMeters = source.MinimumClearanceReserveMeters,
|
|
SmoothingStrength = source.SmoothingStrength,
|
|
AllowFallbackToCoarsePath = source.AllowFallbackToCoarsePath,
|
|
};
|
|
copy.CubicBSpline.EndpointTangentScale = source.CubicBSpline.EndpointTangentScale;
|
|
copy.LocalCubicBezier.CornerHeadingThresholdRadians = source.LocalCubicBezier.CornerHeadingThresholdRadians;
|
|
copy.LocalCubicBezier.MaximumWindowLengthMeters = source.LocalCubicBezier.MaximumWindowLengthMeters;
|
|
copy.LocalCubicBezier.HandleLengthRatio = source.LocalCubicBezier.HandleLengthRatio;
|
|
copy.PiecewiseQuintic.KnotSpacingMeters = source.PiecewiseQuintic.KnotSpacingMeters;
|
|
copy.PiecewiseQuintic.MinimumKnotSpacingMeters = source.PiecewiseQuintic.MinimumKnotSpacingMeters;
|
|
return copy;
|
|
}
|
|
}
|