优化虚拟飞机计算过程,间隔改为150ms可以基本流程模拟1000架
This commit is contained in:
parent
d1a0283dad
commit
c72399d3b0
@ -32,7 +32,7 @@ namespace Plane.Copters
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 更新虚拟飞行器状态的时间间隔,单位为毫秒。
|
/// 更新虚拟飞行器状态的时间间隔,单位为毫秒。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private const int UPDATE_INTERVAL = 100;
|
private const int UPDATE_INTERVAL = 150; //150可以跑1000架 100可以跑500架
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 对飞行器的模拟是否正在运行。
|
/// 对飞行器的模拟是否正在运行。
|
||||||
@ -139,14 +139,19 @@ namespace Plane.Copters
|
|||||||
this.Connection = connection ?? EmptyConnection.Instance;
|
this.Connection = connection ?? EmptyConnection.Instance;
|
||||||
_isRunning = true;
|
_isRunning = true;
|
||||||
// 持续计算并更新虚拟飞行器的状态。
|
// 持续计算并更新虚拟飞行器的状态。
|
||||||
Task.Run(async () =>
|
// Task.Run(async () =>
|
||||||
{
|
|
||||||
|
Task.Factory.StartNew(async () =>
|
||||||
|
|
||||||
|
{
|
||||||
while (_isRunning)
|
while (_isRunning)
|
||||||
{
|
{
|
||||||
Update();
|
Update();
|
||||||
await TaskUtils.Delay(UPDATE_INTERVAL).ConfigureAwait(false);
|
await TaskUtils.Delay(UPDATE_INTERVAL).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
, TaskCreationOptions.LongRunning
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
++HeartbeatCount;
|
++HeartbeatCount;
|
||||||
@ -682,10 +687,12 @@ namespace Plane.Copters
|
|||||||
// 更新高度。
|
// 更新高度。
|
||||||
Altitude += altDelta;
|
Altitude += altDelta;
|
||||||
|
|
||||||
|
|
||||||
// 目标点相对于当前位置的方向。
|
// 目标点相对于当前位置的方向。
|
||||||
var direction = this.CalcDirection2D(lat, lng);
|
var direction = this.CalcDirection2D(lat, lng);
|
||||||
|
/*
|
||||||
// 更新姿态。
|
// 更新姿态。
|
||||||
|
|
||||||
if (Mode == FlightMode.RTL)
|
if (Mode == FlightMode.RTL)
|
||||||
{
|
{
|
||||||
// 林俊清, 20160126, 目前飞行器只在返航时会旋转机头,面对飞行方向。
|
// 林俊清, 20160126, 目前飞行器只在返航时会旋转机头,面对飞行方向。
|
||||||
@ -701,6 +708,7 @@ namespace Plane.Copters
|
|||||||
// Roll = MAX_TILT_IN_FLIGHT * (float)Math.Sin(directionDelta);
|
// Roll = MAX_TILT_IN_FLIGHT * (float)Math.Sin(directionDelta);
|
||||||
// Pitch = MAX_TILT_IN_FLIGHT * (float)Math.Cos(directionDelta);
|
// Pitch = MAX_TILT_IN_FLIGHT * (float)Math.Cos(directionDelta);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// 水平面上的移动距离。
|
// 水平面上的移动距离。
|
||||||
var moveInHorizontalPlane = Math.Sqrt(move * move - altDelta * altDelta);
|
var moveInHorizontalPlane = Math.Sqrt(move * move - altDelta * altDelta);
|
||||||
|
Loading…
Reference in New Issue
Block a user