Encoder position derivative Simulink

6 views (last 30 days)
Marco
Marco on 29 Mar 2017
Edited: Domenico Tuccillo on 27 Nov 2023
Hi, I'm new of simulink and I'm doing some test on a DC motor connected, through a servomechanism, to a disk.The position of the disk is given by an encoder. A block in Simulink gives me out the number of rounds of the disk. How could I derivate this data to obtain velocity? I know the sample time of the encoder; but I do not manage to: -save (online measuraments) the samples, -make a difference between the new sample and the previous one -at the end devide by sample time. What kind of block could I use to save a sample each sample interval? Thank you very much every one.

Answers (2)

Richard Zappulla
Richard Zappulla on 30 Mar 2017
As for saving the data, I would suggest using a "To File" block (under the "Sinks" folder). In the image below, I used a vector concatenate block to form a vector which goes into the "To File" block. You can also use a Mux block as well in this case.
If you use the "To File" block, make sure you have the right "Save Format" selected. You can either save it as an Array (which automatically add the model time as the first row in the data) or a Timeseries object (link to documentation for Time Series Objects )
To differentiate the encoder position to get its velocity, I first assume you are using a fixed-step or discrete model. (If you are not, there are continuous versions of these blocks that you can use). The velocity can be found by modeling the following equation in Simulink:
velocity = (sample(n) - sample(n-1))/Ts
You can perform this a few ways ( Note: items correspond with the picture below):
  1. Write the equation above using basic Simulink blocks (e.g., Add, Unit Delay, Gain).
  2. Use a Discrete Derivative Block (under the "Discrete" folder). The input to this block would be the samples coming from the encoder. The output would be your velocity.
  3. Use a Difference block (from the "Discrete" Folder) followed by a gain block
Hope this helps!

Marco
Marco on 30 Mar 2017
Thanks! this helps a lot! But can I use this values of velocity for a real time control of velocity of the motor? Because I think that in this way I'm introducing a delay that there is not in the real system. Am I wrong?
  1 Comment
Domenico Tuccillo
Domenico Tuccillo on 27 Nov 2023
Edited: Domenico Tuccillo on 27 Nov 2023
Did you find out if it's a problem for a controller?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!