How to include a "time delay" in a simscape custom code [Matlab 2015a]

3 次查看(过去 30 天)
I created a SimScape custom component that implements an externally commanded brake on my rotational degree of freedom. I modified the rotational friction block to respond to an external signal who applies the friction torque instantaneously.
Now, I would like to apply this braking friction gradually within a certain time. In Matlab2017b, I believe that it is fairly straightforward to do with the new events feature. However we are currently locked-up to 2015a, so I am trying to find a way to do something similar.
Anyone has a tip?
In summary, when A becomes active, I want to ramp the friction from 0 to Max in a specified time TAU.
Thanks

采纳的回答

Francois Godin
Francois Godin 2017-11-24
Good day!
I found how to do what I wanted! It was a bit of a stretch, but it seems to works well! For the benefit of the community, here is my solution:
component test
% Delayed Ramp
inputs
A = { 1.0, '1' }; % A:left
end
outputs
B = { 0.0, '1' }; % B:right
end
parameters
Ts = {0.05, 's'}; % delay value
end
variables
x = { 0.0, '1' };
E = { 0.0, '1' };
end
function setup
if Ts <= 0
pm_error('simscape:GreaterThanZero','Time Constant Ts' )
end
end
equations
E == A - delay(A,Ts,History = 0); % change occured in the past Ts sec
if E > 0.5 % A changed from 0 to 1
x.der == 1/Ts;
elseif E < -0.5 % A changed from 1 to 0
x.der == -1/Ts;
else
x.der == 0; % no changes
end
B == x; % When A changes, B will ramp up to A within Ts seconds
end
end

更多回答(1 个)

Francois Godin
Francois Godin 2017-11-9
_Component rotbrake
% Rotational Brake
% The block applies friction in the contact between rotating bodies as a
% specified torque within a certain time delay.
% The friction force is simulated as a function of relative velocity and
% assumed to be the sum of Coulomb, and viscous components.
% Connections R and C are mechanical rotational conserving ports.
% The block positive direction is from port R to port C. This means that if
% port R velocity is greater than that of port C, the block transmits
% torque from port R to port C.
%
% By default, the brake is engaged and requires an external command
% to be de-energised. (based on rotational friction block)
%
% Time delay is not yet implemented
nodes
R = foundation.mechanical.rotational.rotational; % R:left
C = foundation.mechanical.rotational.rotational; % C:right
end
inputs
A = { 1.0, '1' }; % A:left
end
parameters
Col_trq = { 20, 'N*m' }; % Brake friction torque
Ts = {0.002, 's'}; % Brake delay
visc_coef = { 0.001, 'N*m*s/rad' }; % Viscous friction coefficient
vel_thr = { 1e-4, 'rad/s' }; % Linear region velocity threshold
end
parameters (Access=private)
brkwy_trq_th = { 20, 'N*m' }; % Breakaway torque at threshold velocity
end
variables
t_in = { 0, 'N*m' }; % Brake active torque
t_out = { 0, 'N*m' }; % Brake reacting torque
end
function setup
% Parameter range checking
if Col_trq <= 0
pm_error('simscape:GreaterThanZero','Coulomb friction torque' )
end
if visc_coef < 0
pm_error('simscape:GreaterThanOrEqualToZero','Viscous friction coefficient')
end
if vel_thr <= 0
pm_error('simscape:GreaterThanZero','Linear region velocity threshold')
end
if Ts < 0
pm_error('simscape:GreaterThanZero','Brake (de)energizing delay')
end
% Computing breakaway torque at threshold velocity
brkwy_trq_th = visc_coef * vel_thr + Col_trq;
end
branches
t_in : R.t -> *;
t_out : C.t -> *;
end
equations
if (A >= 0.5)
if (abs(R.w) <= vel_thr)
% Linear region
t_in == brkwy_trq_th * R.w / vel_thr;
elseif R.w > 0
t_in == visc_coef * R.w + Col_trq;
else
t_in == visc_coef * R.w - Col_trq;
end
else
t_in == 0;
end
t_out == -t_in;
end
end_
---------- Essentially, what I want is that the friction is not applied instantaneously, but linearly ramped in within a specified deltaT. Col_trq*x where range from 0 to 1 within DT sec.
I have external workarounds for this, but I'd like to figure out a clean way of doing this within the block.

类别

Help CenterFile Exchange 中查找有关 Run-Time Parameters 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by