添加单车底盘仿真平台并完善运动控制与夹臂功能

This commit is contained in:
2026-07-27 17:47:50 +08:00
parent 580a936a83
commit e6b99c45b3
47 changed files with 4238 additions and 122 deletions
+38
View File
@@ -0,0 +1,38 @@
using System.Diagnostics;
namespace MyParking.Simulation.Core;
/// <summary>
/// 以固定周期推进离线仿真世界。
/// </summary>
public sealed class SimulationClock(
SimulationWorld world,
ILogger<SimulationClock> logger) : BackgroundService
{
private static readonly TimeSpan TickInterval =
TimeSpan.FromMilliseconds(20);
protected override async Task ExecuteAsync(
CancellationToken stoppingToken)
{
logger.LogInformation(
"停车机器人离线仿真时钟已启动,周期{Period}ms。",
TickInterval.TotalMilliseconds);
using var timer = new PeriodicTimer(TickInterval);
var stopwatch = Stopwatch.StartNew();
var previousSeconds = stopwatch.Elapsed.TotalSeconds;
while (await timer.WaitForNextTickAsync(stoppingToken))
{
var currentSeconds = stopwatch.Elapsed.TotalSeconds;
var deltaTimeSeconds = Math.Clamp(
currentSeconds - previousSeconds,
0.001,
0.1);
previousSeconds = currentSeconds;
world.Step(deltaTimeSeconds);
}
}
}