Skip to content

Commit

Permalink
Replay enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmnet committed Jun 25, 2021
1 parent 6728d52 commit 7a6263a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class LineChartWidget extends BorderPane implements IChartControl, IColle

private final static int MAXRECENT = 20;
private final static int REFRESH_RATE = 40;
private final static int REFRESH_SLOT = 20;
private final static int REFRESH_SLOT = 10;

private final static String[] BCKGMODES = { "No mode annotation ", "PX4 Flight Mode","EKF2 Status", "Position Estimation",
"GPS Fixtype", "Offboard Phases", "Vision Subsystem", "EKF2 Height mode" };
Expand Down Expand Up @@ -151,22 +151,21 @@ public class LineChartWidget extends BorderPane implements IChartControl, IColle

private StateProperties state = null;

private IntegerProperty timeFrame = new SimpleIntegerProperty(30);
private FloatProperty scroll = new SimpleFloatProperty(0);
private FloatProperty replay = new SimpleFloatProperty(0);
private BooleanProperty isScrolling = new SimpleBooleanProperty(false);
private final IntegerProperty timeFrame = new SimpleIntegerProperty(30);
private final FloatProperty scroll = new SimpleFloatProperty(0);
private final FloatProperty replay = new SimpleFloatProperty(0);
private final BooleanProperty isScrolling = new SimpleBooleanProperty(false);

private int resolution_ms = 100;

private volatile int current_x_pt = 0;
private int current_x_pt = 0;
private int current_x0_pt = 0;
private int current_x1_pt = 0;

private volatile int current_x0_pt = 0;
private volatile int current_x0_pt_scroll = 0;
private volatile int current_x1_pt = 0;


private AnalysisDataModelMetaData meta = AnalysisDataModelMetaData.getInstance();
private AnalysisModelService dataService = AnalysisModelService.getInstance();
private final AnalysisDataModelMetaData meta = AnalysisDataModelMetaData.getInstance();
private final AnalysisModelService dataService = AnalysisModelService.getInstance();
private final Preferences prefs = MAVPreferences.getInstance();

private ArrayList<KeyFigureMetaData> recent = null;

Expand All @@ -187,29 +186,27 @@ public class LineChartWidget extends BorderPane implements IChartControl, IColle
private final Line measure = new Line();
private final Label time_label = new Label();

private List<IChartSyncControl> syncCharts = null;
private final List<IChartSyncControl> syncCharts;

private XYDataPool pool = null;
private Group chartArea = null;

private Preferences prefs = MAVPreferences.getInstance();

private boolean refreshRequest = false;
private boolean isRunning = false;

private long dashboard_update_tms = 0;
private long last_update_ms = 0;


public LineChartWidget() {

this.state = StateProperties.getInstance();

this.syncCharts = new ArrayList<IChartSyncControl>();
syncCharts.add(this);

refresh_step = REFRESH_RATE / dataService.getCollectorInterval_ms();

FXMLLoadHelper.load(this, "LineChartWidget.fxml");

this.state = StateProperties.getInstance();
this.pool = new XYDataPool();

dataService.registerListener(this);
Expand Down Expand Up @@ -306,20 +303,20 @@ private void initialize() {
measure.setStroke(Color.color(0.9,0.6,1.0,0.5));
chartArea.getChildren().add(measure);

// linechart.setOnScrollStarted((event) -> {
// current_x0_pt_scroll = current_x0_pt;
// });

// linechart.setOnScroll((event) -> {
//
// System.out.println(current_x0_pt_scroll+"/"+event.getTotalDeltaX());
// current_x0_pt = current_x0_pt_scroll + (int)(event.getTotalDeltaX());
// if(current_x0_pt < 0) current_x0_pt = 0;
// updateRequest();
//
// });
// linechart.setOnScrollStarted((event) -> {
// current_x0_pt_scroll = current_x0_pt;
// });


// linechart.setOnScroll((event) -> {
//
// System.out.println(current_x0_pt_scroll+"/"+event.getTotalDeltaX());
// current_x0_pt = current_x0_pt_scroll + (int)(event.getTotalDeltaX());
// if(current_x0_pt < 0) current_x0_pt = 0;
// updateRequest();
//
// });

linechart.setOnMouseExited(mouseEvent -> {
for(IChartSyncControl sync : syncCharts)
sync.setMarker(0,0);
Expand All @@ -328,10 +325,10 @@ private void initialize() {
dashboard2.setVal(0,null,false);
dashboard3.setVal(0,null,false);
});


linechart.setOnMouseMoved(mouseEvent -> {


if((dataService.isCollecting() && !isPaused) || (dataService.isReplaying() && !isPaused) || zoom.isVisible()) {
for(IChartSyncControl sync : syncCharts)
Expand Down Expand Up @@ -465,7 +462,7 @@ private void initialize() {
}
mouseEvent.consume();
});


readRecentList();

Expand Down Expand Up @@ -574,18 +571,24 @@ private void initialize() {
if(isDisabled())
return;
refreshRequest = true;
if(nv.intValue()<=5) {
setXResolution(timeFrame.get());
current_x0_pt = 0;
dataService.setCurrent(0);
Platform.runLater(() -> updateGraph(true, 1) );
if(nv.intValue()<0) {
current_x0_pt = dataService.calculateX0Index(-nv.intValue());
if(current_x0_pt>0)
current_x_pt = dataService.calculateX1Index(-nv.intValue());
else {
current_x_pt = -nv.intValue();
}

dataService.setCurrent(-nv.intValue());
Platform.runLater(() -> updateGraph(true, -nv.intValue()) );
} else {
Platform.runLater(() -> updateGraph(false,nv.intValue()) );
dataService.setCurrent(nv.intValue());
Platform.runLater(() -> updateGraph(false, nv.intValue()) );
dataService.setCurrent(nv.intValue());
}

});


isScrolling.addListener((v, ov, nv) -> {
if(nv.booleanValue())
resolution_ms = resolution_ms < 50 ? 50 : resolution_ms * 2 ;
Expand Down Expand Up @@ -827,7 +830,7 @@ private void addToRecent(KeyFigureMetaData nv) {
}

private void setXResolution(float frame) {

int interval = dataService.getCollectorInterval_ms();

if(frame >= 200) {
Expand Down Expand Up @@ -882,7 +885,7 @@ private void updateRequest() {

private void updateGraph(boolean refresh, int max_x0) {
float dt_sec = 0; AnalysisDataModel m =null; boolean set_bounds = false; double v1 ; double v2; double v3;
int max_x = 0; int size = dataService.getModelList().size(); long slot_tms = 0; int count =0;
int max_x = 0; int size = dataService.getModelList().size(); long slot_tms = 0;

if(isDisabled()) {
return;
Expand All @@ -894,7 +897,6 @@ private void updateGraph(boolean refresh, int max_x0) {
refreshRequest = true; return;
}


linechart.getAnnotations().clearAnnotations(Layer.FOREGROUND);
last_annotation_pos = 0;
yoffset = 0;
Expand Down Expand Up @@ -968,7 +970,7 @@ private void updateGraph(boolean refresh, int max_x0) {

while(current_x_pt<max_x && size>0 && current_x_pt< dataService.getModelList().size() &&
((System.currentTimeMillis()-slot_tms) < REFRESH_SLOT || refreshRequest)) {
count++;


m = dataService.getModelList().get(current_x_pt);
dt_sec = current_x_pt * dataService.getCollectorInterval_ms() / 1000f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public class ChartControlWidget extends ChartControlPane {

private StateProperties state = StateProperties.getInstance();

private float replay_index = 0;
private int replay_index = 0;
private long replay_tms = 0;
private long anim_tms = 0;
private long anim_tms = 0;


private AnimationTimer task;
Expand Down Expand Up @@ -228,25 +228,27 @@ public void handle(MouseEvent click) {
.and(state.getLogLoadedProperty().not())));

task = new AnimationTimer() {
long replay_time_ms;
@Override public void handle(long now) {

if((System.currentTimeMillis() - anim_tms) <33) {
return;
}
anim_tms = System.currentTimeMillis();

if(replay_index < modelService.getModelList().size()) {

long replay_time_ms = System.currentTimeMillis() - replay_tms;
replay_time_ms = System.currentTimeMillis() - replay_tms;

charts.entrySet().forEach((chart) -> {
if(chart.getValue().getReplayProperty()!=null)
chart.getValue().getReplayProperty().set(replay_index);
});
replay_index = replay_time_ms / modelService.getCollectorInterval_ms();
replay_index = (int)(replay_time_ms / modelService.getCollectorInterval_ms());
state.getProgressProperty().set((float)(replay_index) / modelService.getModelList().size() );
scroll.setValue((1f - (float)replay_index/modelService.getModelList().size()));
modelService.setCurrent(replay_time_ms/1000f);

} else {
task.stop();
scroll.setValue(0);
Expand All @@ -259,20 +261,21 @@ public void handle(MouseEvent click) {
};

play.setOnAction((ActionEvent event)-> {
if(!state.getReplayingProperty().get()) {
if(!state.getReplayingProperty().get() && modelService.getModelList().size() > 0) {
state.getReplayingProperty().set(true);
modelService.setReplaying(true);
state.getCurrentUpToDate().set(false);

if(scroll.getValue()<0.05)
scroll.setValue(1);

if(modelService.getModelList().size() > 0) {
charts.entrySet().forEach((chart) -> {
if(chart.getValue().getReplayProperty()!=null)
chart.getValue().getReplayProperty().set(1);
});
}
replay_index = (float)(modelService.getModelList().size() * (1f - (scroll.getValue())));
replay_index = ((int)(modelService.getModelList().size() * (1f - scroll.getValue())))+1;

charts.entrySet().forEach((chart) -> {
if(chart.getValue().getReplayProperty()!=null)
chart.getValue().getReplayProperty().set(-replay_index);
});

replay_tms = System.currentTimeMillis() - (long)(replay_index * modelService.getCollectorInterval_ms());
anim_tms = 0;
task.start();
Expand All @@ -281,7 +284,7 @@ public void handle(MouseEvent click) {
state.getProgressProperty().set(-1);
modelService.setReplaying(false);
state.getReplayingProperty().set(false);
state.getCurrentUpToDate().set(true);
state.getCurrentUpToDate().set(true);
}
event.consume();
});
Expand Down

0 comments on commit 7a6263a

Please sign in to comment.