E. Software Implementation of Controlling Algorithm

The following is a snippet of code from the Arduino sketch that controls the apparatus. This snippet illustrates how the system model works.

Here is a discussion of each section:

  • WAIT FOR SAMPLING PERIOD - The discretization model demands that the sampling period be constant and exact. The Metro M4 uses its internal timer to ensure that 800 μs elapses between the start of each feedback loop iteration.
  • GET FEEDBACK - The microcontroller uses its ADC to read the payload displacement from the potentiometer.
  • OBSERVER DYNAMICS - The code is now implementing the discrete-time Kalman filter in these 3 iterative equations. It uses the payload displacement measured during the previous loop iteration to calculate the observer error.
  • CONTROL LAW CALCULATION - The code is now implementing the FSFB control law to calculate the net input force that the solenoids should exert on the payload.
  • DETERMINE FORCE DISTRIBUTION - This code uses the limiting function to calculate the amount of magnetic force each solenoid should exert.
  • PROTECTION AGAINST ERRONEOUS READINGS - This is a limiting function for the displacement. It ensures that the payload position is inside the travel length. When reading the payload position to use in the solenoid current equation, computational delay will create some discrepancy between the measured and actual payload displacement. In order to rectify this, the linearization module will calculate the displacement for the present loop iteration by taking into account the linear observer’s estimated velocity.
  • CALCULATE CORRESPONDING CURRENT PROGRAMMING SIGNALS - Using the payload displacement and calculated force, the code finally calculates the amount of current to supply to each solenoid. There is another limiting function that ensures that the current does not go over 4 A. If the current goes over the maximum value, a new force value must be calculated.
  • OUTPUT THE CONTROL – The controller updates the voltage inputs to the solenoids’ VCCS via the two DAC.

Here is a link to the complete Arduino sketch that enables the Metro M4 to control the motion plant: mgnt_mtn.ino