이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Realtime data from motor controller
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello,
I have a question how to plot and show real-time data in App designer, maybe someone can help me, I am beginner in Matlab.
I get my data (e.g. Velocity) easy with webread() in hex and just have to convert into a decimal number, it already works.
But now I don’t know how to write an easy and efficiency program to get actually data e.g. velocity, motor current, torque to show them into two ways in App Designer:
- In an EditField to see the Data like a Display
- In a plot to see data in a graphic and safe
Thanks a lot for any advice to find a good solution :)
채택된 답변
Mario Malic
2020년 12월 31일
Hey Christian,
It would be the best if you'd do few introductory examples in App Designer and you'll get an idea how to do your task.
% 1. Set the property value of the Edit Field component this way
app.EditField.Value = 5
% 2. Once you create axes in your app, use plot function
plot(ax, x, y); % ax is the handle to your axes, example app.UIAxes
댓글 수: 21
Chris
2021년 1월 3일
Hallo, I try it but the plot is not correct working after push the Start-Bottom. Thanks for helping me.
app.stopp = false;
startTime = datetime('now');
while ~app.stopp
t = datetime('now') - startTime;
plot(app.actualVelocityUIAxes,t,hex2dec(webread('2410/10')))
drawnow
pause(1/10);
app.stopp = app.done;
end
Mario Malic
2021년 1월 3일
Hey again,
1) You need to keep the values on your plot for each plot command, that's why you should use hold, or you can do it in App Designer UI manually
2) When plotting a single point, you will not be able to see it unless you set a point marker.
It would be interesting to see if there will be some lag with webread and refreshing the plot.
app.stopp = false;
hold(app.actualVelocityUIAxes, 'on'); % Note 1
startTime = datetime('now');
while ~app.stopp
t = datetime('now') - startTime;
plot(app.actualVelocityUIAxes,t,hex2dec(webread('2410/10')), 'kd') % Note 2
drawnow
pause(1/10);
app.stopp = app.done;
end
Mario Malic
2021년 1월 3일
편집: Mario Malic
2021년 1월 3일
It is going to be a little bit complicated, but doable, don't know if performance will suffer because you'll be redrawing the whole plot for each step. Added code creates a vector that would increase in column size by one for each step. You have to do the same for vector t. Code for plotting remains the same.
velocityData = []; % initialise the variable
app.stopp = false;
% hold(app.actualVelocityUIAxes, 'on'); % no need for this anymore
startTime = datetime('now');
while ~app.stopp
if isempty(velocityData)
velocityData = hex2dec(webread('2410/10'))
else
velocityData(end+1) = hex2dec(webread('2410/10'))
end
% Adjust for the t
t = datetime('now') - startTime;
plot(app.actualVelocityUIAxes,t,hex2dec(webread('2410/10')), '-b');
drawnow
pause(1/10);
app.stopp = app.done;
end
Chris
2021년 1월 3일
Wow thanks, it really nice.
So its working so far. The only thing is without
% hold(app.actualVelocityUIAxes, 'on'); % no need for this anymore
the x-Axes (time) is not moving but with "hold" is doing the job fine.
Also If I used 'b' instead of 'kd' the plot shows nothing?
Thanks so much :)
Mario Malic
2021년 1월 3일
편집: Mario Malic
2021년 1월 3일
I have forgotten to update the line with plot function
plot(app.actualVelocityUIAxes, t, velocityData, '-b');
You haven't updated the code for vector t. Write it in the same way as velocityData. I have left it as a small task for you to do.
You can read more about line and marker properties in documentation for plot function.
'-b' % blue line, note: this doesn't work if you plot a single point
'kd' % d - diamond marker, can't remember what k stands for
Chris
2021년 1월 3일
Super, now it works how I like it. The last thing would be to safe the date. I guess I have too copied the data and safe it in a file? But I am grateful for you help :))))
velocityData = []; % initialise the variable
t = [];
app.stopp = false;
startTime = datetime('now');
while ~app.stopp
if isempty(velocityData)
velocityData = hex2dec(webread('2410/10'));
else
velocityData(end+1) = hex2dec(webread('2410/10'));
end
if isempty(t)
t = datetime('now') - startTime;
else
t(end+1) = datetime('now') - startTime;
end
plot(app.actualVelocityUIAxes, t, velocityData, '-b');
drawnow
pause(1/10);
app.stopp = app.done;
end
Mario Malic
2021년 1월 3일
편집: Mario Malic
2021년 1월 3일
What do you mean by saving the date? Do you want to know when did you do the measurement? You can put it in a title or add text somewhere on the figure. Use datetime for date, make sure you convert it to string and add to title.
You're welcome, if this solved your problem, please accept the answer. Thanks in advance.
Chris
2021년 1월 4일
After I finish the plot I would be good to have an option to safe the data of the plot in a table e.g. in excel or matlab?
Mario Malic
2021년 1월 4일
Chris
2021년 1월 4일
편집: Chris
2021년 1월 4일
Hallo Mario again ;) , I know you help me so much, but I really want to solve one little other problem and it is something with read data from an table.
Its about an velocity profile, that means I just have an table with x=time and y=velocity that means after e.g. for 10s the velocity is going to 50 rpm and than increase to 100 for 20s etc.
So I need to call every value of the array step by step that I can send my controller after the timeframe is finisehed the new value.
time [s] velocity [rpm]
10 50
20 100
10 150
20 200
10 250
.........
Thanks :)
t = readtable("Daten.xlsx","Sheet",2);
x = table2array(t(:,1));
y = table2array(t(:,3));
stairs(app.UIAxes,x,y,'-o');
Chris
2021년 1월 5일
편집: Chris
2021년 1월 5일
Sorry, I will try to explain it better. I would like to send with webwrite() to my controller the new velocity data after the given time is over (like a Profile). My question how I can provide this data from the array e.g. in a loop until the profil is finished?
Incluse: to know how the motor is driving I showed in a plot to know what’s happen Thanks :)
stairs(app.UIAxes,x,y,'-o'); %its just so see how the Motor is driving
Mario Malic
2021년 1월 5일
편집: Mario Malic
2021년 1월 5일
It's specific to the motor controls, how do you control it? You should find that out first, once you do it, you'll be able to approach the coding problem. It is of course done through the while loop, but I think that using webwrite without some meaningful pauses would cause issues.
Chris
2021년 1월 5일
Yes but my pause would be the times from my table. I am sending the new Velocity-Value to the controller only if the time is done.
Yes, I have to integradet in a while loop but how I implent every value in the while loop? e.g. that first I have for 10s a velocity of 50rpm second 50s a veleocity of 100 and so on...
time= [10, 50, 100, 30,......]
veleoctiy = [50, 100,150, 200....]
Mario Malic
2021년 1월 5일
편집: Mario Malic
2021년 1월 5일
Just an idea, you can probably write it similar to this
t = tic
% or use timer
while true % or t<timeEnd
if t<t1
% websave
elseif t>t1 && t<t2
% websave
elseif %
%
eiseif %
%
else
break
end
% pause(0.01); % not sure about this
end
Chris
2021년 1월 6일
I thought I count how many data are in the column and read every loop the new data into pause and webwrite() until the loop is finished (in this case 4 times. But I still struggle with the implementation?
t = readtable("Daten.xlsx","Sheet",2);
time = table2array(t(:,2)); %time in seconds
velo = table2array(t(:,3));
l = length(time); %to know how many loops are necessary
n=1;
while n <= l
pause(% I need every new value from every row in the the column "time")
webwrite(% and every new value from every row in the the column "velocity")
n=n+1;
end
Mario Malic
2021년 1월 20일
Hi Chris,
Related to your mail, I am not sure what did you mean by "velocity measured is always zero and if I increase the velocity the Torque is stacking but the velocity is working in the plot".
Are you reading the values correctly? I created a demo app with random numbers, there are Edit Field components to show the latest value for torque and velocity, so you can check if that's alright in your app.
Another thought: when velocity is zero, signal you get might not be zero, but very low, let's say 1E-3. On plot it will look like it's jumping around, which it actually is but such small number can be neglected.
Chris
2021년 1월 21일
Hello Mario,
super! Thanks for create a demo app. Everything is working well.
"Another thought: when velocity is zero, signal you get might not be zero, but very low, let's say 1E-3. On plot it will look like it's jumping around, which it actually is but such small number can be neglected."
Exactly, that was the key I had in the beginning really high measurement errors sometimes (1E+9): Now I limited the range in the beginning and the plot is working well.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)