필터 지우기
필터 지우기

Get 1st element/reading from a Real-time encoder readings

조회 수: 1 (최근 30일)
Ahmet
Ahmet 2022년 10월 23일
댓글: Dimitri MANKOV 2022년 10월 24일
I am using an absolute encoder to read my motor in real time through udp on Simulink Real-time, and i would like to save the 1st element from the readings (the position at which the encoder starts at) to use it later on,
I am using the very simple function below, i tried to modify it to include a dynamic array thast stores all values of encoder yet, without success,
Any suggestions?
Thanks in advance!
function y = Encoder_I(Encoder_Readings)
y = Encoder_Readings(1);

채택된 답변

Dimitri MANKOV
Dimitri MANKOV 2022년 10월 24일
편집: Dimitri MANKOV 2022년 10월 24일
Hi Ahmet,
How about using a block-based approach instead? You could for example go for something similar to this:
In this case, I use the simulation time to switch between the new data and the data from the previous step, but you can adjust that condition to your use case.
I hope this is helpful!
Dimitri
  댓글 수: 2
Ahmet
Ahmet 2022년 10월 24일
Hi Dimitri, thank you greatly for you reply, Actually this is how i am reading my absolute encoder, using the same block you provided and i am inputting it as Encoder_Readings to the function, Would you please elaborate more on using simulation time? I just need the first data from the absolute encoder.
Thank you again!
Dimitri MANKOV
Dimitri MANKOV 2022년 10월 24일
Hi Ahmet,
Certainly! When the simulation starts, the clock signal will start incrementing accordingly. If you know when you expect to receive your first UDP Packet, you can compare the clock signal to that value to trigger the condition that will reuse the first packet's data continuously until the end of the simulation.
In the example screenshot above, that time is set to 1ms. Suppose you have a time step of 1ms and you know with certainty that you will receive data during the first time step, this approach could work.
An alternative would be to monitor the data signal output by the "Receive UDP packets" block, and to trigger the same condition as the one shown in the screenshot above by detecting the first change in the data signal.
Dimitri

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Target Computer Setup에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by