Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Thick-Common
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
潘栩锋
Thick-Common
Commits
5d83800f
Commit
5d83800f
authored
Nov 26, 2019
by
潘栩锋
🚴
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自动 调整速度,记录 TimeGridAdv
parent
52fa4a1a
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
749 additions
and
390 deletions
+749
-390
FlyAD7.cs
Project.FLY.FlyADBase/FlyADBase/FlyAD7.cs
+45
-31
AutoGetGridAdv.cs
Project.FLY.FlyADBase/Flyad7_WPF/AutoGetGridAdv.cs
+222
-0
DebugAppParam.cs
Project.FLY.FlyADBase/Flyad7_WPF/DebugAppParam.cs
+51
-31
Flyad7_WPF.csproj
Project.FLY.FlyADBase/Flyad7_WPF/Flyad7_WPF.csproj
+5
-0
GridAdvVm.cs
Project.FLY.FlyADBase/Flyad7_WPF/GridAdvVm.cs
+332
-0
MainWindow.xaml
Project.FLY.FlyADBase/Flyad7_WPF/MainWindow.xaml
+73
-18
MainWindow.xaml.cs
Project.FLY.FlyADBase/Flyad7_WPF/MainWindow.xaml.cs
+21
-310
No files found.
Project.FLY.FlyADBase/FlyADBase/FlyAD7.cs
View file @
5d83800f
...
...
@@ -48,7 +48,7 @@ namespace FlyADBase
dt
=
DateTime
.
Now
;
}
public
bool
NeedGet
(
DateTime
now
,
TimeSpan
delay
)
public
bool
NeedGet
(
DateTime
now
,
TimeSpan
delay
)
{
if
(
bNeedGet
)
{
...
...
@@ -209,7 +209,7 @@ namespace FlyADBase
(
e
.
PropertyName
==
"HVelocity2"
))
{
FObjBase
.
PollModule
.
Current
.
Poll_JustOnce
(
delegate
()
delegate
()
{
//TODO,不应该直接修改Velocity,SVelocity。。。。。。
//所以下面也不可能存在!!!
...
...
@@ -220,7 +220,7 @@ namespace FlyADBase
(
e
.
PropertyName
==
"JogVelocity"
))
{
FObjBase
.
PollModule
.
Current
.
Poll_JustOnce
(
delegate
()
delegate
()
{
CurrObjSys
.
SetValueEx
(
conn
,
FLYAD7_OBJ_INTERFACE
.
SYS_DATA_INTERFACE
.
ID
,
ID
,
FLYAD7_OBJ_INTERFACE
.
SYS_DATA_INTERFACE
.
SET_ZERO_POS
,
...
...
@@ -237,7 +237,7 @@ namespace FlyADBase
(
e
.
PropertyName
==
"Ratio02"
))
{
FObjBase
.
PollModule
.
Current
.
Poll_JustOnce
(
delegate
()
delegate
()
{
SetSysParam
(
PosOfGrid
,
MotorType
,
Ratio01
,
Ratio02
);
},
this
,
MARKNO_SET_SYSPARAM
);
...
...
@@ -411,7 +411,7 @@ namespace FlyADBase
Position2
=
pack
.
pos2
;
if
(!
IsCalSpeed
)
if
(!
IsCalSpeed
)
Speed2
=
pack
.
speed2
;
}
break
;
...
...
@@ -596,6 +596,11 @@ namespace FlyADBase
}
}
TSysTick
mSysTick
=
new
TSysTick
();
private
int
pos1_version
{
get
;
set
;
}
=
2
;
private
int
io_version
{
get
;
set
;
}
=
2
;
private
int
timegrid_version
{
get
;
set
;
}
=
2
;
private
int
grid_version
{
get
;
set
;
}
=
2
;
public
override
void
PushInfo
(
IFConn
from
,
uint
srcid
,
ushort
infoid
,
byte
[]
infodata
)
{
bShieldSetValueEx
=
true
;
...
...
@@ -605,16 +610,17 @@ namespace FlyADBase
{
FLYAD7_OBJ_INTERFACE
.
PUSH_DATA_INTERFACE
.
Pack_PushPos1_2
pack
=
new
FLYAD7_OBJ_INTERFACE
.
PUSH_DATA_INTERFACE
.
Pack_PushPos1_2
();
int
version
;
if
(!
pack
.
TryParse_version
(
infodata
,
out
version
))
if
(!
pack
.
TryParse_version
(
infodata
,
out
version
))
break
;
Version
=
version
;
if
(
version
==
1
)
pos1_version
=
version
;
if
(
version
==
1
)
{
Position
=
pack
.
pos1
;
if
(!
IsCalSpeed
)
Speed
=
pack
.
speed1
;
}
else
if
(
version
==
2
)
else
if
(
version
==
2
)
{
Position
=
pack
.
pos1
;
if
(!
IsCalSpeed
)
...
...
@@ -629,9 +635,8 @@ namespace FlyADBase
{
FLYAD7_OBJ_INTERFACE
.
PUSH_DATA_INTERFACE
.
Pack_PushPos2_2
pack
=
new
FLYAD7_OBJ_INTERFACE
.
PUSH_DATA_INTERFACE
.
Pack_PushPos2_2
();
int
version
;
if
(!
pack
.
TryParse_version
(
infodata
,
out
version
))
if
(!
pack
.
TryParse_version
(
infodata
,
out
version
))
break
;
Version
=
version
;
Position2
=
pack
.
pos2
;
if
(!
IsCalSpeed
)
Speed2
=
pack
.
speed2
;
...
...
@@ -651,7 +656,7 @@ namespace FlyADBase
int
version
;
if
(!
pack
.
TryParse_version
(
infodata
,
out
version
))
break
;
V
ersion
=
version
;
io_v
ersion
=
version
;
if
(
version
==
1
)
{
UInt16
inchange
=
(
UInt16
)(
IStatus
^
pack
.
istatus
);
...
...
@@ -669,7 +674,7 @@ namespace FlyADBase
Position
,
Position2
));
}
else
if
(
version
==
2
)
else
if
(
version
==
2
)
{
IStatus
=
pack
.
istatus
;
OStatus
=
pack
.
ostatus
;
...
...
@@ -702,7 +707,7 @@ namespace FlyADBase
{
break
;
}
V
ersion
=
version
;
timegrid_v
ersion
=
version
;
DateTime
dt
;
int
[]
data
;
...
...
@@ -743,7 +748,6 @@ namespace FlyADBase
FLYAD7_OBJ_INTERFACE
.
PUSH_DATA_INTERFACE
.
Pack_PushStatus_2
pack
=
new
FLYAD7_OBJ_INTERFACE
.
PUSH_DATA_INTERFACE
.
Pack_PushStatus_2
();
if
(!
pack
.
TryParse_version
(
infodata
,
out
version
))
break
;
Version
=
version
;
if
(
version
==
1
)
{
DriveOrder
=
pack
.
order
;
...
...
@@ -763,9 +767,9 @@ namespace FlyADBase
{
int
version
;
var
pack
=
new
FLYAD7_OBJ_INTERFACE
.
PUSH_DATA_INTERFACE
.
Pack_PushGrid_2
();
if
(!
pack
.
TryParse_version
(
infodata
,
out
version
))
if
(!
pack
.
TryParse_version
(
infodata
,
out
version
))
break
;
grid_version
=
version
;
DateTime
dt
;
int
marker
;
if
(
version
==
1
)
...
...
@@ -850,7 +854,7 @@ namespace FlyADBase
}
}
if
(
sysinfo_wait
.
NeedGet
(
now
,
TimeSpan
.
FromSeconds
(
1
)))
if
(
sysinfo_wait
.
NeedGet
(
now
,
TimeSpan
.
FromSeconds
(
1
)))
{
CurrObjSys
.
GetValueEx
(
conn
,
...
...
@@ -874,7 +878,7 @@ namespace FlyADBase
// }
//}
//else
if
(
driveman_wait
.
NeedGet
(
now
,
TimeSpan
.
FromSeconds
(
3
)))
//每3秒检查一次
if
(
driveman_wait
.
NeedGet
(
now
,
TimeSpan
.
FromSeconds
(
3
)))
//每3秒检查一次
{
driveman_wait
.
Clear
();
if
(
Position
==
last_position
)
//当前正在running,但脉冲在3秒内都没变化,问AD卡,现在什么情况。
...
...
@@ -937,7 +941,17 @@ namespace FlyADBase
/// <summary>
/// AD盒版本号 版本1 没有systick;版本2 有systick;
/// </summary>
public
int
Version
{
get
;
private
set
;
}
=
2
;
public
int
Version
{
get
{
if
(
pos1_version
==
2
&&
timegrid_version
==
2
&&
grid_version
==
2
)
return
2
;
else
return
1
;
}
}
/// <summary>
/// 脉冲
...
...
Project.FLY.FlyADBase/Flyad7_WPF/AutoGetGridAdv.cs
0 → 100644
View file @
5d83800f
using
FlyADBase
;
using
GalaSoft.MvvmLight.Command
;
using
Newtonsoft.Json
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
System.Windows.Threading
;
namespace
Flyad7_WPF
{
[
JsonObject
(
MemberSerialization
.
OptIn
)]
public
class
AutoGetGridAdv
:
INotifyPropertyChanged
{
FlyAD7
flyad
;
public
bool
IsError
{
get
;
set
;
}
public
string
ErrMsg
{
get
;
set
;
}
public
string
ProgressMsg
{
get
;
set
;
}
public
bool
IsRunning
{
get
;
private
set
;
}
[
JsonProperty
]
public
int
FB_Pos1
{
get
;
set
;
}
=
1000
;
[
JsonProperty
]
public
int
FB_Pos2
{
get
;
set
;
}
=
3000
;
[
JsonProperty
]
public
int
StartV
{
get
;
set
;
}
=
100
;
[
JsonProperty
]
public
int
StepV
{
get
;
set
;
}
=
100
;
[
JsonProperty
]
public
int
EndV
{
get
;
set
;
}
=
2000
;
public
RelayCommand
StartCmd
{
get
;
private
set
;
}
public
RelayCommand
StopCmd
{
get
;
private
set
;
}
List
<
IEnumerable
<
GridAdvUnit
>>
gridAdvUnits
=
new
List
<
IEnumerable
<
GridAdvUnit
>>();
public
AutoGetGridAdv
()
{
StartCmd
=
new
RelayCommand
(
Start
);
StopCmd
=
new
RelayCommand
(
Stop
);
Load
();
}
public
void
Init
(
FlyAD7
flyad
)
{
this
.
PropertyChanged
+=
AutoSave
;
this
.
flyad
=
flyad
;
}
CancellationTokenSource
cancellationTokenSource
;
public
async
void
Start
()
{
if
(
IsRunning
)
return
;
cancellationTokenSource
=
new
CancellationTokenSource
();
IsError
=
false
;
IsRunning
=
true
;
ProgressMsg
=
"准备动作,到达 开始位置"
;
await
Task
.
Delay
(
1
);
flyad
.
SetVelocity
((
UInt32
)(
StartV
+
EndV
)
/
2
);
flyad
.
Runto
(
FB_Pos1
);
if
(!
await
Wait
())
goto
_end
;
ProgressMsg
=
"正式开始"
;
await
Task
.
Delay
(
1
);
//正式开始
gridAdvUnits
.
Clear
();
flyad
.
TimeGridAdvEvent
+=
Flyad_TimeGridAdvEvent
;
int
v
=
StartV
;
int
cnt
=
(
EndV
-
StartV
)
/
StepV
;
for
(
int
j
=
0
;
j
<
cnt
;
j
++)
{
flyad
.
SetVelocity
((
UInt32
)
v
);
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
ProgressMsg
=
$"
{
j
*
2
+
i
}
/
{
cnt
*
2
}
以速度
{
v
}
pps 来回扫描"
;
await
Task
.
Delay
(
1
);
flyad
.
Runto
(
FB_Pos2
);
if
(!
await
Wait
())
goto
_end
;
flyad
.
Runto
(
FB_Pos1
);
if
(!
await
Wait
())
goto
_end
;
}
v
+=
StepV
;
}
_end
:
await
Task
.
Delay
(
1000
);
//等1秒,等最后一个TimeGridAdvEvent收到
flyad
.
TimeGridAdvEvent
-=
Flyad_TimeGridAdvEvent
;
//保存数据
string
strDesktopPath
=
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
DesktopDirectory
);
string
path
=
System
.
IO
.
Path
.
Combine
(
strDesktopPath
,
$"autoGridAdv_
{
DateTime
.
Now
.
ToString
(
"yyyyMMdd_HHmmss"
)}
.json"
);
string
json
=
Newtonsoft
.
Json
.
JsonConvert
.
SerializeObject
(
gridAdvUnits
);
File
.
WriteAllText
(
path
,
json
);
ProgressMsg
=
$"成功保存到
{
path
}
"
;
gridAdvUnits
.
Clear
();
IsRunning
=
false
;
}
private
void
Flyad_TimeGridAdvEvent
(
object
sender
,
TimeGridAdvEventArgs
e
)
{
gridAdvUnits
.
Add
(
e
.
Data
);
}
async
Task
<
bool
>
Wait
()
{
while
(
true
)
{
try
{
await
Task
.
Delay
(
2000
,
cancellationTokenSource
.
Token
);
}
catch
{
//被叫醒了
ErrMsg
=
"强制退出"
;
IsError
=
true
;
await
Task
.
Delay
(
1
);
return
false
;
}
if
(!
flyad
.
IsConnected
)
{
ErrMsg
=
"连接断开"
;
IsError
=
true
;
await
Task
.
Delay
(
1
);
return
false
;
}
if
(
flyad
.
DriveStatus
==
DRIVE_MAN_STATUS
.
RUNNING
)
{
continue
;
}
else
if
(
flyad
.
DriveStatus
==
DRIVE_MAN_STATUS
.
STOP
)
{
return
true
;
}
else
{
ErrMsg
=
$"异常停止 flyad.DriveStatus=
{
flyad
.
DriveStatus
}
"
;
IsError
=
true
;
return
false
;
}
}
}
public
void
Stop
()
{
if
(!
IsRunning
)
return
;
if
(
cancellationTokenSource
==
null
)
return
;
if
(
cancellationTokenSource
.
IsCancellationRequested
)
return
;
cancellationTokenSource
.
Cancel
();
}
public
event
PropertyChangedEventHandler
PropertyChanged
;
private
bool
isIgnoreSave
;
private
async
void
AutoSave
(
object
sender
,
PropertyChangedEventArgs
e
)
{
if
(
isIgnoreSave
)
return
;
if
(
this
.
GetType
()
.
GetProperty
(
e
.
PropertyName
)
.
GetCustomAttributes
(
typeof
(
JsonPropertyAttribute
),
false
)
.
Count
()
>
0
)
{
isIgnoreSave
=
true
;
await
Task
.
Delay
(
5000
);
//Task.Yield();
Save
();
isIgnoreSave
=
false
;
}
}
void
Save
()
{
try
{
string
json
=
Newtonsoft
.
Json
.
JsonConvert
.
SerializeObject
(
this
);
File
.
WriteAllText
(
"autoGridAdv.json"
,
json
);
}
catch
(
Exception
e
)
{
}
}
void
Load
()
{
try
{
string
json
=
File
.
ReadAllText
(
"autoGridAdv.json"
);
isIgnoreSave
=
true
;
Newtonsoft
.
Json
.
JsonConvert
.
PopulateObject
(
json
,
this
);
isIgnoreSave
=
false
;
}
catch
(
Exception
e
)
{
}
}
}
}
Project.FLY.FlyADBase/Flyad7_WPF/DebugAppParam.cs
View file @
5d83800f
...
...
@@ -6,6 +6,7 @@ using System.ComponentModel;
using
Misc
;
using
System.IO
;
using
Newtonsoft.Json
;
using
System.Threading.Tasks
;
namespace
Flyad7_WPF
{
...
...
@@ -31,51 +32,70 @@ namespace Flyad7_WPF
public
int
FB_Pos2
{
get
;
set
;
}
=
3000
;
public
UInt32
Velocity
{
get
;
set
;
}
public
UInt32
SVelocity
{
get
;
set
;
}
public
UInt32
ATime
{
get
;
set
;
}
public
UInt32
DTime
{
get
;
set
;
}
public
UInt32
HVelocity1
{
get
;
set
;
}
public
UInt32
HVelocity2
{
get
;
set
;
}
public
UInt32
Velocity
{
get
;
set
;
}
=
3000
;
public
UInt32
SVelocity
{
get
;
set
;
}
=
100
;
public
UInt32
ATime
{
get
;
set
;
}
=
300
;
public
UInt32
DTime
{
get
;
set
;
}
=
300
;
public
UInt32
HVelocity1
{
get
;
set
;
}
=
1000
;
public
UInt32
HVelocity2
{
get
;
set
;
}
=
300
;
public
int
PosLen
{
get
;
set
;
}
=
8900
;
public
int
ADLag
{
get
;
set
;
}
=
0
;
public
int
PosLen
;
public
int
ADLag
{
get
;
set
;
}
#
region
INotifyPropertyChanged
成员
public
event
PropertyChangedEventHandler
PropertyChanged
;
#
endregion
public
void
Save
()
public
DebugAppParam
()
{
Misc
.
SaveToXmlHepler
.
Save
(
file_path
,
this
);
Load
(
);
}
string
file_path
=
"param.xml"
;
public
void
Load
()
public
void
Init
()
{
Misc
.
SaveToXmlHepler
.
Load
(
file_path
,
this
)
;
this
.
PropertyChanged
+=
AutoSave
;
}
private
bool
isIgnoreSave
;
private
async
void
AutoSave
(
object
sender
,
PropertyChangedEventArgs
e
)
{
if
(
isIgnoreSave
)
return
;
if
(
this
.
GetType
().
GetProperty
(
e
.
PropertyName
).
GetCustomAttributes
(
typeof
(
JsonPropertyAttribute
),
false
).
Count
()
>
0
)
{
isIgnoreSave
=
true
;
await
Task
.
Delay
(
5000
);
//Task.Yield();
Save
();
isIgnoreSave
=
false
;
}
public
class
DebugAppParamJsonDB
}
public
void
Save
()
{
public
string
EPStr
;
public
bool
HasTimeGrid
;
public
bool
HasGrid
;
try
{
string
json
=
JsonConvert
.
SerializeObject
(
this
);
File
.
WriteAllText
(
"param.json"
,
json
);
}
catch
{
public
bool
HasGridAdv
;
}
}
public
bool
HasCRC
;
public
void
Load
()
{
try
{
string
json
=
File
.
ReadAllText
(
"param.json"
);
isIgnoreSave
=
true
;
JsonConvert
.
PopulateObject
(
json
,
this
);
isIgnoreSave
=
false
;
}
catch
{
}
}
public
int
FB_Pos1
;
public
int
FB_Pos2
;
}
}
Project.FLY.FlyADBase/Flyad7_WPF/Flyad7_WPF.csproj
View file @
5d83800f
...
...
@@ -72,12 +72,14 @@
<SubType>
Designer
</SubType>
</ApplicationDefinition>
<Compile
Include=
"AutoForwBackw.cs"
/>
<Compile
Include=
"AutoGetGridAdv.cs"
/>
<Compile
Include=
"AutoSync.cs"
/>
<Compile
Include=
"Converters\BinConverter.cs"
/>
<Compile
Include=
"Converters\BytesConverter.cs"
/>
<Compile
Include=
"Converters\IO2BinConverter.cs"
/>
<Compile
Include=
"DebugAppParam.cs"
/>
<Compile
Include=
"FlyADClientUI.cs"
/>
<Compile
Include=
"GridAdvVm.cs"
/>
<Compile
Include=
"Window1.xaml.cs"
>
<DependentUpon>
Window1.xaml
</DependentUpon>
</Compile>
...
...
@@ -184,6 +186,9 @@
<IncludeAssets>
runtime; build; native; contentfiles; analyzers
</IncludeAssets>
<PrivateAssets>
all
</PrivateAssets>
</PackageReference>
<PackageReference
Include=
"MvvmLightLibs"
>
<Version>
5.4.1.1
</Version>
</PackageReference>
<PackageReference
Include=
"Newtonsoft.Json"
>
<Version>
12.0.3
</Version>
</PackageReference>
...
...
Project.FLY.FlyADBase/Flyad7_WPF/GridAdvVm.cs
0 → 100644
View file @
5d83800f
using
FlyADBase
;
using
GalaSoft.MvvmLight.Command
;
using
Microsoft.Win32
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows
;
using
System.Windows.Forms.DataVisualization.Charting
;
namespace
Flyad7_WPF
{
public
class
GridAdvVm
:
INotifyPropertyChanged
{
public
event
PropertyChangedEventHandler
PropertyChanged
;
public
bool
HasGridAdv
{
get
;
set
;
}
public
RelayCommand
SaveCmd
{
get
;
private
set
;
}
public
RelayCommand
LoadCmd
{
get
;
private
set
;
}
public
RelayCommand
CalAdLagCmd
{
get
;
private
set
;
}
Chart
chart3
;
FlyAD7
flyad
;
int
timeGridAdvIndex
=
0
;
List
<
IEnumerable
<
GridAdvUnit
>>
gridAdvUnits
=
new
List
<
IEnumerable
<
GridAdvUnit
>>();
public
GridAdvVm
()
{
SaveCmd
=
new
RelayCommand
(
Save
);
LoadCmd
=
new
RelayCommand
(
Load
);
CalAdLagCmd
=
new
RelayCommand
(
CalAdLag
);
}
public
void
Init
(
Chart
chart3
,
FlyAD7
flyad
)
{
this
.
chart3
=
chart3
;
this
.
flyad
=
flyad
;
InitializeComponent4
();
flyad
.
TimeGridAdvEvent
+=
flyad_TimeGridAdvEvent
;
}
void
InitializeComponent4
()
{
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartArea
chartArea1
=
new
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartArea
();
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Legend
legend1
=
new
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Legend
();
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Series
series1
=
new
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Series
();
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Series
series2
=
new
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Series
();
//
// chart1
//
chartArea1
.
AxisX
.
LabelStyle
.
Font
=
new
System
.
Drawing
.
Font
(
"Trebuchet MS"
,
8.25F
,
System
.
Drawing
.
FontStyle
.
Bold
);
chartArea1
.
AxisX
.
LineColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))));
chartArea1
.
AxisX
.
MajorGrid
.
LineColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))));
chartArea1
.
AxisY
.
LabelStyle
.
Font
=
new
System
.
Drawing
.
Font
(
"Trebuchet MS"
,
8.25F
,
System
.
Drawing
.
FontStyle
.
Bold
);
chartArea1
.
AxisY
.
LineColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))));
chartArea1
.
AxisY
.
MajorGrid
.
LineColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))));
chartArea1
.
BackColor
=
System
.
Drawing
.
Color
.
OldLace
;
//chartArea1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
//chartArea1.BackSecondaryColor = System.Drawing.Color.White;
chartArea1
.
BorderColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))));
chartArea1
.
BorderDashStyle
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartDashStyle
.
Solid
;
chartArea1
.
Name
=
"Default"
;
chartArea1
.
ShadowColor
=
System
.
Drawing
.
Color
.
Transparent
;
chartArea1
.
CursorX
.
IsUserEnabled
=
true
;
chartArea1
.
CursorX
.
IsUserSelectionEnabled
=
true
;
chartArea1
.
CursorX
.
SelectionColor
=
System
.
Drawing
.
SystemColors
.
Highlight
;
chartArea1
.
CursorY
.
IsUserEnabled
=
true
;
chartArea1
.
CursorY
.
IsUserSelectionEnabled
=
true
;
chartArea1
.
CursorY
.
SelectionColor
=
System
.
Drawing
.
SystemColors
.
Highlight
;
//对数坐标
//chartArea1.AxisY.IsLogarithmic = true;
//chartArea1.AxisY.LogarithmBase = Math.E;
chart3
.
ChartAreas
.
Add
(
chartArea1
);
legend1
.
BackColor
=
System
.
Drawing
.
Color
.
Transparent
;
legend1
.
Enabled
=
true
;
legend1
.
Font
=
new
System
.
Drawing
.
Font
(
"Trebuchet MS"
,
8.25F
,
System
.
Drawing
.
FontStyle
.
Bold
);
legend1
.
Alignment
=
System
.
Drawing
.
StringAlignment
.
Near
;
legend1
.
Docking
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Docking
.
Right
;
legend1
.
IsDockedInsideChartArea
=
true
;
legend1
.
DockedToChartArea
=
chartArea1
.
Name
;
//legend1.IsTextAutoFit = false;
legend1
.
Name
=
"Default"
;
chart3
.
Legends
.
Add
(
legend1
);
series1
.
Name
=
"Series 1"
;
series1
.
BorderColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
180
)))),
((
int
)(((
byte
)(
26
)))),
((
int
)(((
byte
)(
59
)))),
((
int
)(((
byte
)(
105
)))));
series1
.
BorderWidth
=
3
;
series1
.
ChartArea
=
chartArea1
.
Name
;
series1
.
ChartType
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
SeriesChartType
.
Line
;
series1
.
Color
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
220
)))),
((
int
)(((
byte
)(
65
)))),
((
int
)(((
byte
)(
140
)))),
((
int
)(((
byte
)(
240
)))));
series1
.
Legend
=
legend1
.
Name
;
series1
.
LegendText
=
"Series 1"
;
series1
.
ShadowColor
=
System
.
Drawing
.
Color
.
Black
;
series1
.
ShadowOffset
=
2
;
series1
.
XValueType
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartValueType
.
Int32
;
series1
.
YValueType
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartValueType
.
Int32
;
chart3
.
Series
.
Add
(
series1
);
series2
.
Name
=
"Series 2"
;
series2
.
BorderColor
=
System
.
Drawing
.
Color
.
Pink
;
series2
.
BorderWidth
=
3
;
series2
.
ChartArea
=
chartArea1
.
Name
;
series2
.
ChartType
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
SeriesChartType
.
Line
;
series2
.
Color
=
System
.
Drawing
.
Color
.
Red
;
series2
.
Legend
=
legend1
.
Name
;
series2
.
LegendText
=
"Series 2"
;
series2
.
ShadowColor
=
System
.
Drawing
.
Color
.
Black
;
series2
.
ShadowOffset
=
2
;
series2
.
XValueType
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartValueType
.
Int32
;
series2
.
YValueType
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartValueType
.
Int32
;
chart3
.
Series
.
Add
(
series2
);
//this.chart1.Location = new System.Drawing.Point(16, 32);
chart3
.
Name
=
"chart3"
;
chart3
.
BackColor
=
System
.
Drawing
.
Color
.
Transparent
;
}
#
region
timeGridAdv
private
async
void
flyad_TimeGridAdvEvent
(
object
sender
,
TimeGridAdvEventArgs
e
)
{
if
(!
HasGridAdv
)
return
;
if
(
gridAdvUnits
==
null
)
gridAdvUnits
=
new
List
<
IEnumerable
<
GridAdvUnit
>>();
gridAdvUnits
.
Add
(
e
.
Data
);
await
Task
.
Factory
.
StartNew
(()
=>
{
//画图
DrawGridAdv
(
gridAdvUnits
.
Last
());
while
(
gridAdvUnits
.
Count
>
chart3
.
Series
.
Count
())
gridAdvUnits
.
RemoveAt
(
0
);
if
(
gridAdvUnits
.
Count
()
>=
2
)
{
CurrR
=
CalGridAdvR
(
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
1
],
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
2
],
0
);
}
});
}
void
DrawGridAdv
(
IEnumerable
<
GridAdvUnit
>
units
,
int
adLag
=
0
)
{
flyad
.
ToGrid
(
units
,
out
int
[]
datas
,
adLag
);
//画图
timeGridAdvIndex
++;
if
(
timeGridAdvIndex
>=
chart3
.
Series
.
Count
())
timeGridAdvIndex
=
0
;
App
.
Current
.
Dispatcher
.
Invoke
(()
=>
{
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Series
series
=
chart3
.
Series
[
timeGridAdvIndex
];
series
.
Points
.
Clear
();
int
gridLen
=
flyad
.
PosLen
/
flyad
.
PosOfGrid
;
for
(
int
i
=
0
;
i
<
datas
.
Length
;
i
++)
{
int
pos
=
i
*
flyad
.
PosOfGrid
;
int
ad
=
datas
[
i
];
series
.
Points
.
AddXY
(
pos
,
ad
);
if
(
ad
==
Misc
.
MyBase
.
NULL_VALUE
)
series
.
Points
[
i
].
IsEmpty
=
true
;
}
chart3
.
ChartAreas
[
0
].
AxisX
.
Minimum
=
0
;
chart3
.
ChartAreas
[
0
].
AxisX
.
Maximum
=
flyad
.
PosLen
;
});
}
//计算相关性
public
int
BestAdLag
{
get
;
private
set
;
}
public
double
BestR
{
get
;
private
set
;
}
public
double
CurrR
{
get
;
private
set
;
}
public
double
ProgressOfAdLag
{
get
;
private
set
;
}
public
double
ProgressOfR
{
get
;
private
set
;
}
double
CalGridAdvR
(
IEnumerable
<
GridAdvUnit
>
units1
,
IEnumerable
<
GridAdvUnit
>
units2
,
int
adLag
)
{
flyad
.
ToGrid
(
units1
,
out
int
[]
datas1
,
adLag
);
flyad
.
ToGrid
(
units2
,
out
int
[]
datas2
,
adLag
);
return
Misc
.
MyMath
.
Correl
(
datas1
,
datas2
);
}
void
CalAdLag
(
IEnumerable
<
GridAdvUnit
>
units1
,
IEnumerable
<
GridAdvUnit
>
units2
,
int
adLag
,
int
range
,
double
targetR
,
out
int
bestAdLag
,
out
double
bestR
)
{
int
step
=
range
/
5
;
if
(
step
<
0
)
step
=
1
;
List
<
AdLagAndR
>
rList
=
new
List
<
AdLagAndR
>();
for
(
int
i
=
0
;
i
<
range
;
i
+=
step
)
{
int
_adLag
=
adLag
-
i
;
double
_r
=
CalGridAdvR
(
units1
,
units2
,
_adLag
);
rList
.
Add
(
new
AdLagAndR
()
{
AdLag
=
_adLag
,
R
=
_r
});
ProgressOfAdLag
=
_adLag
;
ProgressOfR
=
_r
;
}
for
(
int
i
=
step
;
i
<
range
;
i
+=
step
)
{
int
_adLag
=
adLag
+
i
;
double
_r
=
CalGridAdvR
(
units1
,
units2
,
_adLag
);
rList
.
Add
(
new
AdLagAndR
()
{
AdLag
=
_adLag
,
R
=
_r
});
ProgressOfAdLag
=
_adLag
;
ProgressOfR
=
_r
;
}
double
maxR
=
rList
.
Max
(
lr
=>
lr
.
R
);
adLag
=
rList
.
Find
(
_lr
=>
_lr
.
R
==
maxR
).
AdLag
;
if
(
step
==
1
)
{
//已经是最小查找步进
bestAdLag
=
adLag
;
bestR
=
maxR
;
return
;
}
if
(
maxR
>=
targetR
)
{
//找到了
bestAdLag
=
adLag
;
bestR
=
maxR
;
return
;
}
//缩小范围,继续找
range
=
step
*
2
;
CalAdLag
(
units1
,
units2
,
adLag
,
range
,
targetR
,
out
bestAdLag
,
out
bestR
);
}
class
AdLagAndR
{
public
int
AdLag
;
public
double
R
;
}
private
void
Save
()
{
string
strDesktopPath
=
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
DesktopDirectory
);
string
path
=
System
.
IO
.
Path
.
Combine
(
strDesktopPath
,
$"
{
DateTime
.
Now
.
ToString
(
"yyyyMMdd_HHmmss"
)}
.json"
);
string
json
=
Newtonsoft
.
Json
.
JsonConvert
.
SerializeObject
(
gridAdvUnits
);
File
.
WriteAllText
(
path
,
json
);
MessageBox
.
Show
(
$"成功保存到
{
path
}
"
);
}
private
async
void
Load
()
{
string
strDesktopPath
=
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
DesktopDirectory
);
OpenFileDialog
openFileDialog
=
new
OpenFileDialog
();
openFileDialog
.
DefaultExt
=
".json"
;
openFileDialog
.
Filter
=
"json文件|*.json"
;
openFileDialog
.
InitialDirectory
=
strDesktopPath
;
if
(
openFileDialog
.
ShowDialog
()
!=
true
)
return
;
string
path
=
openFileDialog
.
FileName
;
string
json
=
File
.
ReadAllText
(
path
);
try
{
gridAdvUnits
=
Newtonsoft
.
Json
.
JsonConvert
.
DeserializeObject
<
List
<
IEnumerable
<
GridAdvUnit
>>>(
json
);
}
catch
(
Exception
ex
)
{
MessageBox
.
Show
(
$"读取失败
{
ex
}
"
);
return
;
}
if
(
gridAdvUnits
==
null
)
{
gridAdvUnits
=
new
List
<
IEnumerable
<
GridAdvUnit
>>();
MessageBox
.
Show
(
$"读取失败 没有数据"
);
}
else
{
await
Task
.
Factory
.
StartNew
(()
=>
{
foreach
(
var
units
in
gridAdvUnits
)
{
DrawGridAdv
(
units
);
}
if
(
gridAdvUnits
.
Count
>
chart3
.
Series
.
Count
())
gridAdvUnits
.
RemoveAt
(
0
);
if
(
gridAdvUnits
.
Count
()
>=
2
)
{
CurrR
=
CalGridAdvR
(
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
1
],
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
2
],
0
);
}
});
MessageBox
.
Show
(
$"读取成功"
);
}
}
private
async
void
CalAdLag
()
{
if
(
gridAdvUnits
.
Count
()
<
2
)
{
MessageBox
.
Show
(
"数量小于2次"
);
return
;
}
int
bestAdLag
=
0
;
double
bestR
=
-
1
;
await
Task
.
Factory
.
StartNew
(()
=>
{
CalAdLag
(
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
1
],
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
2
],
0
,
(
int
)(
1000
/
1.28
),
0.99
,
out
bestAdLag
,
out
bestR
);
});
BestAdLag
=
bestAdLag
;
BestR
=
bestR
;
await
Task
.
Factory
.
StartNew
(()
=>
{
DrawGridAdv
(
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
1
],
BestAdLag
);
DrawGridAdv
(
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
2
],
BestAdLag
);
});
MessageBox
.
Show
(
$"计算完成 最佳滞后=
{
BestAdLag
}
"
);
}
#
endregion
}
}
Project.FLY.FlyADBase/Flyad7_WPF/MainWindow.xaml
View file @
5d83800f
...
...
@@ -25,7 +25,6 @@
</Style>
<Style TargetType="TextBlock" x:Key="TextBlockStyle_itemTitle">
<Setter Property="Width" Value="60" />
<Setter Property="Height" Value="23" />
<Setter Property="Margin" Value="3" />
</Style>
<Style TargetType="TextBox" x:Key="TextBoxStyle_itemContent">
...
...
@@ -35,8 +34,8 @@
</Style>
<Style TargetType="Button" x:Key="ButtonStyle">
<Setter Property="Height" Value="30"/>
<Setter Property="Width" Value="80"/>
<Setter Property="Margin" Value="3"/>
<Setter Property="Padding" Value="20,3"/>
</Style>
</ResourceDictionary>
</Window.Resources>
...
...
@@ -371,15 +370,16 @@
<RowDefinition Height="auto" />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Name="stackpanel_graph_gridadv">
<StackPanel >
<GroupBox Name="gbTimeGridAdv" Header="TimeGridAdv操作" d:DataContext="{d:DesignInstance Type=local:GridAdvVm}">
<StackPanel>
<StackPanel Orientation="Horizontal" >
<CheckBox Content="接收GridAdv" IsChecked="{Binding DataContext.HasGridAdv,ElementName=grid_param}" VerticalAlignment="Center" Margin="3" />
<Button Padding="20,5" Margin="3" Content="保存GridAdv" Click="btnSaveGridAdvClick" />
<Button Padding="20,5" Margin="3" Content="读取GridAdv" Click="btnLoadGridAdvClick" />
<CheckBox Content="接收GridAdv" IsChecked="{Binding HasGridAdv }" VerticalAlignment="Center" Margin="3" />
<Button Style="{StaticResource ButtonStyle}" Content="保存" Command="{Binding SaveCmd}" />
<Button Style="{StaticResource ButtonStyle}" Content="读取" Command="{Binding LoadCmd}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button Padding="20,5" Margin="3" Content="计算滞后" Click="btnCalAdLagClick
" />
<Button Style="{StaticResource ButtonStyle}" Content="计算滞后" Command="{Binding CalAdLagCmd}
" />
<TextBlock Margin="10,0">
当前相关性=<Run Text="{Binding CurrR, StringFormat={}{0:F4}, Mode=OneWay}"/>
</TextBlock>
...
...
@@ -394,6 +394,61 @@
</StackPanel>
</StackPanel>
</GroupBox>
<GroupBox x:Name="gbAutoGetGridAdv" Header="自动采集不同速度TimeGridAdv" d:DataContext="{d:DesignInstance Type=local:AutoGetGridAdv}" >
<StackPanel >
<StackPanel Orientation="Horizontal" >
<Button Style="{StaticResource ButtonStyle}" Content="开始" Command="{Binding StartCmd}" />
<Button Style="{StaticResource ButtonStyle}" Content="停止" Command="{Binding StopCmd}" />
<StackPanel Orientation="Horizontal">
<TextBox Style="{StaticResource TextBoxStyle_itemContent}" Text="{Binding FB_Pos1}" />
<TextBlock Text="<---->" VerticalAlignment="Center"/>
<TextBox Style="{StaticResource TextBoxStyle_itemContent}" Text="{Binding FB_Pos2}" />
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal">
<StackPanel Margin="2">
<TextBlock Style="{StaticResource TextBlockStyle_itemTitle}" Text="开始速度" />
<TextBox Style="{StaticResource TextBoxStyle_itemContent}" Text="{Binding StartV}" />
</StackPanel>
<StackPanel Margin="2">
<TextBlock Style="{StaticResource TextBlockStyle_itemTitle}" Text="结束速度" />
<TextBox Style="{StaticResource TextBoxStyle_itemContent}" Text="{Binding EndV}" />
</StackPanel>
<StackPanel Margin="2">
<TextBlock Style="{StaticResource TextBlockStyle_itemTitle}" Text="步进" />
<TextBox Style="{StaticResource TextBoxStyle_itemContent}" Text="{Binding StepV}" />
</StackPanel>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="10,0">
运行中 =<Run Text="{Binding IsRunning, Mode=OneWay}"/>
</TextBlock>
<TextBlock Margin="10,0">
Error=<Run Text="{Binding ErrMsg,Mode=OneWay}" />
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding IsError}" Value="False">
<Setter Property="Visibility" Value="Collapsed"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</StackPanel>
<TextBlock Margin="10,0">
Progess=<Run Text="{Binding ProgressMsg,Mode=OneWay}"/>
</TextBlock>
</StackPanel>
</GroupBox>
</StackPanel>
<WindowsFormsHost Grid.Row="1">
<Chr:Chart x:Name="chart3" />
...
...
Project.FLY.FlyADBase/Flyad7_WPF/MainWindow.xaml.cs
View file @
5d83800f
...
...
@@ -36,55 +36,51 @@ namespace Flyad7_WPF
AutoForwBackw
autofb
;
FlyADClientUI
flyad_clientui
;
AutoSync
mAutoSync
;
int
timeGridAdvIndex
=
0
;
List
<
IEnumerable
<
GridAdvUnit
>>
gridAdvUnits
=
new
List
<
IEnumerable
<
GridAdvUnit
>>()
;
AutoGetGridAdv
autoGetGridAdv
;
GridAdvVm
gridAdvVm
;
public
MainWindow
()
{
InitializeComponent
();
InitializeComponent2
();
InitializeComponent3
();
InitializeComponent4
();
flyad
=
new
FlyAD7
();
param
=
new
DebugAppParam
();
param
.
Load
();
param
.
Init
();
flyad
=
new
FlyAD7
();
Misc
.
BindingOperations
.
SetBinding
(
param
,
"HasCRC"
,
flyad
,
"HasCRC"
);
autofb
=
new
AutoForwBackw
(
flyad
);
Misc
.
BindingOperations
.
SetBinding
(
param
,
"FB_Pos1"
,
autofb
,
"FB_Pos1"
,
Misc
.
BindingOperations
.
BindingMode
.
TwoWay
);
Misc
.
BindingOperations
.
SetBinding
(
param
,
"FB_Pos2"
,
autofb
,
"FB_Pos2"
,
Misc
.
BindingOperations
.
BindingMode
.
TwoWay
);
flyad_clientui
=
new
FlyADClientUI
(
flyad
);
autoGetGridAdv
=
new
AutoGetGridAdv
();
autoGetGridAdv
.
Init
(
flyad
);
mAutoSync
=
new
AutoSync
();
mAutoSync
.
Init
(
flyad
);
Misc
.
BindingOperations
.
SetBinding
(
param
,
"HasCRC"
,
flyad
,
"HasCRC"
);
Misc
.
BindingOperations
.
SetBinding
(
param
,
"FB_Pos1"
,
autofb
,
"FB_Pos1"
,
Misc
.
BindingOperations
.
BindingMode
.
TwoWay
);
Misc
.
BindingOperations
.
SetBinding
(
param
,
"FB_Pos2"
,
autofb
,
"FB_Pos2"
,
Misc
.
BindingOperations
.
BindingMode
.
TwoWay
);
gridAdvVm
=
new
GridAdvVm
();
gridAdvVm
.
Init
(
chart3
,
flyad
);
Misc
.
BindingOperations
.
SetBinding
(
param
,
"HasGridAdv"
,
gridAdvVm
,
"HasGridAdv"
,
Misc
.
BindingOperations
.
BindingMode
.
TwoWay
);
this
.
DataContext
=
flyad
;
this
.
stackpanel_graph_gridadv
.
DataContext
=
this
;
this
.
grid_param
.
DataContext
=
param
;
this
.
groupBox_fb
.
DataContext
=
autofb
;
this
.
groupBox_adpos
.
DataContext
=
flyad_clientui
;
this
.
gbAutoGetGridAdv
.
DataContext
=
autoGetGridAdv
;
this
.
gbTimeGridAdv
.
DataContext
=
gridAdvVm
;
flyad
.
GridEvent
+=
flyad_GridEvent
;
flyad
.
TimeGridEvent
+=
flyad_TimeGridEvent
;
flyad
.
TimeGridAdvEvent
+=
flyad_TimeGridAdvEvent
;
param
.
PropertyChanged
+=
(
s
,
e
)
=>
{
param
.
Save
();
};
FObjBase
.
PollModule
.
Current
.
Start
();
//Thread t = new Thread(() =>
//{
// while (true)
// {
// FObjBase.PollModule.Current.OnPoll();
// Thread.Sleep(10);
// }
//});
//t.IsBackground = true;
//t.Start();
}
...
...
@@ -223,87 +219,7 @@ namespace Flyad7_WPF
this
.
chart2
.
BackColor
=
System
.
Drawing
.
Color
.
Transparent
;
}
void
InitializeComponent4
()
{
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartArea
chartArea1
=
new
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartArea
();
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Legend
legend1
=
new
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Legend
();
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Series
series1
=
new
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Series
();
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Series
series2
=
new
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Series
();
//
// chart1
//
chartArea1
.
AxisX
.
LabelStyle
.
Font
=
new
System
.
Drawing
.
Font
(
"Trebuchet MS"
,
8.25F
,
System
.
Drawing
.
FontStyle
.
Bold
);
chartArea1
.
AxisX
.
LineColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))));
chartArea1
.
AxisX
.
MajorGrid
.
LineColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))));
chartArea1
.
AxisY
.
LabelStyle
.
Font
=
new
System
.
Drawing
.
Font
(
"Trebuchet MS"
,
8.25F
,
System
.
Drawing
.
FontStyle
.
Bold
);
chartArea1
.
AxisY
.
LineColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))));
chartArea1
.
AxisY
.
MajorGrid
.
LineColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))));
chartArea1
.
BackColor
=
System
.
Drawing
.
Color
.
OldLace
;
//chartArea1.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
//chartArea1.BackSecondaryColor = System.Drawing.Color.White;
chartArea1
.
BorderColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))),
((
int
)(((
byte
)(
64
)))));
chartArea1
.
BorderDashStyle
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartDashStyle
.
Solid
;
chartArea1
.
Name
=
"Default"
;
chartArea1
.
ShadowColor
=
System
.
Drawing
.
Color
.
Transparent
;
chartArea1
.
CursorX
.
IsUserEnabled
=
true
;
chartArea1
.
CursorX
.
IsUserSelectionEnabled
=
true
;
chartArea1
.
CursorX
.
SelectionColor
=
System
.
Drawing
.
SystemColors
.
Highlight
;
chartArea1
.
CursorY
.
IsUserEnabled
=
true
;
chartArea1
.
CursorY
.
IsUserSelectionEnabled
=
true
;
chartArea1
.
CursorY
.
SelectionColor
=
System
.
Drawing
.
SystemColors
.
Highlight
;
//对数坐标
//chartArea1.AxisY.IsLogarithmic = true;
//chartArea1.AxisY.LogarithmBase = Math.E;
chart3
.
ChartAreas
.
Add
(
chartArea1
);
legend1
.
BackColor
=
System
.
Drawing
.
Color
.
Transparent
;
legend1
.
Enabled
=
true
;
legend1
.
Font
=
new
System
.
Drawing
.
Font
(
"Trebuchet MS"
,
8.25F
,
System
.
Drawing
.
FontStyle
.
Bold
);
legend1
.
Alignment
=
System
.
Drawing
.
StringAlignment
.
Near
;
legend1
.
Docking
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Docking
.
Right
;
legend1
.
IsDockedInsideChartArea
=
true
;
legend1
.
DockedToChartArea
=
chartArea1
.
Name
;
//legend1.IsTextAutoFit = false;
legend1
.
Name
=
"Default"
;
chart3
.
Legends
.
Add
(
legend1
);
series1
.
Name
=
"Series 1"
;
series1
.
BorderColor
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
180
)))),
((
int
)(((
byte
)(
26
)))),
((
int
)(((
byte
)(
59
)))),
((
int
)(((
byte
)(
105
)))));
series1
.
BorderWidth
=
3
;
series1
.
ChartArea
=
chartArea1
.
Name
;
series1
.
ChartType
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
SeriesChartType
.
Line
;
series1
.
Color
=
System
.
Drawing
.
Color
.
FromArgb
(((
int
)(((
byte
)(
220
)))),
((
int
)(((
byte
)(
65
)))),
((
int
)(((
byte
)(
140
)))),
((
int
)(((
byte
)(
240
)))));
series1
.
Legend
=
legend1
.
Name
;
series1
.
LegendText
=
"Series 1"
;
series1
.
ShadowColor
=
System
.
Drawing
.
Color
.
Black
;
series1
.
ShadowOffset
=
2
;
series1
.
XValueType
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartValueType
.
Int32
;
series1
.
YValueType
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartValueType
.
Int32
;
chart3
.
Series
.
Add
(
series1
);
series2
.
Name
=
"Series 2"
;
series2
.
BorderColor
=
System
.
Drawing
.
Color
.
Pink
;
series2
.
BorderWidth
=
3
;
series2
.
ChartArea
=
chartArea1
.
Name
;
series2
.
ChartType
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
SeriesChartType
.
Line
;
series2
.
Color
=
System
.
Drawing
.
Color
.
Red
;
series2
.
Legend
=
legend1
.
Name
;
series2
.
LegendText
=
"Series 2"
;
series2
.
ShadowColor
=
System
.
Drawing
.
Color
.
Black
;
series2
.
ShadowOffset
=
2
;
series2
.
XValueType
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartValueType
.
Int32
;
series2
.
YValueType
=
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
ChartValueType
.
Int32
;
chart3
.
Series
.
Add
(
series2
);
//this.chart1.Location = new System.Drawing.Point(16, 32);
chart3
.
Name
=
"chart3"
;
chart3
.
BackColor
=
System
.
Drawing
.
Color
.
Transparent
;
}
#
region
grid
void
flyad_GridEvent
(
object
sender
,
MiniGridEventArgs
e
)
{
...
...
@@ -401,208 +317,7 @@ namespace Flyad7_WPF
GetGrid
(
Misc
.
DIRECTION
.
BACKWARD
);
}
#
endregion
#
region
timeGridAdv
private
async
void
flyad_TimeGridAdvEvent
(
object
sender
,
TimeGridAdvEventArgs
e
)
{
if
(!
param
.
HasGridAdv
)
return
;
if
(
gridAdvUnits
==
null
)
gridAdvUnits
=
new
List
<
IEnumerable
<
GridAdvUnit
>>();
gridAdvUnits
.
Add
(
e
.
Data
);
await
Task
.
Factory
.
StartNew
(()
=>
{
//画图
DrawGridAdv
(
gridAdvUnits
.
Last
());
while
(
gridAdvUnits
.
Count
>
chart3
.
Series
.
Count
())
gridAdvUnits
.
RemoveAt
(
0
);
if
(
gridAdvUnits
.
Count
()
>=
2
)
{
CurrR
=
CalGridAdvR
(
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
1
],
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
2
],
0
);
}
});
}
void
DrawGridAdv
(
IEnumerable
<
GridAdvUnit
>
units
,
int
adLag
=
0
)
{
flyad
.
ToGrid
(
units
,
out
int
[]
datas
,
adLag
);
//画图
timeGridAdvIndex
++;
if
(
timeGridAdvIndex
>=
chart3
.
Series
.
Count
())
timeGridAdvIndex
=
0
;
this
.
Dispatcher
.
Invoke
(()
=>
{
System
.
Windows
.
Forms
.
DataVisualization
.
Charting
.
Series
series
=
chart3
.
Series
[
timeGridAdvIndex
];
series
.
Points
.
Clear
();
int
gridLen
=
flyad
.
PosLen
/
flyad
.
PosOfGrid
;
for
(
int
i
=
0
;
i
<
datas
.
Length
;
i
++)
{
int
pos
=
i
*
flyad
.
PosOfGrid
;
int
ad
=
datas
[
i
];
series
.
Points
.
AddXY
(
pos
,
ad
);
if
(
ad
==
Misc
.
MyBase
.
NULL_VALUE
)
series
.
Points
[
i
].
IsEmpty
=
true
;
}
chart1
.
ChartAreas
[
0
].
AxisX
.
Minimum
=
0
;
chart1
.
ChartAreas
[
0
].
AxisX
.
Maximum
=
flyad
.
PosLen
;
});
}
//计算相关性
public
int
BestAdLag
{
get
;
private
set
;
}
public
double
BestR
{
get
;
private
set
;
}
public
double
CurrR
{
get
;
private
set
;
}
public
double
ProgressOfAdLag
{
get
;
private
set
;
}
public
double
ProgressOfR
{
get
;
private
set
;
}
double
CalGridAdvR
(
IEnumerable
<
GridAdvUnit
>
units1
,
IEnumerable
<
GridAdvUnit
>
units2
,
int
adLag
)
{
flyad
.
ToGrid
(
units1
,
out
int
[]
datas1
,
adLag
);
flyad
.
ToGrid
(
units2
,
out
int
[]
datas2
,
adLag
);
return
Misc
.
MyMath
.
Correl
(
datas1
,
datas2
);
}
void
CalAdLag
(
IEnumerable
<
GridAdvUnit
>
units1
,
IEnumerable
<
GridAdvUnit
>
units2
,
int
adLag
,
int
range
,
double
targetR
,
out
int
bestAdLag
,
out
double
bestR
)
{
int
step
=
range
/
5
;
if
(
step
<
0
)
step
=
1
;
List
<
AdLagAndR
>
rList
=
new
List
<
AdLagAndR
>();
for
(
int
i
=
0
;
i
<
range
;
i
+=
step
)
{
int
_adLag
=
adLag
-
i
;
double
_r
=
CalGridAdvR
(
units1
,
units2
,
_adLag
);
rList
.
Add
(
new
AdLagAndR
()
{
AdLag
=
_adLag
,
R
=
_r
});
ProgressOfAdLag
=
_adLag
;
ProgressOfR
=
_r
;
}
for
(
int
i
=
step
;
i
<
range
;
i
+=
step
)
{
int
_adLag
=
adLag
+
i
;
double
_r
=
CalGridAdvR
(
units1
,
units2
,
_adLag
);
rList
.
Add
(
new
AdLagAndR
()
{
AdLag
=
_adLag
,
R
=
_r
});
ProgressOfAdLag
=
_adLag
;
ProgressOfR
=
_r
;
}
double
maxR
=
rList
.
Max
(
lr
=>
lr
.
R
);
adLag
=
rList
.
Find
(
_lr
=>
_lr
.
R
==
maxR
).
AdLag
;
if
(
step
==
1
)
{
//已经是最小查找步进
bestAdLag
=
adLag
;
bestR
=
maxR
;
return
;
}
if
(
maxR
>=
targetR
)
{
//找到了
bestAdLag
=
adLag
;
bestR
=
maxR
;
return
;
}
//缩小范围,继续找
range
=
step
*
2
;
CalAdLag
(
units1
,
units2
,
adLag
,
range
,
targetR
,
out
bestAdLag
,
out
bestR
);
}
class
AdLagAndR
{
public
int
AdLag
;
public
double
R
;
}
private
void
btnSaveGridAdvClick
(
object
sender
,
RoutedEventArgs
e
)
{
string
strDesktopPath
=
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
DesktopDirectory
);
string
path
=
System
.
IO
.
Path
.
Combine
(
strDesktopPath
,
$"
{
DateTime
.
Now
.
ToString
(
"yyyyMMdd_HHmmss"
)}
.json"
);
string
json
=
Newtonsoft
.
Json
.
JsonConvert
.
SerializeObject
(
gridAdvUnits
);
File
.
WriteAllText
(
path
,
json
);
MessageBox
.
Show
(
$"成功保存到
{
path
}
"
);
}
private
async
void
btnLoadGridAdvClick
(
object
sender
,
RoutedEventArgs
e
)
{
string
strDesktopPath
=
Environment
.
GetFolderPath
(
Environment
.
SpecialFolder
.
DesktopDirectory
);
OpenFileDialog
openFileDialog
=
new
OpenFileDialog
();
openFileDialog
.
DefaultExt
=
".json"
;
openFileDialog
.
Filter
=
"json文件|*.json"
;
openFileDialog
.
InitialDirectory
=
strDesktopPath
;
if
(
openFileDialog
.
ShowDialog
()
!=
true
)
return
;
string
path
=
openFileDialog
.
FileName
;
string
json
=
File
.
ReadAllText
(
path
);
try
{
gridAdvUnits
=
Newtonsoft
.
Json
.
JsonConvert
.
DeserializeObject
<
List
<
IEnumerable
<
GridAdvUnit
>>>(
json
);
}
catch
(
Exception
ex
)
{
MessageBox
.
Show
(
$"读取失败
{
ex
}
"
);
return
;
}
if
(
gridAdvUnits
==
null
)
{
gridAdvUnits
=
new
List
<
IEnumerable
<
GridAdvUnit
>>();
MessageBox
.
Show
(
$"读取失败 没有数据"
);
}
else
{
await
Task
.
Factory
.
StartNew
(()
=>
{
foreach
(
var
units
in
gridAdvUnits
)
{
DrawGridAdv
(
units
);
}
if
(
gridAdvUnits
.
Count
>
chart3
.
Series
.
Count
())
gridAdvUnits
.
RemoveAt
(
0
);
if
(
gridAdvUnits
.
Count
()
>=
2
)
{
CurrR
=
CalGridAdvR
(
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
1
],
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
2
],
0
);
}
});
MessageBox
.
Show
(
$"读取成功"
);
}
}
private
async
void
btnCalAdLagClick
(
object
sender
,
RoutedEventArgs
e
)
{
if
(
gridAdvUnits
.
Count
()
<
2
)
{
MessageBox
.
Show
(
"数量小于2次"
);
return
;
}
int
bestAdLag
=
0
;
double
bestR
=-
1
;
await
Task
.
Factory
.
StartNew
(()
=>
{
CalAdLag
(
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
1
],
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
2
],
0
,
(
int
)(
1000
/
1.28
),
0.99
,
out
bestAdLag
,
out
bestR
);
});
BestAdLag
=
bestAdLag
;
BestR
=
bestR
;
await
Task
.
Factory
.
StartNew
(()
=>
{
DrawGridAdv
(
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
1
],
BestAdLag
);
DrawGridAdv
(
gridAdvUnits
[
gridAdvUnits
.
Count
()
-
2
],
BestAdLag
);
});
MessageBox
.
Show
(
$"计算完成 最佳滞后=
{
BestAdLag
}
"
);
}
#
endregion
int
timecnt
=
0
;
class
MaxMin
{
...
...
@@ -751,7 +466,6 @@ namespace Flyad7_WPF
param
.
HVelocity2
=
flyad
.
HVelocity2
;
param
.
PosLen
=
flyad
.
PosLen
;
param
.
ADLag
=
flyad
.
ADLag
;
param
.
Save
();
MessageBox
.
Show
(
"保存成功"
);
}
...
...
@@ -764,7 +478,6 @@ namespace Flyad7_WPF
flyad
.
DTime
=
param
.
DTime
;
flyad
.
HVelocity1
=
param
.
HVelocity1
;
flyad
.
HVelocity2
=
param
.
HVelocity2
;
flyad
.
PosLen
=
param
.
PosLen
;
flyad
.
ADLag
=
param
.
ADLag
;
...
...
@@ -793,8 +506,6 @@ namespace Flyad7_WPF
{
flyad
.
RuntoMax
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment