自分はロボットをシリ​アル通信で動かしてい​るのですが、 滑らかに動かすために​、時間を経過時間で表​したいのですが、どの​ように表したらよいか​教えて頂けますでしょ​うか。よろしくお願い​します。

3 views (last 30 days)
雷太 鈴木
雷太 鈴木 on 9 Dec 2022
Commented: 雷太 鈴木 on 13 Dec 2022
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 Comment
Atsushi Ueno
Atsushi Ueno on 9 Dec 2022
前の質問を踏まえた追加質問です。

Sign in to comment.

Answers (1)

Atsushi Ueno
Atsushi Ueno on 9 Dec 2022
Edited: Atsushi Ueno on 9 Dec 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
P = 100×3
1.0e+09 * 1.670587637203717 -0.000000000078181 0.000001997000000 1.670587637205053 -0.000000000074185 0.000002000000000 1.670587637205461 -0.000000000072964 0.000002000000000 1.670587637205850 -0.000000000071800 0.000002001000000 1.670587637206386 -0.000000000070196 0.000002002000000 1.670587637207956 -0.000000000065497 0.000002005000000 1.670587637208044 -0.000000000065233 0.000002005000000 1.670587637208089 -0.000000000065098 0.000002006000000 1.670587637208201 -0.000000000064763 0.000002006000000 1.670587637208380 -0.000000000064227 0.000002006000000
  1 Comment
雷太 鈴木
雷太 鈴木 on 13 Dec 2022
ありがとうございます.おかげで実行通り出来ました.

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!