現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)