simulink robot arm trajectory control

2 次查看(过去 30 天)
jone
jone 2014-5-30
评论: jone 2014-6-3
Hi all I am trying to simulate 6dof robot arm with Force/position sensor feedback using matlab/simulink and msc.adams now I need to generate trajectory for robot I am using "matlab function" but I have problem "matlab function" doesn't update output variable until function finished
I tried simple code
function y = fcn(u)
%#codegen
coder.extrinsic('if','pause','min');
y = 1;
pause(1);
y = 2;
paus3(1);
y = 3;
pause(1);
y = 4;
pause(1);
but the y always 4 is there any way to make function update variables value in real time????? or is there other way to generate trajectory and modifying outputs according to force and position values?????
thanks all

回答(1 个)

Ryan Livingston
Ryan Livingston 2014-5-30
On each time step of the simulation, the entirety of the code in your MATLAB Function Block will execute to produce the output y. This is why its value is always 4.
If you need access to the simulation time you can use a Clock Block:
as the input to the MATLAB Function Block. Then, on each time step, the input u will be the value of the current simulation time.
As a suggestion, making if an extrinsic will likely have unexpected consequences so removing that may be best. Similarly, min is supported for code generation so there should be little need to make it an extrinsic function.
  3 个评论
Ryan Livingston
Ryan Livingston 2014-6-2
Hi Jone, you should be able to use the clock block that I referenced in my answer. This will give you access to the simulation time so you can do a computation based upon it. If you need to log the previous state from the prior time step, you could use a persistent variable in the MATLAB Function Block.
jone
jone 2014-6-3
Hi Ryan, thank you again but I am not sure that I got the idea, If that possible could you please give simple example.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Block Libraries 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by