-
-
Save dj1711572002/6356c9c6a6233fc35e1ae7de1e3a22be to your computer and use it in GitHub Desktop.
C# GPS Doppler Graphic Pgm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
using System.IO.Ports; | |
using System.Diagnostics; | |
using Microsoft.VisualBasic.FileIO; | |
namespace ITP_LPS_rev011 | |
{ | |
public partial class Form1 : Form | |
{ | |
int rN; | |
int rowN;//dgv rowCount | |
String fname; | |
public double[] f; | |
public double[] fout; | |
public double [] fkekka; | |
//bitmap definition | |
const int bw=180000 ; | |
Bitmap sourceBitmap = new Bitmap(bw, 500);//X軸bw個 data(10msec周期で300秒) Y軸 | |
Bitmap trimmedBitmap = new Bitmap(1000, 500);//PictuerBox1に貼りこむBitmap | |
//ComboBoxArray | |
private System.Windows.Forms.ComboBox[] CBarry; | |
//CheckBox Arry | |
private System.Windows.Forms.CheckBox[] CKarry; | |
//Struct GraphLine | |
public Color []samples= new Color[] { Color.Red, Color.Blue, Color.Green ,Color.Yellow,Color.Aqua,Color.DeepPink}; | |
struct lines | |
{ | |
public string name;//LIne名 選択されたデータ名 | |
public bool available;//Lineが有効:true 無効:false | |
public int colN;//Column番号 | |
public Color clr; | |
public int sa;//data 間隔 | |
public int rN_avail; | |
public int period; | |
public int x; | |
public int x_1; | |
public int y; | |
public int y_1; | |
public int max; | |
public int min; | |
public int baseL;//Graph base Line 1/2 1/1 | |
public int uscale;//headMot=100000 | |
} | |
lines[] gline;//gline global | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
serialPort1.BaudRate = 115200; | |
serialPort1.Parity = Parity.None; | |
serialPort1.DataBits = 8; | |
serialPort1.StopBits = StopBits.One; | |
serialPort1.Handshake = Handshake.None; | |
serialPort1.PortName = portComboBox.Text; | |
serialPort1.Open(); | |
//file name timestanmp | |
DateTime dt = DateTime.Now; | |
fname = dt.ToString($"{dt:MMddHHmm}"); | |
string fpath = "C:/RTK_LOG/"; | |
fname = fpath + fname + ".csv"; | |
textBox2.Text = fname; | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
this.Text = "ITP_LPS_rev011"; | |
string[] ports = SerialPort.GetPortNames(); | |
foreach (string port in ports) | |
{ | |
portComboBox.Items.Add(port); | |
} | |
if (portComboBox.Items.Count > 0) | |
{ | |
portComboBox.SelectedIndex = 0; | |
} | |
rN = 0; | |
//--------------------------------- | |
// this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseWheel); | |
//comboBox7 MovingAverage 初期値0 | |
comboBox7.SelectedIndex = 0; | |
//comboBox配列で一括定義------------------------------ | |
this.CBarry = new System.Windows.Forms.ComboBox[6]; | |
this.CKarry = new System.Windows.Forms.CheckBox[6]; | |
//ボタンコントロールの配列にすでに作成されているインスタンスを代入 | |
this.CBarry[0] = this.comboBox1; | |
this.CBarry[1] = this.comboBox2; | |
this.CBarry[2] = this.comboBox3; | |
this.CBarry[3] = this.comboBox4; | |
this.CBarry[4] = this.comboBox5; | |
this.CBarry[5] = this.comboBox6; | |
//チェックボックス配列 | |
this.CKarry[0] = this.checkBox2; | |
this.CKarry[1] = this.checkBox3; | |
this.CKarry[2] = this.checkBox4; | |
this.CKarry[3] = this.checkBox5; | |
this.CKarry[4] = this.checkBox6; | |
this.CKarry[5] = this.checkBox7; | |
//combobox color | |
// comboBox1.BackColor = Color.Red; | |
int ia; | |
for (ia = 0; ia <6; ia++) | |
{ | |
CBarry[ia].BackColor=samples[ia]; | |
CBarry[ia].Items.Add("無し"); | |
CBarry[ia].Items.Add("No"); | |
CBarry[ia].Items.Add("itow"); | |
CBarry[ia].Items.Add("f9p_gSpeed(10Hz)"); | |
CBarry[ia].Items.Add("f9p_gSpeed(50Hz)"); | |
CBarry[ia].Items.Add("f9p_headMot(10Hz)"); | |
CBarry[ia].Items.Add("f9p_headMot(50Hz)"); | |
CBarry[ia].Items.Add("lon(10Hz)"); | |
CBarry[ia].Items.Add("lon(50Hz)"); | |
CBarry[ia].Items.Add("lat(10Hz)"); | |
CBarry[ia].Items.Add("lat(50Hz)"); | |
CBarry[ia].Items.Add("f9p_velN(10Hz)"); | |
CBarry[ia].Items.Add("f9p_velN(50Hz)"); | |
CBarry[ia].Items.Add("f9p_velE(10Hz)"); | |
CBarry[ia].Items.Add("f9p_velE(50Hz)"); | |
CBarry[ia].Items.Add("f9p_velD(10Hz)"); | |
CBarry[ia].Items.Add("f9p_velD(50Hz)"); | |
CBarry[ia].Items.Add("flags"); | |
CBarry[ia].Items.Add("hacc"); | |
CBarry[ia].Items.Add("m9n_gSpeed(25Hz)"); | |
CBarry[ia].Items.Add("m9n_gSpeed(50Hz)"); | |
CBarry[ia].Items.Add("m9n_headMot(25Hz)"); | |
CBarry[ia].Items.Add("m9n_headMot(50Hz)"); | |
CBarry[ia].Items.Add("m9n_velN(25Hz)"); | |
CBarry[ia].Items.Add("m9n_velN(50Hz)"); | |
CBarry[ia].Items.Add("m9n_velE(25Hz)"); | |
CBarry[ia].Items.Add("m9n_velE(50Hz)"); | |
CBarry[ia].Items.Add("m9n_velD(25Hz)"); | |
CBarry[ia].Items.Add("m9n_velD(50Hz)"); | |
//MA | |
CBarry[ia].Items.Add("m9n_gSpeed_MA(25Hz)"); | |
CBarry[ia].Items.Add("m9n_gSpeed_MA(50Hz)"); | |
CBarry[ia].Items.Add("m9n_headMot_MA(25Hz)"); | |
CBarry[ia].Items.Add("m9n_headMot_MA(50Hz)"); | |
CBarry[ia].Items.Add("m9n_velN_MA(25Hz)"); | |
CBarry[ia].Items.Add("m9n_velN_MA(50Hz)"); | |
CBarry[ia].Items.Add("m9n_velE_MA(25Hz)"); | |
CBarry[ia].Items.Add("m9n_velE_MA(50Hz)"); | |
CBarry[ia].Items.Add("m9n_velD_MA(25Hz)"); | |
CBarry[ia].Items.Add("m9n_velD_MA(50Hz)"); | |
CBarry[ia].SelectedIndex = 0; | |
} | |
} | |
private void name2gline(int comN) | |
{ | |
string name= CBarry[comN].Text; | |
gline[comN].name = name; | |
gline[comN].clr = samples[comN]; | |
gline[comN].available = true; | |
gline[comN].max = 10000; | |
gline[comN].min = -10000; | |
gline[comN].baseL = 2; | |
gline[comN].uscale = 1; | |
int coln= 0; | |
if (name == "無し") { gline[comN].colN = -1;gline[comN].available = false; } | |
if (name == "No") { gline[comN].colN = 0; } | |
if (name == "itow") { gline[comN].colN = 1; } | |
if (name == "f9p_gSpeed(10Hz)") { gline[comN].colN = 2; gline[comN].sa = 5;gline[comN].period = 100; } | |
if (name == "f9p_gSpeed(50Hz)") { gline[comN].colN = 2; gline[comN].sa = 1; gline[comN].period = 20; } | |
if (name == "f9p_headMot(10Hz)") { gline[comN].colN = 3; gline[comN].sa = 5; gline[comN].period = 100;gline[comN].max = 36000000; gline[comN].min = 0;gline[comN].baseL = 1; gline[comN].uscale = 100000; } | |
if (name == "f9p_headMot(50Hz)") { gline[comN].colN = 3; gline[comN].sa = 1; gline[comN].period = 20;gline[comN].max = 36000000; gline[comN].min = 0; gline[comN].baseL = 1; gline[comN].uscale = 100000; } | |
if (name == "lon(10Hz)") { gline[comN].colN = 4; gline[comN].sa = 5; gline[comN].period = 100; } | |
if (name == "lon(50Hz)") { gline[comN].colN = 4; gline[comN].sa = 1; gline[comN].period = 20; } | |
if (name == "lat(10Hz)") { gline[comN].colN = 5; gline[comN].sa = 5; gline[comN].period = 100; } | |
if (name == "lat(50Hz)") { gline[comN].colN = 5; gline[comN].sa = 1; gline[comN].period = 20; } | |
if (name == "f9p_velN(10Hz)") { gline[comN].colN = 6; gline[comN].sa = 5; gline[comN].period = 100; } | |
if (name == "f9p_velN(50Hz)") { gline[comN].colN = 6; gline[comN].sa = 1; gline[comN].period = 20; } | |
if (name == "f9p_velE(10Hz)") { gline[comN].colN = 7; gline[comN].sa = 5; gline[comN].period = 100; } | |
if (name == "f9p_velE(50Hz)") { gline[comN].colN = 7; gline[comN].sa = 1; gline[comN].period = 20; } | |
if (name == "f9p_velD(10Hz)") { gline[comN].colN = 8; gline[comN].sa = 5; gline[comN].period = 100; } | |
if (name == "f9p_velD(50Hz)") { gline[comN].colN = 8; gline[comN].sa = 1; gline[comN].period = 20; } | |
if (name == "flags") { gline[comN].colN = 9;} | |
if (name == "hacc") { gline[comN].colN = 10; } | |
if (name == "m9n_gSpeed(25Hz)") { gline[comN].colN = 11; gline[comN].sa = 2; gline[comN].period =40; } | |
if (name == "m9n_gSpeed(50Hz)") { gline[comN].colN = 11; gline[comN].sa = 1; gline[comN].period = 20; } | |
if (name == "m9n_headMot(25Hz)") { gline[comN].colN = 12; gline[comN].sa = 2; gline[comN].period = 40; gline[comN].max = 36000000; gline[comN].min = 0; gline[comN].baseL = 1; gline[comN].uscale = 100000; } | |
if (name == "m9n_headMot(50Hz)") { gline[comN].colN = 12; gline[comN].sa = 1; gline[comN].period = 20; gline[comN].max = 36000000; gline[comN].min = 0; gline[comN].baseL = 1; gline[comN].uscale = 100000; } | |
if (name == "m9n_velN(25Hz)") { gline[comN].colN = 13; gline[comN].sa = 2; gline[comN].period = 40; } | |
if (name == "m9n_velN(50Hz)") { gline[comN].colN = 13; gline[comN].sa = 1; gline[comN].period = 20; } | |
if (name == "m9n_velE(25Hz)") { gline[comN].colN = 14; gline[comN].sa = 2; gline[comN].period = 40; } | |
if (name == "m9n_velE(50Hz)") { gline[comN].colN = 14; gline[comN].sa = 1; gline[comN].period = 20; } | |
if (name == "m9n_velD(25Hz)") { gline[comN].colN = 15; gline[comN].sa = 2; gline[comN].period = 40; } | |
if (name == "m9n_velD(50Hz)") { gline[comN].colN = 15; gline[comN].sa = 1; gline[comN].period = 20; } | |
//MA | |
if (name == "m9n_gSpeed_MA(25Hz)") { gline[comN].colN = 16; gline[comN].sa = 2; gline[comN].period = 40; } | |
if (name == "m9n_gSpeed_MA(50Hz)") { gline[comN].colN = 16; gline[comN].sa = 1; gline[comN].period = 20; } | |
if (name == "m9n_headMot_MA(25Hz)") { gline[comN].colN = 17; gline[comN].sa = 2; gline[comN].period = 40; gline[comN].max = 36000000; gline[comN].min = 0; gline[comN].baseL = 1; gline[comN].uscale = 100000; } | |
if (name == "m9n_headMot_MA(50Hz)") { gline[comN].colN = 17; gline[comN].sa = 1; gline[comN].period = 20; gline[comN].max = 36000000; gline[comN].min = 0; gline[comN].baseL = 1; gline[comN].uscale = 100000; } | |
if (name == "m9n_velN_MA(25Hz)") { gline[comN].colN = 18; gline[comN].sa = 2; gline[comN].period = 40; } | |
if (name == "m9n_velN_MA(50Hz)") { gline[comN].colN = 18; gline[comN].sa = 1; gline[comN].period = 20; } | |
if (name == "m9n_velE_MA(25Hz)") { gline[comN].colN = 19; gline[comN].sa = 2; gline[comN].period = 40; } | |
if (name == "m9n_velE_MA(50Hz)") { gline[comN].colN = 19; gline[comN].sa = 1; gline[comN].period = 20; } | |
if (name == "m9n_velD_MA(25Hz)") { gline[comN].colN = 20; gline[comN].sa = 2; gline[comN].period = 40; } | |
if (name == "m9n_velD_MA(50Hz)") { gline[comN].colN = 20; gline[comN].sa = 1; gline[comN].period = 20; } | |
} | |
private void button5_Click(object sender, EventArgs e) | |
{ | |
//******************************************************************************************************************* | |
// BryantFilter2(double[] f,double []fout, int rowmin, int rowmax, int colmin, int colmax, double fc, double fs) | |
//******************************************************************************************************************* | |
//Input Array making 11:M9N_gSpeed,12:M9N_headMot,13:M9N_velN,14:M9N_velE,15:M9N_velD | |
int i,j,k, n; | |
int l = 0; | |
int m = 0; | |
int roN = dgv1.RowCount; | |
f = new double[roN];//Globalで定義 | |
fout= new double[roN];//Globalで定義 | |
fkekka = new double[rowN];//Globalで定義 | |
int fc = Convert.ToInt32(textBox12.Text);// 2;//CUt off Hz | |
int fs = Convert.ToInt32(textBox11.Text);//25;//Sampling Hz | |
for (i = 11; i < 16; i++)//列カウンタ//M9N 11=gSpeed,12=headMot,13=velN,14=velE,15=velD | |
{ | |
m = 0; | |
for (j = 0; j < roN - 1; j++)//f配列作成 | |
{ | |
int itow = Convert.ToInt32(dgv1.Rows[j].Cells[1].Value); | |
if (itow % 40 == 0)//25Hzデータ抽出 | |
{ | |
f[m] = Convert.ToDouble(dgv1.Rows[j].Cells[i].Value); | |
double dummy = f[m]; | |
// Debug.Print("Make:f[" + m.ToString() + ",0]=" + f[m, 0].ToString()); | |
m++; | |
} | |
} | |
//BryantFilter2(double[] f,double []fout, int rowmin, int rowmax, int colmin, int colmax, double fc, double fs) | |
BryantFilter2(f, fout, 1, m - 1, 0, 1, fc, fs); | |
Debug.Print("Filter Finished m-1=" + (m - 1).ToString()); | |
int mi = 0; | |
dgv1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True; | |
dgv1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; | |
dgv1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; | |
for (l = 0; l < roN; l++) | |
{ | |
int itow = Convert.ToInt32(dgv1.Rows[l].Cells[1].Value); | |
if (itow % 40 == 0) | |
{ | |
dgv1.Rows[l].Cells[i + 5].Value = fout[mi].ToString(); | |
//Debug.Print("Kekka:fout[" + l.ToString() + "]=" + fout[mi].ToString() + "fkekka=" + fkekka[mi].ToString()); | |
mi++; | |
} | |
} | |
} | |
}//button5 filter | |
// BryantFilter(); | |
/* | |
//OpenFileDialogクラスのインスタンスを作成 | |
OpenFileDialog ofd = new OpenFileDialog(); | |
//ダイアログを表示する | |
if (ofd.ShowDialog() == DialogResult.OK) | |
{ | |
// DataGridView初期化(データクリア) | |
dgv1.Columns.Clear(); | |
dgv1.Rows.Clear(); | |
// dgv1 set | |
dgv1.ColumnCount = 21; | |
dgv1.RowCount = 2; | |
dgv1.RowHeadersWidth = 80; | |
dgv1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True; | |
dgv1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; | |
dgv1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; | |
headerName(); | |
rowN = 0; | |
//OKボタンがクリックされたとき、選択されたファイルを読み取り専用で開く | |
textBox2.Text = ofd.FileName; | |
using (var parser = new TextFieldParser(ofd.FileName))////@"C:\Test\car1.csv")) | |
{ | |
parser.Delimiters = new string[] { "," }; | |
while (!parser.EndOfData) | |
{ | |
//Console.WriteLine("-----"); | |
// richTextBox1.AppendText("\n"); | |
var fields = parser.ReadFields(); | |
//int ifi; | |
dgv1.Rows.Add(fields);//dgv1書き込み | |
rowN++; | |
dgv1.Rows[rowN].HeaderCell.Value = rowN.ToString(); | |
// for (ifi = 0; ifi < fields.Length; ifi++) | |
// { | |
// Debug.Print(fields[ifi]); | |
// richTextBox1.AppendText(fields[ifi]); | |
// } | |
//foreach (string s in fields) | |
//{ | |
//Console.WriteLine($"{s}"); | |
// richTextBox1.AppendText(s+"," ); | |
//Debug.Print(s); | |
//} | |
} | |
} | |
*/ | |
/* | |
// MA計算 列作成 | |
int MA = Convert.ToInt32(comboBox7.SelectedItem); | |
int ir, im, ic; | |
int sum0 = 0; | |
int sumN = 0; | |
int srccol = 11;//元列開始 | |
int dcol = 5;//書き込み列開始増分 | |
int rowN = dgv1.RowCount; | |
// auto size off | |
dgv1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; | |
dgv1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; | |
//dgv1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; | |
// Debug.Print("MA=" + MA.ToString()); | |
if (MA > 0) | |
{ | |
{ | |
for (ic = 11; ic < 16; ic++)//ソース列 | |
{ | |
// Debug.Print("ic=" + ic.ToString()); | |
for (ir = MA; ir < rowN - MA - 1; ir++)//行ループ MAから行移動平均結果を入力 | |
{ | |
sum0 = 0; | |
for (im = 0; im < MA; im++)//MAループ回す | |
{ | |
sum0 = sum0 + Convert.ToInt32(dgv1.Rows[ir - im].Cells[ic].Value); | |
} | |
int ave = (int)((double)sum0 / MA); | |
// Debug.Print("ic=" + ic.ToString() + "ir=" + ir.ToString() + "ave=" + ave.ToString()); | |
dgv1.Rows[ir].Cells[ic + dcol].Value = ave.ToString(); | |
} | |
} | |
} | |
} | |
*/ | |
// } | |
//======================================================================================= | |
//=======================Low Pass Filter================================================= | |
//======================================================================================= | |
//private void BryantFilter2(double[,] f,double [,]fout, int rowmin, int rowmax, int colmin, int colmax, double fc, double fs) | |
private void BryantFilter2(double[] f, double []fout, int rowmin, int rowmax, int colmin, int colmax, double fc, double fs) | |
{ | |
int i, j; | |
double[] temp = new double[rowmax]; | |
for(i=rowmin;i<rowmax;i++) | |
{ | |
for (j = colmin; j <= colmax; j++) | |
{ | |
temp[i] = f[i]; | |
fout[i] = f[i]; | |
// Debug.Print("temp[" + i.ToString() + ",0]=" + temp[i, 0].ToString()); | |
} | |
} | |
//Bryant のバターワースフィルタ,臨床歩行分析入門より | |
double FF,W,B,c,D; | |
FF = fc / fs; | |
W = Math.Tan(3.14159 * FF); | |
B = 1 + Math.Sqrt(2) * W + W * W; | |
c = 2 * (1 - W * W) / B; | |
D = -(1 - Math.Sqrt(2) * W + W * W) / B; | |
j =0; | |
for (i = rowmin + 2; i < rowmax-1; i ++) | |
{ | |
fout[i] = (temp[i] + 2 * temp[i - 1] + temp[i - 2]) * W *W / B + c * fout[i - 1] + D * fout[i - 2]; | |
// Debug.Print("InFilter:temp["+i.ToString()+","+j.ToString()+"]=" + temp[i].ToString() + ",fout["+i.ToString()+"]=" + fout[i].ToString()); | |
} | |
Debug.Print("Pass1"+"rowmax="+rowmax.ToString()); | |
//反対側からもう一度 | |
for (i = rowmin; i < rowmax; i++) | |
{ | |
j = 0; | |
temp[i] = fout[i]; | |
} | |
for( i = rowmax -3;i> rowmin;i--) | |
{ | |
fout[i] = (temp[i] + 2 * temp[i + 1] + temp[i + 2]) * W * W / B + c * fout[i + 1] + D * fout[i + 2]; | |
fkekka[i] = fout[i]; | |
// Debug.Print("GyakunFilter:temp[" + i.ToString()+ "]=" + temp[i].ToString() + ",fout[]=" + fout[i].ToString(), "fkekka=" + fkekka[i].ToString()); | |
} | |
}// BryantFileter END================================================================= | |
//==================================================================================== | |
//private void countCombo(int[] LiN, int[] sa) | |
private void countCombo() | |
{ | |
//構造体 | |
this.gline = new lines[6]; | |
int icom;//combobox No | |
for (icom = 0; icom < 6; icom++) | |
{ | |
if (CBarry[icom].SelectedIndex > 0) | |
{ | |
gline[icom].available = true; | |
name2gline(icom); | |
// richTextBox1.AppendText(gline[icom].name + ","+gline[icom].colN+","+gline[icom].sa+","+gline[icom].period+","+"\r"); | |
} | |
else | |
{ | |
gline[icom].available = false; | |
} | |
} | |
} | |
// button 2で、グラフ | |
private void button2_Click(object sender, EventArgs e) | |
{ | |
pictureBox1.Visible = false; | |
ReadDialog(); | |
} | |
delegate void SetTextCallback(string text); | |
private void Response(string text) | |
{ | |
if (textBox1.InvokeRequired) | |
{ | |
SetTextCallback d = new SetTextCallback(Response); | |
BeginInvoke(d, new object[] { text }); | |
} | |
else | |
{ | |
// textBox1.AppendText(text + "\n"); | |
//===============データグリッドビュー dgv1へ記録=================== | |
// string[] data =( text+",\n").Split(',');//カンマ区切りにばらす | |
string[] data = text.Split(',');//カンマ区切りにばらす | |
int cN = 21;// data.Length16+5; | |
//data[] to string | |
int iN; | |
string datas = ""; | |
for (iN = 0; iN < cN; iN++) | |
{ | |
datas = datas + "," + data[iN]; | |
// Debug.Print("data[" + iN.ToString() + "]=" + data[iN]); | |
} | |
datas = datas + "\r\n"; | |
// Debug.Print("rN=" + rN.ToString()+"text=" + datas); | |
// 自動csv保存 書き込むファイルが既に存在している場合は、Appendする | |
System.IO.StreamWriter sw = new System.IO.StreamWriter(@fname, true, System.Text.Encoding.GetEncoding("shift_jis")); | |
//TextBox1.Textの内容を書き込む | |
sw.Write(datas); | |
//閉じる | |
sw.Close(); | |
if (rN == 0)//行カウントrN==0のときdgv1定義 | |
{ | |
//dgv1.DefaultCellStyle.Font = new Font("Tahoma", 10); | |
//dgv1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders; | |
dgv1.ColumnCount = cN; | |
dgv1.RowCount = 2; | |
dgv1.RowHeadersWidth = 100; | |
dgv1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True; | |
// dgv1.Columns[0].DefaultCellStyle.Alignment =DataGridViewContentAlignment.TopLeft; | |
} | |
rN++; | |
dgv1.FirstDisplayedScrollingRowIndex = rN; | |
dgv1.Rows.Add(data);//dgv1書き込み | |
dgv1.Rows[rN].HeaderCell.Value = rN.ToString(); | |
//================================================================= | |
} | |
} | |
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) | |
{ | |
serialPort1.NewLine = "\r\n"; | |
string str = serialPort1.ReadLine(); | |
Response(str); | |
} | |
private void button3_Click(object sender, EventArgs e) | |
{ | |
serialPort1.Close(); | |
} | |
//==================Open File Dialog============================== | |
private void ReadDialog() | |
{ | |
int irn = 0; | |
int icn = 0; | |
//sourceBitmap_clear(); | |
//OpenFileDialogクラスのインスタンスを作成 | |
OpenFileDialog ofd = new OpenFileDialog(); | |
//ダイアログを表示する | |
if (ofd.ShowDialog() == DialogResult.OK) | |
{ | |
// DataGridView初期化(データクリア) | |
dgv1.Columns.Clear(); | |
dgv1.Rows.Clear(); | |
// dgv1 set | |
dgv1.ColumnCount = 21; | |
dgv1.RowCount = 2; | |
dgv1.RowHeadersWidth = 80; | |
dgv1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True; | |
dgv1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; | |
dgv1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; | |
headerName(); | |
rowN = 0; | |
//OKボタンがクリックされたとき、選択されたファイルを読み取り専用で開く | |
textBox2.Text = ofd.FileName; | |
using (var parser = new TextFieldParser(ofd.FileName))////@"C:\Test\car1.csv")) | |
{ | |
parser.Delimiters = new string[] { "," }; | |
while (!parser.EndOfData) | |
{ | |
//Console.WriteLine("-----"); | |
var fields = parser.ReadFields(); | |
dgv1.Rows.Add(fields);//dgv1書き込み | |
rowN++; | |
dgv1.Rows[rowN].HeaderCell.Value = rowN.ToString(); | |
} | |
label1.Text = "dgvRows=" + rowN.ToString(); | |
} | |
/* | |
System.IO.Stream stream; | |
stream = ofd.OpenFile(); | |
if (stream != null) | |
{ | |
//内容を読み込み、表示する | |
System.IO.StreamReader sr = new System.IO.StreamReader(stream); | |
while (sr.Peek() >-1) | |
{ | |
// ReadLineメソッドで1行の文字列データを読み込む | |
string txt = sr.ReadLine(); | |
string[] datasr = txt.Split(',');//カンマ区切りにばらす | |
//Debug.Print(datasr); | |
rowN++; | |
dgv1.Rows.Add(datasr);//dgv1書き込み | |
// dgv1.Rows[rowN].HeaderCell.Value = rowN.ToString(); | |
//richTextBox1.AppendText(rowN.ToString()); | |
} | |
//閉じる | |
sr.Close(); | |
stream.Close(); | |
label1.Text = "dgvRows=" + rowN.ToString(); | |
} | |
} | |
*/ | |
} | |
/* | |
int[] max = new int[16]; | |
int[] maxrow = new int[16]; | |
int[] min = new int[16]; | |
int[] minrow = new int[16]; | |
//最大値を求める | |
for (icn = 0; icn < 16; icn++)//列スキャン | |
{ | |
min[icn] = 10000000; | |
for (irn = 0; irn < rowN; irn++)//行スキャン | |
{ | |
int celval = Convert.ToInt32(dgv1.Rows[irn].Cells[icn].Value); | |
// Debug.Print("icn="+icn.ToString()+"celval=" + celval.ToString() + "," + "max=" + max[icn].ToString() + "min=" + min[icn].ToString()); | |
if (max[icn] < celval) { max[icn] = celval; maxrow[icn] = irn; } | |
if (min[icn] > celval) { min[icn] = celval; minrow[icn] = irn; } | |
} | |
//richTextBox1.AppendText(dgv1.Columns[icn].HeaderText +"max[" + icn + "]=" + max[icn].ToString() + ",maxrow=" + maxrow[icn].ToString() + "\n"); | |
//richTextBox1.AppendText(dgv1.Columns[icn].HeaderText+"min[" + icn + "]=" + min[icn].ToString() + ",minrow=" + minrow[icn].ToString() + "\n"); | |
} | |
//max,maxrow,min,minrowをdgv1最終行に追記---------------------------------------- | |
dgv1.Rows.Add(); | |
dgv1.Rows.Add(); | |
dgv1.Rows.Add(); | |
dgv1.Rows[rowN + 1].Cells[0].Value = "max[]"; | |
dgv1.Rows[rowN + 2].Cells[0].Value = "maxrow[]"; | |
dgv1.Rows[rowN + 3].Cells[0].Value = "min[]"; | |
dgv1.Rows[rowN + 4].Cells[0].Value = "minrow[]"; | |
for (icn = 1; icn < 16; icn++) | |
{ | |
dgv1.Rows[rowN + 1].Cells[icn].Value = max[icn].ToString(); | |
dgv1.Rows[rowN + 2].Cells[icn].Value = maxrow[icn].ToString(); | |
dgv1.Rows[rowN + 3].Cells[icn].Value = min[icn].ToString(); | |
dgv1.Rows[rowN + 4].Cells[icn].Value = minrow[icn].ToString(); | |
} | |
*/ | |
//M9N MovingAverage processing | |
//m9nMA(); | |
/* | |
//-------------sourceBitmap にプロット------------------------- | |
for (irn = 1; irn < rowN; irn++) | |
{ | |
plotVel(irn, 0); | |
} | |
//hscrollbar1のセット | |
hScrollBar1.Minimum = 0; | |
hScrollBar1.Maximum = rowN; | |
hScrollBar1.Value = rowN; | |
textBox3.Text = hScrollBar1.Value.ToString(); | |
//------------------------------------------------------------- | |
*/ | |
} | |
// M9N MovingAveraging | |
private void m9nMA() | |
{ | |
// MA計算 列作成 | |
int MA = Convert.ToInt32(comboBox7.SelectedItem); | |
int ir, im, ic; | |
int sum0 = 0; | |
int sumN = 0; | |
int srccol = 11;//元列開始 | |
int dcol = 5;//書き込み列開始増分 | |
int rowN = dgv1.RowCount; | |
// auto size off | |
dgv1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; | |
dgv1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None; | |
//dgv1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; | |
// Debug.Print("MA=" + MA.ToString()); | |
if (MA > 0) | |
{ | |
{ | |
for (ic = 11; ic < 16; ic++)//ソース列 | |
{ | |
// Debug.Print("ic=" + ic.ToString()); | |
for (ir = MA; ir < rowN - MA - 1; ir++)//行ループ MAから行移動平均結果を入力 | |
{ | |
sum0 = 0; | |
for (im = 0; im < MA; im++)//MAループ回す | |
{ | |
sum0 = sum0 + Convert.ToInt32(dgv1.Rows[ir - im].Cells[ic].Value); | |
} | |
int ave = (int)((double)sum0 / MA); | |
// Debug.Print("ic=" + ic.ToString() + "ir=" + ir.ToString() + "ave=" + ave.ToString()); | |
dgv1.Rows[ir].Cells[ic + dcol].Value = ave.ToString(); | |
} | |
} | |
} | |
} | |
} | |
private void checkBox1_CheckedChanged(object sender, EventArgs e) | |
{ | |
if (checkBox1.Checked == true) | |
{ | |
pictureBox1.Visible = false; | |
dgv1.Visible = true; | |
} | |
else | |
{ | |
dgv1.Visible = false; | |
pictureBox1.Visible = true; | |
} | |
} | |
private void headerName() | |
{ | |
{ | |
dgv1.ColumnHeadersDefaultCellStyle.Font = new Font(dgv1.Font, FontStyle.Bold); | |
//DataGridView1の行ヘッダーに行番号を表示する | |
dgv1.Columns[0].HeaderText = "No"; | |
dgv1.Columns[1].HeaderText = "itow"; | |
dgv1.Columns[2].HeaderText = "f9p_gSpeed"; | |
dgv1.Columns[3].HeaderText = "f9p_headMot"; | |
dgv1.Columns[4].HeaderText = "lon"; | |
dgv1.Columns[5].HeaderText = "lat"; | |
dgv1.Columns[6].HeaderText = "f9p_velN"; | |
dgv1.Columns[7].HeaderText = "f9p_velE"; | |
dgv1.Columns[8].HeaderText = "f9p_velD"; | |
dgv1.Columns[9].HeaderText = "flags"; | |
dgv1.Columns[10].HeaderText = "hacc"; | |
dgv1.Columns[11].HeaderText = "m9n_gSpeed"; | |
dgv1.Columns[12].HeaderText = "m9n_headMot"; | |
dgv1.Columns[13].HeaderText = "m9n_velN"; | |
dgv1.Columns[14].HeaderText = "m9n_velE"; | |
dgv1.Columns[15].HeaderText = "m9n_velD"; | |
dgv1.Columns[16].HeaderText = "m9n_gSpeed_MA"; | |
dgv1.Columns[17].HeaderText = "m9n_headMot_MA"; | |
dgv1.Columns[18].HeaderText = "m9n_velN_MA"; | |
dgv1.Columns[19].HeaderText = "m9n_velE_MA"; | |
dgv1.Columns[20].HeaderText = "m9n_velD_MA"; | |
//ヘッダーとすべてのセルの内容に合わせて、列の幅を自動調整する | |
dgv1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; | |
int i; | |
for (i = 0; i < 21; i++) | |
{ | |
dgv1.Rows[0].Cells[i].Value = i.ToString(); | |
} | |
} | |
} | |
//==================PLOT ボタン押し========================================= | |
private void button4_Click(object sender, EventArgs e)//PLOT4 ボタン押してグラフ開始 | |
{ | |
//グラフパラメータセッツアップ | |
//comboBox配列から読み取り | |
countCombo();//comboBox 6個からプロット列と周期を読み取るgline[]構造体を作成 | |
//source Bitmapを作成 | |
makeSrcBitmap(); | |
int ir; | |
pictureBox1.Visible = true; | |
hScrollBar1.Minimum = 0; | |
int xdot = timeScale(); | |
hScrollBar1.Maximum = rowN*xdot; | |
hScrollBar1.Value = rowN*xdot; | |
textBox3.Text = Convert.ToInt32(hScrollBar1.Value/xdot).ToString(); | |
sourceCut(rowN*xdot); | |
/* | |
if (rowN > 1000) | |
{ | |
for (ir = rowN - 1000; ir < rowN; ir++) | |
{ | |
plotVel(ir, 1); | |
} | |
} | |
*/ | |
} | |
// ------SourceBitmapの作成------------------------------ | |
private void makeSrcBitmap() | |
{ | |
int gsel;//gline selector | |
int irn; | |
int pw = pictureBox1.Width; | |
int ph = pictureBox1.Height; | |
int velMax = 10000; | |
int velMin = -10000; | |
int headMax = 36000000; | |
int headMin = 0; | |
int xdot = timeScale(); | |
// double yscale = (double)ph / (velMax - velMin); | |
Graphics g1 = Graphics.FromImage(sourceBitmap); | |
g1.Clear(Color.Black); | |
for (gsel=0;gsel<6;gsel++) | |
{ | |
if(gline[gsel].available==true) | |
{ | |
int pmsec = gline[gsel].period; | |
int psa = gline[gsel].sa; | |
int pcoln = gline[gsel].colN; | |
double yscale = (double)ph / (gline[gsel].max - gline[gsel].min); | |
//Debug.Print("gline[" + gsel.ToString() + "].colN=" + gline[gsel].colN.ToString()); | |
for (irn=2;irn<rowN;irn++) | |
{ | |
int itow0 = Convert.ToInt32(dgv1.Rows[irn].Cells[1].Value); | |
// Debug.Print("itow0=" + itow0.ToString() + "gline[" + gsel.ToString() + "].colN=" + gline[gsel].colN.ToString()); | |
Pen p = new Pen(samples[gsel], 1); | |
Brush b1 = new SolidBrush(samples[gsel]); | |
if ( itow0%pmsec==0 && irn>psa) | |
{ | |
// Debug.Print("irn=" + irn.ToString() + "psa=" + psa.ToString()); | |
int y0 = Convert.ToInt32(dgv1.Rows[irn].Cells[pcoln].Value); | |
int y0_1 = Convert.ToInt32(dgv1.Rows[irn-psa].Cells[pcoln].Value); | |
int px = irn*xdot; | |
int px_1 = (irn - psa)*xdot; | |
int py0 = ph / gline[gsel].baseL - (int)((double)y0 * yscale); | |
int py0_1 = ph / gline[gsel].baseL - (int)((double)y0_1 * yscale); | |
// g1.DrawLine(Pens.Blue, px, py0, px - 1, py0_1); | |
g1.DrawLine(p, px, py0, px_1, py0_1); | |
Color c = samples[gsel]; | |
if (CKarry[gsel].Checked == true) { g1.FillEllipse(b1, px, py0, 5, 5); } | |
// Debug.Print("itow0="+itow0.ToString()+"px=" + px.ToString()+"py0="+py0.ToString()+"px_1="+px_1.ToString()+"py0_1="+py0_1.ToString()); | |
} | |
} | |
} | |
} | |
} | |
private int timeScale() | |
{ | |
int dot=Convert.ToInt32(textBox10.Text); | |
if (dot * dgv1.RowCount >bw) | |
{ | |
dot = (int)(bw / dgv1.RowCount); | |
} | |
return dot; | |
} | |
/* | |
private void plot_srcBitmap(int rNp,int colN) | |
{ | |
int pW = 1000; | |
int pH = 500; | |
int px; | |
int py0, py0_1; | |
int startLX; | |
int vy0, vy1; | |
double yscale = (double)pH / (velMax - velMin); | |
Graphics g1 = Graphics.FromImage(sourceBitmap); | |
px = rNp; | |
py0_1 = pH / 2 - (int)((double)velN_F9P_1 * yscale); | |
py0 = pH / 2 - (int)((double)velN_F9P * yscale); | |
g1.DrawLine(Pens.Blue, px, py0, px - 1, py0_1); | |
} | |
*/ | |
private void plotVel(int rNp, int plot) | |
{ | |
int pW = 1000; | |
int pH =500; | |
int px; | |
int py0, py0_1; | |
int py1, py1_1; | |
int py2, py2_1; | |
int startX; | |
int vy0, vy1; | |
// | |
Graphics g1 = Graphics.FromImage(sourceBitmap); | |
Graphics g2 = Graphics.FromImage(trimmedBitmap); | |
// | |
int velN_F9P = Convert.ToInt32(dgv1.Rows[rNp].Cells[6].Value); | |
int velN_F9P_1 = Convert.ToInt32(dgv1.Rows[rNp - 1].Cells[6].Value); | |
int velN_M9N = Convert.ToInt32(dgv1.Rows[rNp].Cells[13].Value); | |
int velN_M9N_1 = Convert.ToInt32(dgv1.Rows[rNp - 1].Cells[13].Value); | |
int velMax = 10000;//4000mm/sec | |
int velMin = -10000;//-4000mm/sec | |
double yscale = (double)pH / (velMax - velMin); | |
// | |
px = rNp; | |
py0_1 = pH / 2 - (int)((double)velN_F9P_1 * yscale); | |
py1_1 = pH / 2 - (int)((double)velN_M9N_1 * yscale); | |
py0 = pH / 2 - (int)((double)velN_F9P * yscale); | |
py1 = pH / 2 - (int)((double)velN_M9N * yscale); | |
g1.DrawLine(Pens.Blue, px, py0, px - 1, py0_1); | |
g1.DrawLine(Pens.Red, px, py1, px - 1, py1_1); | |
// Debug.Print("rn="+rN.ToString()+"velN_F9P="+velN_F9P.ToString()+"px,py=" + px.ToString() + "," + py0.ToString()); | |
if (plot == 1) | |
{ | |
pictureBox1.Image = sourceBitmap; | |
} | |
rN++; | |
} | |
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e) | |
{ | |
int cx = hScrollBar1.Value; | |
int pW = pictureBox1.Width; | |
textBox3.Text = hScrollBar1.Value.ToString(); | |
sourceCut(cx); | |
int xdot = timeScale(); | |
int rcx =(int)(( cx-pW/2) / xdot); | |
string g0s = (Convert.ToDouble(dgv1.Rows[rcx].Cells[gline[0].colN].Value) / gline[0].uscale).ToString(); | |
string g1s = (Convert.ToDouble(dgv1.Rows[rcx].Cells[gline[1].colN].Value) / gline[1].uscale).ToString(); | |
string g2s = (Convert.ToDouble(dgv1.Rows[rcx].Cells[gline[2].colN].Value) / gline[2].uscale).ToString(); | |
string g3s = (Convert.ToDouble(dgv1.Rows[rcx].Cells[gline[3].colN].Value) / gline[3].uscale).ToString(); | |
string g4s = (Convert.ToDouble(dgv1.Rows[rcx].Cells[gline[4].colN].Value) / gline[4].uscale).ToString(); | |
string g5s = (Convert.ToDouble(dgv1.Rows[rcx].Cells[gline[5].colN].Value) / gline[5].uscale).ToString(); | |
if (gline[0].available == true && cx>pW/2) { textBox4.Text = g0s; } | |
if (gline[1].available == true && cx > pW / 2) { textBox5.Text =g1s; } | |
if (gline[2].available == true && cx > pW / 2) { textBox6.Text = g2s; } | |
if (gline[3].available == true && cx > pW / 2) { textBox7.Text = g3s; } | |
if (gline[4].available == true && cx > pW / 2) { textBox8.Text = g4s; } | |
if (gline[5].available == true && cx > pW / 2) { textBox9.Text = g5s; } | |
//monitor | |
label2.Text = "HscrollValue=cx="+cx.ToString(); | |
label3.Text = "rowN=cx/xdot=" + (cx / xdot).ToString(); | |
label4.Text = "rcx=" + rcx.ToString(); | |
label5.Text = "HscrollMax=" + (hScrollBar1.Maximum).ToString(); | |
} | |
// soukrceBitamapを切り取って | |
private void sourceCut(int cx) | |
{ | |
Graphics g2 = Graphics.FromImage(trimmedBitmap); | |
g2.Clear(Color.Black); | |
int pW = 1000; | |
int startX = 0; | |
if (cx > pW) | |
{ | |
startX = cx - pW; | |
} | |
else | |
{ | |
startX = 0; | |
} | |
Rectangle srcRect = new Rectangle(startX, 0, pW, 500); | |
Rectangle desRect = new Rectangle(0, 0, pW, 500); | |
g2.DrawImage(sourceBitmap, desRect, srcRect, GraphicsUnit.Pixel); | |
//Center Cursor | |
g2.DrawLine(Pens.White, pW / 2, 0, pW / 2, pictureBox1.Height); | |
pictureBox1.Image = trimmedBitmap; | |
} | |
//pictureBox1 Clear | |
private void sourceBitmap_clear() | |
{ | |
Graphics g4 = Graphics.FromImage(sourceBitmap); | |
g4.Clear(Color.Black); | |
pictureBox1.Image = sourceBitmap; | |
} | |
private void label1_Click(object sender, EventArgs e) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment