// ########################################################################### // // P U B L I C // // ########################################################################### // =========================================================================== /// \brief Constructor // =========================================================================== public FormMain() { // Instantiate the application components pendulumInterface = new PendulumInterface(); pendulum = new Pendulum(pendulumInterface); // Instantiate HMI components ctrlPendulum = new CtrlPendulum(pendulum); ctrlParamDisplay = new CtrlParamDisplay(pendulum); // Designer InitializeComponent( ); // HMI disposal splitMain.Panel2.Controls.Add(ctrlPendulum); splitMain.Panel1.Controls.Add(ctrlParamDisplay); ctrlPendulum.Width = splitMain.Panel2.Width; ctrlPendulum.Height = splitMain.Panel2.Height; ctrlPendulum.Enabled = false; ctrlParamDisplay.Dock = DockStyle.Top; // Linking ctrlLog.StartLoggingEvent += EvLog_StartLogging; ctrlLog.StopLoggingEvent += EvLog_StopLogging; pendulumInterface.ConnectionChangedEvent += EvInterface_ConnectionChanged; ctrlScopes.AttachPendulum(pendulum); UpdateMenuState( ); }
// ########################################################################### // // P R I V A TE // // ########################################################################### #region PRIVATE // =========================================================================== /// \brief Handle pendulum update event /// /// Refresh motor speed // =========================================================================== private void EvPendulum_Update(Pendulum pendulum) { if (pendulum == null) { return; } // Get the speed activate synchronous update rpm = pendulum.StateWheelSpeed * 60.0f / (2.0f * (float)Math.PI); BeginInvoke(dlgtUpdateForm); }
// =========================================================================== /// \brief Constructor /// /// \param pendulum Pendulum to calibrate // =========================================================================== public FormCalibBattery(Pendulum pendulum) { InitializeComponent( ); this.pendulum = pendulum; // Timer for update timer = new Timer( ); timer.Interval = 1000; timer.Tick += EvTimer_Tick; timer.Start( ); }
// ########################################################################### // // P U B L I C // // ########################################################################### #region PUBLIC // =========================================================================== /// \brief Constructor // =========================================================================== public FormMotorManual(Pendulum pendulum) { InitializeComponent( ); // Delegates in order to support asynchronously form update dlgtUpdateForm = new DlgtUpdateForm(UpdateForm); // Initial state torque = 0; enabled = false; brake = false; forward = true; lblTorque.Text = "0 %"; txtRPM.Enabled = true; // Get events from the pendulum pendulum.UpdatedEvent += EvPendulum_Update; this.pendulum = pendulum; }
// ########################################################################### // // P U B L I C // // ########################################################################### #region PUBLIC // =========================================================================== /// \brief Constructor /// /// \param pendulum Pendulum to calibrate // =========================================================================== public FormCalibIMU(Pendulum pendulum) { InitializeComponent( ); this.pendulum = pendulum; // Regsiter to pendulum events pendulum.UpdatedEvent += EvPendulum_Update; // Delegates in order to support asynchronously form update dlgtUpdateControl = new DlgtUpdateControl(UpdateControl); // Reset calibration values pendulum.pendulumInterface.CalibrateIMU(new float [2] { 1f, 1f }, new float [3] { 0f, 0f, 0f }, 0f); step = 1; barProgress.Minimum = 0; barProgress.Maximum = N_SAMPLES; }
// ########################################################################### // // P R I V A T E // // ########################################################################### #region PRIVATE // =========================================================================== /// \brief Pendulum state changed event /// /// Process the new sensor values for the current calibration step // =========================================================================== private void EvPendulum_Update(Pendulum pendulum) { bool r = false; // Nothing to do until the next step if (status == Status.Done) { return; } // Validate the conditions are met to make this calibration step if (step <= 2) { r = CheckStepFaceDown( ); } else { r = CheckStepRightSide( ); } // Not in position ? if (r == false) { timestampRef = pendulum.Timestamp; status = Status.Wait; RestartStep( ); } // Processin ongoing ? else if (status == Status.Busy) { if (step <= 2) { r = ProcessStepFaceDown( ); } else { r = ProcessStepRightSide( ); } if (r == true) { status = Status.Done; // Peform the final calibration at the end of the last step if (step == 4) { Calibrate( ); step = 5; } } } // 1 second stability ? We are ready to process this step else if (pendulum.Timestamp - timestampRef >= 1000) { status = Status.Ready; } // Update the control to reflect changes BeginInvoke(dlgtUpdateControl); }