Example Code

Approximating the angle of a shaft using DIAdem and VBScript

Code and Documents

Attachment

Download All

Overview


This is an example showing how you can use VBScript in DIAdem to implement interpolation and approximate a parameter from an input, specifically the angle of a shaft from a positional sensor.


Description


This example is based upon a rotating shaft which is being measured using a trigger tooth, with the number of times and timestamp of when this trigger passes a sensor being recorded, in this case there is only one trigger per full revolution. From this we can then calculate the approximate angle of the shaft at a certain point in time based upon the time between the triggers.  If you have more than one trigger you can change the variable "NumberofTriggers" in the script to scale the data based on this.

To do this we need two channels, a voltage channel referenced to the number of samples, and a timestamp channel which maps the samples to a specific point in time. Firstly, before any analysis is done, your channel should be thresholded  to give a uniform reference for the script to analyse.

To do this we first detect where all triggers occur in the data channel and place these into a temporary array. We then work out the number of samples and hence the amount of time(using the timestamp channel) between each trigger.

This allows us to work out the differential of angular displacement and from that the approximate value of angle over the set time between two triggers. We then iterate over the entire channel of data which allows us to buid up the approximate angle of the shaft over this timebase. The angle resets to 0 degrees after a full rotation.


Steps to Implement or Execute Code

  1. 1) Load your data channels into DIAdem ready for analysis. (There is some test data attached which allows you to test this)
  2. 2) Threshold the channels as described above.
  3. 3) Change the channel names in the VBScript code to match the names in your data portal.
  4. 4)    Run the script.

Requirements

Software


DIAdem 2012

Hardware

None

James Kent | Applications Engineer | National Instruments UK & Ireland
w: uk.ni.com | ireland.ni.com

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Contributors