simulink robot arm trajectory control

2 views (last 30 days)
jone
jone on 30 May 2014
Commented: jone on 3 Jun 2014
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

Answers (1)

Ryan Livingston
Ryan Livingston on 30 May 2014
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 Comments
Ryan Livingston
Ryan Livingston on 2 Jun 2014
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 on 3 Jun 2014
Hi Ryan, thank you again but I am not sure that I got the idea, If that possible could you please give simple example.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!