/// <summary> /// Handle reset animation button click /// </summary> /// <param name="sender">Event object</param> /// <param name="e">Event arguments</param> private void ResetButton_Click(object sender, RoutedEventArgs e) { animationPlaying = false; PlayButton.IsEnabled = true; PauseButton.IsEnabled = false; EnableSystemParameters(true); dispatcherTimer.Stop(); PlotsControl.ResetPlots(); if (trajectoryController.TrajectoryEnabled) { var startPosition = trajectoryController.GetTargetStartPosition(); systemState.Reset(XCoordAngle, YCoordAngle, startPosition.X, startPosition.Y); } else { systemState.Reset(XCoordAngle, YCoordAngle); } SceneControl.ResetSimulation(systemState); foreach (var controller in controllers) { controller.Reset(); } xCoordVoltageController.Reset(systemState.TimeDelta); yCoordVoltageController.Reset(systemState.TimeDelta); UpdateGUI(); }
/// <summary> /// Dispatcher timer cyclic function /// </summary> /// <remarks> /// Method responsible for the whole simulation process. It manages calculations loop. /// </remarks> private void DispatcherTimerTick(object sender, EventArgs e) { // Get info about trajectory bool nextCheckPoint; var targetPosition = trajectoryController.GetTargetPosition(systemState.StateX.Position, systemState.StateY.Position, out nextCheckPoint); if (nextCheckPoint) { xCoordVoltageController.Reset(systemState.TimeDelta); yCoordVoltageController.Reset(systemState.TimeDelta); } // Get info about interferences SceneControl.UpdateWindDirection(windController.UpdateWindForce(), windController.WindPower); // Calculate X-coordinate system double xCoordVoltage = 0.0; var resultXState = ExecuteSystemCalculations(xCoordVoltageController, systemState.StateX, gameController.UserAngleX, targetPosition.X, -windController.GetZCoordWindPower(), -windController.GetXCoordWindPower(), out xCoordVoltage); if (resultXState == null) { return; } systemState.UpdateSystemStateX(resultXState); // Calculate Y-coordinate system double yCoordVoltage = 0.0; var resultYState = ExecuteSystemCalculations(yCoordVoltageController, systemState.StateY, gameController.UserAngleY, targetPosition.Y, -windController.GetZCoordWindPower(), -windController.GetYCoordWindPower(), out yCoordVoltage); if (resultYState == null) { return; } systemState.UpdateSystemStateY(resultYState); // Update plots PlotsControl.PassParameters(TimeDelta, XCoordAngle, YCoordAngle, RodLength, CartMass, PendulumMass, WindPower); PlotsControl.UpdateVoltagePlots(systemState.Time, xCoordVoltage, yCoordVoltage); PlotsControl.UpdateAngleErrorPlots(systemState.Time, systemState.StateX.Angle, systemState.StateY.Angle); PlotsControl.UpdatePositionErrorPlots(systemState.Time, targetPosition.X - systemState.StateX.Position, targetPosition.Y - systemState.StateY.Position); // Update visualization systemState.UpdateTimer(); UpdateGUI(); SceneControl.UpdateFrame(systemState); }