フィルターのクリア

Defining time on Ev3 Robot in matlab

1 回表示 (過去 30 日間)
Julian Høstan Urrea
Julian Høstan Urrea 2018 年 11 月 5 日
回答済み: Sebastian Castro 2018 年 11 月 7 日
Hi
Im using Matlab to make an Lego Ev3 unit, with help of a light sensor,go forward until the light value changes. After the value changes i want the Ev3 to go backwards during 2 sec. Ive managed to make it stop and go back, but im at a loss how to make it go back during this 2 seconds of time before turning and continuing.
this is my code so far:
if Lys (k) > 10
PowerB (k) = 20;
Powerc (k) = 20;
else Lys (k) >1
PowerB (k) = -20;
PowerC (k) = -20;
light values are from my livingroom table.

回答 (1 件)

Sebastian Castro
Sebastian Castro 2018 年 11 月 7 日
If you're using the MATLAB - LEGO interface, then you're not really deploying any code, right? If so, then I would recommend using the tic and toc functions.
Your code would look something like
tic;
while (toc < 2)
% Do stuff
% Optionally, pause if you don't want to spam as fast as possible
pause(0.1)
end
If you have Robotics System Toolbox, you can get more advanced with the sample rates using Robotics.Rate.
r = robotics.Rate(10); % 10 Hz
while (r.TotalElapsedTime < 2)
% Do stuff
waitfor(r);
end
- Sebastian

カテゴリ

Help Center および File ExchangeMATLAB Support Package for LEGO MINDSTORMS EV3 Hardware についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by