自分はロボットをシリアル通信で動かしているのですが、 滑らかに動かすために、時間を経過時間で表したいのですが、どのように表したらよいか教えて頂けますでしょうか。よろしくお願いします。
Afficher commentaires plus anciens
omega = 3.0;
m = 0.5;
P = [];
t0 = 0; %基準時間
t1 = 1;%現在の時間
for t1 = 1 : n
t = (t1 - t0) ; %時刻
theta = a * sin(omega * t); %角度θ
value = ((4095.0/(2.0*pi))*theta)+2048; %指令値
Value = round(value); %指令値valueを切り捨てたValue
str1 = sprintf("%d",Value); %数値を文字列に
writeline(s,str1);
writeline(s,"R");
pause(m)
P=[P; t,theta,Value];
end
1 commentaire
Atsushi Ueno
le 9 Déc 2022
前の質問を踏まえた追加質問です。
Réponses (1)
Atsushi Ueno
le 9 Déc 2022
Modifié(e) : Atsushi Ueno
le 9 Déc 2022
前の質問も踏まえ:posixtime関数でUNIX時間 - Wikipediaを得ています。例えば今日2022年12月9日21時10分なら1670588089になります。小数以下第6位(マイクロ秒単位)まで時刻値が取得されます。
omega = 3.0; m = 0.5; a = 1; P = [];
while true
t = posixtime(datetime); % t = (t1 - t0) ; % 時刻
theta = a * sin(omega * t); %角度θ
value = ((4095.0/(2.0*pi))*theta)+2048; %指令値
Value = round(value); %指令値valueを切り捨てたValue
%% ここは置いときます
% str1 = sprintf("%d",Value); % 数値を文字列に
% writeline(s,str1);
% writeline(s,"R");
%% ここで結果をコマンドウィンドウで確認できます
% fprintf('value = %i\n',value);
pause(m);
P = [P; t,theta,Value]
end
1 commentaire
雷太 鈴木
le 13 Déc 2022
Catégories
En savoir plus sur プログラミング dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!