forked from ArduPilot/MissionPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RAW_Sensor.cs
281 lines (231 loc) · 10.1 KB
/
RAW_Sensor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using AGaugeApp;
using System.IO.Ports;
using System.Threading;
namespace MissionPlanner
{
public partial class RAW_Sensor : Form
{
// for graph
RollingPointPairList list1 = new RollingPointPairList(10 * 50);
RollingPointPairList list2 = new RollingPointPairList(10 * 50);
RollingPointPairList list3 = new RollingPointPairList(10 * 50);
RollingPointPairList list4 = new RollingPointPairList(10 * 50);
RollingPointPairList list5 = new RollingPointPairList(10 * 50);
RollingPointPairList list6 = new RollingPointPairList(10 * 50);
object thisLock = new object();
int tickStart = 0;
public RAW_Sensor()
{
InitializeComponent();
CreateChart(zg1, "Raw Sensors", "Time", "Raw Data");
}
public struct plot
{
public string Name;
public RollingPointPairList PointList;
public Color color;
}
public void CreateChart(ZedGraphControl zgc,string Title, string XAxis, string YAxis)
{
GraphPane myPane = zgc.GraphPane;
// Set the titles and axis labels
myPane.Title.Text = Title;
myPane.XAxis.Title.Text = XAxis;
myPane.YAxis.Title.Text = YAxis;
LineItem myCurve;
myCurve = myPane.AddCurve("Accel X", list1, Color.Red, SymbolType.None);
myCurve = myPane.AddCurve("Accel Y", list2, Color.Green, SymbolType.None);
myCurve = myPane.AddCurve("Accel Z", list3, Color.SandyBrown, SymbolType.None);
myCurve = myPane.AddCurve("Gyro X", list4, Color.Blue, SymbolType.None);
myCurve = myPane.AddCurve("Gyro Y", list5, Color.Black, SymbolType.None);
myCurve = myPane.AddCurve("Gyro Z", list6, Color.Violet, SymbolType.None);
// Show the x axis grid
myPane.XAxis.MajorGrid.IsVisible = true;
myPane.XAxis.Scale.Min = 0;
myPane.XAxis.Scale.Max = 5;
// Make the Y axis scale red
myPane.YAxis.Scale.FontSpec.FontColor = Color.Red;
myPane.YAxis.Title.FontSpec.FontColor = Color.Red;
// turn off the opposite tics so the Y tics don't show up on the Y2 axis
myPane.YAxis.MajorTic.IsOpposite = false;
myPane.YAxis.MinorTic.IsOpposite = false;
// Don't display the Y zero line
myPane.YAxis.MajorGrid.IsZeroLine = true;
// Align the Y axis labels so they are flush to the axis
myPane.YAxis.Scale.Align = AlignP.Inside;
// Manually set the axis range
//myPane.YAxis.Scale.Min = -1;
//myPane.YAxis.Scale.Max = 1;
// Fill the axis background with a gradient
myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f);
// Sample at 20ms intervals
timer1.Interval = 100;
timer1.Enabled = true;
timer1.Start();
// Calculate the Axis Scale Ranges
zgc.AxisChange();
tickStart = Environment.TickCount;
}
private void timer1_Tick(object sender, EventArgs e)
{
double time = (Environment.TickCount - tickStart) / 1000.0;
// Make sure that the curvelist has at least one curve
if (zg1.GraphPane == null || zg1.GraphPane.CurveList.Count <= 0)
return;
// Get the first CurveItem in the graph
LineItem curve = zg1.GraphPane.CurveList[0] as LineItem;
if (curve == null)
return;
// Get the PointPairList
IPointListEdit list = curve.Points as IPointListEdit;
// If this is null, it means the reference at curve.Points does not
// support IPointListEdit, so we won't be able to modify it
if (list == null)
return;
// Time is measured in seconds
//double time = (Environment.TickCount - tickStart) / 1000.0;
// Keep the X scale at a rolling 30 second interval, with one
// major step between the max X value and the end of the axis
Scale xScale = zg1.GraphPane.XAxis.Scale;
if (time > xScale.Max - xScale.MajorStep)
{
xScale.Max = time + xScale.MajorStep;
xScale.Min = xScale.Max - 10.0;
}
// Make sure the Y axis is rescaled to accommodate actual data
try
{
zg1.AxisChange();
}
catch { }
// Force a redraw
zg1.Invalidate();
}
private void timer2serial_Tick(object sender, EventArgs e)
{
if (!MainV2.comPort.BaseStream.IsOpen && !MainV2.comPort.logreadmode)
return;
//Console.WriteLine(DateTime.Now.Millisecond + " timer2 serial");
try
{
MainV2.comPort.MAV.cs.UpdateCurrentSettings(currentStateBindingSource);
}
catch { }
if (sw != null && sw.BaseStream.CanWrite)
{
sw.WriteLine(string.Format("{0},{1},{2},{3},{4},{5},{6}",DateTime.Now.ToString(), MainV2.comPort.MAV.cs.ax, MainV2.comPort.MAV.cs.ay, MainV2.comPort.MAV.cs.az, MainV2.comPort.MAV.cs.gx,MainV2.comPort.MAV.cs.gy, MainV2.comPort.MAV.cs.gz));
}
double time = (Environment.TickCount - tickStart) / 1000.0;
if (chkax.Checked)
{
list1.Add(time, MissionPlanner.MainV2.comPort.MAV.cs.ax);
}
else { list1.Clear(); }
if (chkay.Checked)
{
list2.Add(time, MissionPlanner.MainV2.comPort.MAV.cs.ay);
}
else { list2.Clear(); }
if (chkaz.Checked)
{
list3.Add(time, MissionPlanner.MainV2.comPort.MAV.cs.az);
}
else { list3.Clear(); }
if (chkgx.Checked)
{
list4.Add(time, MissionPlanner.MainV2.comPort.MAV.cs.gx);
}
else { list4.Clear(); }
if (chkgy.Checked)
{
list5.Add(time, MissionPlanner.MainV2.comPort.MAV.cs.gy);
}
else { list5.Clear(); }
if (chkgz.Checked)
{
list6.Add(time, MissionPlanner.MainV2.comPort.MAV.cs.gz);
}
else { list6.Clear(); }
}
private void ACM_Setup_Load(object sender, EventArgs e)
{
timer2serial.Interval = 10;
timer2serial.Enabled = true;
timer2serial.Start();
tabControl.SelectedTab = tabRadio;
tabControl.SelectedTab = tabRawSensor;
//tabControl1_SelectedIndexChanged(sender, e);
}
private void ACM_Setup_FormClosed(object sender, FormClosedEventArgs e)
{
if (MainV2.comPort != null && MainV2.comPort.BaseStream.IsOpen)
{
try
{
if (sw != null)
sw.Close();
}
catch { }
}
timer1.Stop();
timer2serial.Stop();
}
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (!MainV2.comPort.BaseStream.IsOpen && !MainV2.comPort.logreadmode)
{
CustomMessageBox.Show("Please connect first");
this.Close();
}
//comPort.DtrEnable = true;
//comPort.Open();
//comPort.stopall(true); // ensure off
//comPort.requestDatastream((byte)MissionPlanner.MAVLink09.MAV_DATA_STREAM.EXTENDED_STATUS, 0); // mode gps raw
//comPort.requestDatastream((byte)MissionPlanner.MAVLink09.MAV_DATA_STREAM.POSITION, 3); // request location
//comPort.requestDatastream((byte)MissionPlanner.MAVLink09.MAV_DATA_STREAM.EXTRA1, 3); // request attitude
//comPort.requestDatastream((byte)MissionPlanner.MAVLink09.MAV_DATA_STREAM.EXTRA2, 3); // request vfr
MainV2.comPort.requestDatastream(MAVLink.MAV_DATA_STREAM.RAW_SENSORS, MainV2.comPort.MAV.cs.ratesensors); // request raw sensor
//comPort.requestDatastream((byte)MissionPlanner.MAVLink09.MAV_DATA_STREAM.RC_CHANNELS, 3); // request rc info
}
catch
{
CustomMessageBox.Show("Comport open failed");
return;
}
timer1.Start();
}
private void CMB_rawupdaterate_SelectedIndexChanged(object sender, EventArgs e)
{
MainV2.comPort.MAV.cs.ratesensors = (byte)int.Parse(CMB_rawupdaterate.Text);
MainV2.comPort.requestDatastream(MAVLink.MAV_DATA_STREAM.RAW_SENSORS, (byte)int.Parse(CMB_rawupdaterate.Text)); // request raw sensor
}
System.IO.StreamWriter sw = null;
private void BUT_savecsv_Click(object sender, EventArgs e)
{
SaveFileDialog ofd = new SaveFileDialog();
ofd.AddExtension = true;
ofd.DefaultExt = ".csv";
ofd.ShowDialog();
if (ofd.FileName != "")
{
try
{
if (sw != null)
sw.Close();
}
catch { }
sw = new System.IO.StreamWriter(ofd.OpenFile());
}
}
}
}