From: Bdale Garbee Date: Thu, 11 May 2017 17:16:25 +0000 (-0600) Subject: take local control of what's plotted on graph X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=27bdee2a046703f761910ed9bf741b82e8dceed2;p=fw%2Faltos take local control of what's plotted on graph --- diff --git a/teststand/Makefile.am b/teststand/Makefile.am index 94364ac6..45b88b47 100644 --- a/teststand/Makefile.am +++ b/teststand/Makefile.am @@ -13,13 +13,16 @@ teststanddir=$(datadir)/java teststand_JAVA= \ TestStand.java \ - TestStandStatus.java \ - TestStandStatusUpdate.java \ - TestStandState.java \ TestStandConfig.java \ TestStandConfigUI.java \ - TestStandPreferences.java \ - TestStandGraphUI.java + TestStandDataPoint.java \ + TestStandDataSet.java \ + TestStandGraph.java \ + TestStandGraphUI.java \ + TestStandPreferences.java + TestStandState.java \ + TestStandStatus.java \ + TestStandStatusUpdate.java JFREECHART_CLASS= \ jfreechart.jar diff --git a/teststand/TestStandDataPoint.java b/teststand/TestStandDataPoint.java new file mode 100644 index 00000000..813f6f08 --- /dev/null +++ b/teststand/TestStandDataPoint.java @@ -0,0 +1,250 @@ +/* + * Copyright © 2013 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.altosuilib_11; + +import org.altusmetrum.altoslib_11.*; + +public class TestStandDataPoint implements AltosUIDataPoint { + + AltosState state; + + public static final int data_height = 0; + public static final int data_speed = 1; + public static final int data_accel = 2; + public static final int data_temp = 3; + public static final int data_battery_voltage = 4; + public static final int data_drogue_voltage = 5; + public static final int data_main_voltage = 6; + public static final int data_rssi = 7; + public static final int data_state = 8; + public static final int data_gps_height = 9; + public static final int data_gps_nsat_solution = 10; + public static final int data_gps_nsat_view = 11; + public static final int data_gps_altitude = 12; + public static final int data_temperature = 13; + public static final int data_range = 14; + public static final int data_distance = 15; + public static final int data_pressure = 16; + public static final int data_accel_along = 17; + public static final int data_accel_across = 18; + public static final int data_accel_through = 19; + public static final int data_gyro_roll = 20; + public static final int data_gyro_pitch = 21; + public static final int data_gyro_yaw = 22; + public static final int data_mag_along = 23; + public static final int data_mag_across = 24; + public static final int data_mag_through = 25; + public static final int data_orient = 26; + public static final int data_gps_course = 27; + public static final int data_gps_ground_speed = 28; + public static final int data_gps_climb_rate = 29; + public static final int data_gps_pdop = 30; + public static final int data_gps_hdop = 31; + public static final int data_gps_vdop = 32; + public static final int data_ignitor_0 = 33; + public static final int data_ignitor_num = 32; + public static final int data_ignitor_max = data_ignitor_0 + data_ignitor_num - 1; + public static final int data_ignitor_fired_0 = data_ignitor_0 + data_ignitor_num; + public static final int data_ignitor_fired_max = data_ignitor_fired_0 + data_ignitor_num - 1; + + public double x() throws AltosUIDataMissing { + double time = state.time_since_boost(); + if (time < -2) + throw new AltosUIDataMissing(-1); + return time; + } + + public double y(int index) throws AltosUIDataMissing { + double y = AltosLib.MISSING; + switch (index) { + case data_height: + y = state.height(); + break; + case data_speed: + y = state.speed(); + break; + case data_accel: + y = state.acceleration(); + break; + case data_temp: + y = state.temperature; + break; + case data_battery_voltage: + y = state.battery_voltage; + break; + case data_drogue_voltage: + y = state.apogee_voltage; + break; + case data_main_voltage: + y = state.main_voltage; + break; + case data_rssi: + y = state.rssi; + break; + case data_gps_height: + y = state.gps_height; + break; + case data_gps_nsat_solution: + if (state.gps != null) + y = state.gps.nsat; + break; + case data_gps_nsat_view: + if (state.gps != null) { + if (state.gps.cc_gps_sat != null) + y = state.gps.cc_gps_sat.length; + else + y = 0; + } + break; + case data_gps_altitude: + y = state.gps_altitude(); + break; + case data_temperature: + y = state.temperature; + break; + case data_range: + y = state.range; + break; + case data_distance: + if (state.from_pad != null) + y = state.from_pad.distance; + break; + case data_pressure: + y = state.pressure(); + break; + + case data_accel_along: + y = state.accel_along(); + break; + case data_accel_across: + y = state.accel_across(); + break; + case data_accel_through: + y = state.accel_through(); + break; + case data_gyro_roll: + y = state.gyro_roll(); + break; + case data_gyro_pitch: + y = state.gyro_pitch(); + break; + case data_gyro_yaw: + y = state.gyro_yaw(); + break; + case data_mag_along: + y = state.mag_along(); + break; + case data_mag_across: + y = state.mag_across(); + break; + case data_mag_through: + y = state.mag_through(); + break; + case data_orient: + y = state.orient(); + break; + case data_gps_course: + if (state.gps != null) + y = state.gps.course; + else + y = AltosLib.MISSING; + break; + case data_gps_ground_speed: + if (state.gps != null) + y = state.gps.ground_speed; + else + y = AltosLib.MISSING; + break; + case data_gps_climb_rate: + if (state.gps != null) + y = state.gps.climb_rate; + else + y = AltosLib.MISSING; + break; + case data_gps_pdop: + if (state.gps != null) + y = state.gps.pdop; + else + y = AltosLib.MISSING; + break; + case data_gps_hdop: + if (state.gps != null) + y = state.gps.hdop; + else + y = AltosLib.MISSING; + break; + case data_gps_vdop: + if (state.gps != null) + y = state.gps.vdop; + else + y = AltosLib.MISSING; + break; + default: + if (data_ignitor_0 <= index && index <= data_ignitor_max) { + int ignitor = index - data_ignitor_0; + if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) + y = state.ignitor_voltage[ignitor]; + } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) { + int ignitor = index - data_ignitor_fired_0; + if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) { + if ((state.pyro_fired & (1 << ignitor)) != 0) + y = 1; + else + y = 0; + } + } + break; + } + if (y == AltosLib.MISSING) + throw new AltosUIDataMissing(index); + return y; + } + + public int id(int index) { + if (index == data_state) { + int s = state.state(); + if (AltosLib.ao_flight_boost <= s && s <= AltosLib.ao_flight_landed) + return s; + } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) { + int ignitor = index - data_ignitor_fired_0; + if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) { + if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) { + if ((state.pyro_fired & (1 << ignitor)) != 0) + return 1; + } + } + } + return -1; + } + + public String id_name(int index) { + if (index == data_state) { + return state.state_name(); + } else if (data_ignitor_fired_0 <= index && index <= data_ignitor_fired_max) { + int ignitor = index - data_ignitor_fired_0; + if (state.ignitor_voltage != null && ignitor < state.ignitor_voltage.length) + return AltosLib.ignitor_name(ignitor); + } + return ""; + } + + public TestStandDataPoint (AltosState state) { + this.state = state; + } +} diff --git a/teststand/TestStandGraph.java b/teststand/TestStandGraph.java new file mode 100644 index 00000000..636fd1e2 --- /dev/null +++ b/teststand/TestStandGraph.java @@ -0,0 +1,484 @@ +/* + * Copyright © 2013 Keith Packard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +package org.altusmetrum.altosuilib_11; + +import java.io.*; +import java.util.ArrayList; + +import java.awt.*; +import javax.swing.*; +import org.altusmetrum.altoslib_11.*; + +import org.jfree.ui.*; +import org.jfree.chart.*; +import org.jfree.chart.plot.*; +import org.jfree.chart.axis.*; +import org.jfree.chart.renderer.*; +import org.jfree.chart.renderer.xy.*; +import org.jfree.chart.labels.*; +import org.jfree.data.xy.*; +import org.jfree.data.*; + +class AltosVoltage extends AltosUnits { + + public double value(double v, boolean imperial_units) { + return v; + } + + public double inverse(double v, boolean imperial_units) { + return v; + } + + public String show_units(boolean imperial_units) { + return "V"; + } + + public String say_units(boolean imperial_units) { + return "volts"; + } + + public int show_fraction(int width, boolean imperial_units) { + return width / 2; + } +} + +class AltosNsat extends AltosUnits { + + public double value(double v, boolean imperial_units) { + return v; + } + + public double inverse(double v, boolean imperial_units) { + return v; + } + + public String show_units(boolean imperial_units) { + return "Sats"; + } + + public String say_units(boolean imperial_units) { + return "Satellites"; + } + + public int show_fraction(int width, boolean imperial_units) { + return 0; + } +} + +class AltosPressure extends AltosUnits { + + public double value(double p, boolean imperial_units) { + return p; + } + + public double inverse(double p, boolean imperial_units) { + return p; + } + + public String show_units(boolean imperial_units) { + return "Pa"; + } + + public String say_units(boolean imperial_units) { + return "pascals"; + } + + public int show_fraction(int width, boolean imperial_units) { + return 0; + } +} + +class AltosDbm extends AltosUnits { + + public double value(double d, boolean imperial_units) { + return d; + } + + public double inverse(double d, boolean imperial_units) { + return d; + } + + public String show_units(boolean imperial_units) { + return "dBm"; + } + + public String say_units(boolean imperial_units) { + return "D B M"; + } + + public int show_fraction(int width, boolean imperial_units) { + return 0; + } +} + +class AltosGyroUnits extends AltosUnits { + + public double value(double p, boolean imperial_units) { + return p; + } + + public double inverse(double p, boolean imperial_units) { + return p; + } + + public String show_units(boolean imperial_units) { + return "°/sec"; + } + + public String say_units(boolean imperial_units) { + return "degrees per second"; + } + + public int show_fraction(int width, boolean imperial_units) { + return 1; + } +} + +class AltosMagUnits extends AltosUnits { + + public double value(double p, boolean imperial_units) { + return p; + } + + public double inverse(double p, boolean imperial_units) { + return p; + } + + public String show_units(boolean imperial_units) { + return "Ga"; + } + + public String say_units(boolean imperial_units) { + return "gauss"; + } + + public int show_fraction(int width, boolean imperial_units) { + return 2; + } +} + +class AltosDopUnits extends AltosUnits { + + public double value(double p, boolean imperial_units) { + return p; + } + + public double inverse(double p, boolean imperial_units) { + return p; + } + + public String show_units(boolean imperial_units) { + return null; + } + + public String say_units(boolean imperial_units) { + return null; + } + + public int show_fraction(int width, boolean imperial_units) { + return 1; + } +} + +public class TestStandGraph extends AltosUIGraph { + + static final private Color height_color = new Color(194,31,31); + static final private Color gps_height_color = new Color(150,31,31); + static final private Color pressure_color = new Color (225,31,31); + static final private Color range_color = new Color(100, 31, 31); + static final private Color distance_color = new Color(100, 31, 194); + static final private Color speed_color = new Color(31,194,31); + static final private Color accel_color = new Color(31,31,194); + static final private Color voltage_color = new Color(194, 194, 31); + static final private Color battery_voltage_color = new Color(194, 194, 31); + static final private Color drogue_voltage_color = new Color(150, 150, 31); + static final private Color main_voltage_color = new Color(100, 100, 31); + static final private Color gps_nsat_color = new Color (194, 31, 194); + static final private Color gps_nsat_solution_color = new Color (194, 31, 194); + static final private Color gps_nsat_view_color = new Color (150, 31, 150); + static final private Color gps_course_color = new Color (100, 31, 112); + static final private Color gps_ground_speed_color = new Color (31, 112, 100); + static final private Color gps_climb_rate_color = new Color (31, 31, 112); + static final private Color gps_pdop_color = new Color(50, 194, 0); + static final private Color gps_hdop_color = new Color(50, 0, 194); + static final private Color gps_vdop_color = new Color(194, 0, 50); + static final private Color temperature_color = new Color (31, 194, 194); + static final private Color dbm_color = new Color(31, 100, 100); + static final private Color state_color = new Color(0,0,0); + static final private Color accel_x_color = new Color(255, 0, 0); + static final private Color accel_y_color = new Color(0, 255, 0); + static final private Color accel_z_color = new Color(0, 0, 255); + static final private Color gyro_x_color = new Color(192, 0, 0); + static final private Color gyro_y_color = new Color(0, 192, 0); + static final private Color gyro_z_color = new Color(0, 0, 192); + static final private Color mag_x_color = new Color(128, 0, 0); + static final private Color mag_y_color = new Color(0, 128, 0); + static final private Color mag_z_color = new Color(0, 0, 128); + static final private Color orient_color = new Color(31, 31, 31); + + static AltosVoltage voltage_units = new AltosVoltage(); + static AltosPressure pressure_units = new AltosPressure(); + static AltosNsat nsat_units = new AltosNsat(); + static AltosDbm dbm_units = new AltosDbm(); + static AltosGyroUnits gyro_units = new AltosGyroUnits(); + static AltosOrient orient_units = new AltosOrient(); + static AltosMagUnits mag_units = new AltosMagUnits(); + static AltosDopUnits dop_units = new AltosDopUnits(); + + AltosUIAxis height_axis, speed_axis, accel_axis, voltage_axis, temperature_axis, nsat_axis, dbm_axis; + AltosUIAxis distance_axis, pressure_axis; + AltosUIAxis gyro_axis, orient_axis, mag_axis; + AltosUIAxis course_axis, dop_axis; + + public TestStandGraph(AltosUIEnable enable, AltosFlightStats stats, TestStandDataSet dataSet) { + super(enable); + + pressure_axis = newAxis("Pressure", pressure_units, pressure_color, 0); + accel_axis = newAxis("Acceleration", AltosConvert.accel, accel_color); + voltage_axis = newAxis("Voltage", voltage_units, voltage_color); + temperature_axis = newAxis("Temperature", AltosConvert.temperature, temperature_color, 0); + nsat_axis = newAxis("Satellites", nsat_units, gps_nsat_color, + AltosUIAxis.axis_include_zero | AltosUIAxis.axis_integer); + dbm_axis = newAxis("Signal Strength", dbm_units, dbm_color, 0); + distance_axis = newAxis("Distance", AltosConvert.distance, range_color); + + gyro_axis = newAxis("Rotation Rate", gyro_units, gyro_z_color, 0); + orient_axis = newAxis("Tilt Angle", orient_units, orient_color, 0); + mag_axis = newAxis("Magnetic Field", mag_units, mag_x_color, 0); + course_axis = newAxis("Course", orient_units, gps_course_color, 0); + dop_axis = newAxis("Dilution of Precision", dop_units, gps_pdop_color, 0); + + addMarker("State", TestStandDataPoint.data_state, state_color); + + if (stats.has_flight_data) { + addSeries("Pressure", + TestStandDataPoint.data_pressure, + pressure_units, + pressure_color, + true, + pressure_axis); + addSeries("Acceleration", + TestStandDataPoint.data_accel, + AltosConvert.accel, + accel_color, + true, + accel_axis); + } + if (stats.has_gps) { + boolean enable_gps = false; + + if (!stats.has_flight_data) + enable_gps = true; + + addSeries("Range", + TestStandDataPoint.data_range, + AltosConvert.distance, + range_color, + false, + distance_axis); + addSeries("Distance", + TestStandDataPoint.data_distance, + AltosConvert.distance, + distance_color, + enable_gps, + distance_axis); + addSeries("GPS Height", + TestStandDataPoint.data_gps_height, + AltosConvert.height, + gps_height_color, + enable_gps, + height_axis); + addSeries("GPS Altitude", + TestStandDataPoint.data_gps_altitude, + AltosConvert.height, + gps_height_color, + false, + height_axis); + addSeries("GPS Satellites in Solution", + TestStandDataPoint.data_gps_nsat_solution, + nsat_units, + gps_nsat_solution_color, + false, + nsat_axis); + if (stats.has_gps_sats) { + addSeries("GPS Satellites in View", + TestStandDataPoint.data_gps_nsat_view, + nsat_units, + gps_nsat_view_color, + false, + nsat_axis); + } + if (stats.has_gps_detail) { + addSeries("GPS Course", + TestStandDataPoint.data_gps_course, + orient_units, + gps_course_color, + false, + course_axis); + addSeries("GPS Ground Speed", + TestStandDataPoint.data_gps_ground_speed, + AltosConvert.speed, + gps_ground_speed_color, + enable_gps, + speed_axis); + addSeries("GPS Climb Rate", + TestStandDataPoint.data_gps_climb_rate, + AltosConvert.speed, + gps_climb_rate_color, + enable_gps, + speed_axis); + } + addSeries("GPS Position DOP", + TestStandDataPoint.data_gps_pdop, + dop_units, + gps_pdop_color, + false, + dop_axis); + if (stats.has_gps_detail) { + addSeries("GPS Horizontal DOP", + TestStandDataPoint.data_gps_hdop, + dop_units, + gps_hdop_color, + false, + dop_axis); + addSeries("GPS Vertical DOP", + TestStandDataPoint.data_gps_vdop, + dop_units, + gps_vdop_color, + false, + dop_axis); + } + } + if (stats.has_rssi) + addSeries("Received Signal Strength", + TestStandDataPoint.data_rssi, + dbm_units, + dbm_color, + false, + dbm_axis); + + if (stats.has_battery) + addSeries("Battery Voltage", + TestStandDataPoint.data_battery_voltage, + voltage_units, + battery_voltage_color, + false, + voltage_axis); + + if (stats.has_flight_adc) { + addSeries("Temperature", + TestStandDataPoint.data_temperature, + AltosConvert.temperature, + temperature_color, + false, + temperature_axis); + addSeries("Drogue Voltage", + TestStandDataPoint.data_drogue_voltage, + voltage_units, + drogue_voltage_color, + false, + voltage_axis); + addSeries("Main Voltage", + TestStandDataPoint.data_main_voltage, + voltage_units, + main_voltage_color, + false, + voltage_axis); + } + + if (stats.has_imu) { + addSeries("Acceleration Along", + TestStandDataPoint.data_accel_along, + AltosConvert.accel, + accel_x_color, + false, + accel_axis); + addSeries("Acceleration Across", + TestStandDataPoint.data_accel_across, + AltosConvert.accel, + accel_y_color, + false, + accel_axis); + addSeries("Acceleration Through", + TestStandDataPoint.data_accel_through, + AltosConvert.accel, + accel_z_color, + false, + accel_axis); + addSeries("Roll Rate", + TestStandDataPoint.data_gyro_roll, + gyro_units, + gyro_x_color, + false, + gyro_axis); + addSeries("Pitch Rate", + TestStandDataPoint.data_gyro_pitch, + gyro_units, + gyro_y_color, + false, + gyro_axis); + addSeries("Yaw Rate", + TestStandDataPoint.data_gyro_yaw, + gyro_units, + gyro_z_color, + false, + gyro_axis); + } + if (stats.has_mag) { + addSeries("Magnetometer Along", + TestStandDataPoint.data_mag_along, + mag_units, + mag_x_color, + false, + mag_axis); + addSeries("Magnetometer Across", + TestStandDataPoint.data_mag_across, + mag_units, + mag_y_color, + false, + mag_axis); + addSeries("Magnetometer Through", + TestStandDataPoint.data_mag_through, + mag_units, + mag_z_color, + false, + mag_axis); + } + if (stats.has_orient) + addSeries("Tilt Angle", + TestStandDataPoint.data_orient, + orient_units, + orient_color, + false, + orient_axis); + if (stats.num_ignitor > 0) { + for (int i = 0; i < stats.num_ignitor; i++) + addSeries(AltosLib.ignitor_name(i), + TestStandDataPoint.data_ignitor_0 + i, + voltage_units, + main_voltage_color, + false, + voltage_axis); + for (int i = 0; i < stats.num_ignitor; i++) + addMarker(AltosLib.ignitor_name(i), TestStandDataPoint.data_ignitor_fired_0 + i, state_color); + } + + setDataSet(dataSet); + } +} diff --git a/teststand/TestStandGraphUI.java b/teststand/TestStandGraphUI.java index b6d88f82..0558a872 100644 --- a/teststand/TestStandGraphUI.java +++ b/teststand/TestStandGraphUI.java @@ -37,11 +37,11 @@ import org.jfree.ui.RefineryUtilities; public class TestStandGraphUI extends AltosUIFrame { JTabbedPane pane; - AltosGraph graph; + TestStandGraph graph; AltosUIEnable enable; AltosState state; AltosFlightStats stats; - AltosGraphDataSet graphDataSet; + TestStandDataSet graphDataSet; AltosFlightStatsTable statsTable; private void close() { @@ -58,8 +58,8 @@ public class TestStandGraphUI extends AltosUIFrame enable = new AltosUIEnable(); stats = new AltosFlightStats(states); - graphDataSet = new AltosGraphDataSet(states); - graph = new AltosGraph(enable, stats, graphDataSet); + graphDataSet = new TestStandDataSet(states); + graph = new TestStandGraph(enable, stats, graphDataSet); statsTable = new AltosFlightStatsTable(stats); pane.add("Graph", graph.panel);