去掉飞行时间,飞行距离,姿态计算和更新,提高效率

碰撞检测改为异步提示
修改任务无法停止的bug
This commit is contained in:
xu 2020-01-28 22:45:08 +08:00
parent 1308b31717
commit d1a0283dad
2 changed files with 24 additions and 14 deletions

View File

@ -179,6 +179,7 @@ namespace Plane.Copters
public CopterImplSharedPart(SynchronizationContext uiSyncContext) : base(uiSyncContext)
{
PropertyChanged += CopterImplSharedPart_PropertyChanged;
/*
Task.Run(async () =>
{
while (true)
@ -230,7 +231,9 @@ namespace Plane.Copters
await Task.Delay(5000).ConfigureAwait(false);
}
}
});
*/
}
public event EventHandler AltitudeChanged;

View File

@ -137,16 +137,13 @@ namespace Plane.Copters
_scaledFastMaxMoveInInterval = MAX_MOVE_IN_INTERVAL_FAST * _speedScale;
this.Connection = connection ?? EmptyConnection.Instance;
_isRunning = true;
// 持续计算并更新虚拟飞行器的状态。
Task.Run(async () =>
{
while (true)
while (_isRunning)
{
if (_isRunning)
{
Update();
}
Update();
await TaskUtils.Delay(UPDATE_INTERVAL).ConfigureAwait(false);
}
});
@ -424,11 +421,15 @@ namespace Plane.Copters
protected override void UpdateFlightDataIfNeeded()
{
//计算飞机距离,没必要
/*
if (!TakeOffPoint.IsNullOrEmpty())
{
FlightDistance = TakeOffPoint.CalcDistance(this);
FlightDistance2D = TakeOffPoint.CalcDistance2D(this);
}
if (FlightTimeSpan.TotalSeconds > 0)
{
if (_lastCalcSpeedPoint.IsNullOrEmpty())
@ -457,6 +458,7 @@ namespace Plane.Copters
}
}
}
*/
}
private void MoveToPointImmediately(double lat, double lng, float alt)
@ -520,7 +522,8 @@ namespace Plane.Copters
case FlightMode.GUIDED:
// 林俊清, 20160317, 指点时也能体感控制若干通道。
UpdateWithChannels();
//考虑不更新这个,好像没必要-xu
//UpdateWithChannels();
UpdateWithDestination(_targetLat, _targetLng, _targetAlt);
break;
@ -590,11 +593,14 @@ namespace Plane.Copters
}
_uiSyncContext.Post(() =>
{
//位置变化需要在UI刷新
RaiseLocationChangedIfNeeded();
RaiseAltitudeChangedIfNeeded();
RaiseDataStreamReceived(PDataStreamType.GPS_RAW_INT);
RaiseAttitudeChanged();
//高度变化需要在UI刷新
// RaiseAltitudeChangedIfNeeded();
//GPS数据用于显示
// RaiseDataStreamReceived(PDataStreamType.GPS_RAW_INT);
//不考虑姿态
// RaiseAttitudeChanged();
});
}
@ -690,9 +696,10 @@ namespace Plane.Copters
}
else
{
var directionDelta = direction - Heading.DegToRad();
Roll = MAX_TILT_IN_FLIGHT * (float)Math.Sin(directionDelta);
Pitch = MAX_TILT_IN_FLIGHT * (float)Math.Cos(directionDelta);
//不用更新姿态-xu
//var directionDelta = direction - Heading.DegToRad();
// Roll = MAX_TILT_IN_FLIGHT * (float)Math.Sin(directionDelta);
// Pitch = MAX_TILT_IN_FLIGHT * (float)Math.Cos(directionDelta);
}
// 水平面上的移动距离。