S curve ramp function
I need help creating a function for an s curve ramp. The code below will create the inserted picture below. However, this code only works for a constant ramp block (connected to x). This code from the piecewise function on the Matlab smf() help file page.
I need two additional inputs (acceleration rate and jerk rate). The output should ramp the input velocity (x) signal based on the acceleration rate (a), and jerk rate (j). I need the block or code to be dynamic. I do not want to put a time value inside of my code. I will be exporting the code to structure text and input the code into a Siemens PLC.
I don’t want to include a fixed dt in my code because I will be running the code in a PLC. Maybe it would be better to design this function in simulink and set a fixed time solver and use integrator blocks?
x = 0:0.01:10; % domain
a = 1; % unsaturated interval’s left endpoint
b = 8; % unsaturated interval’s right endpoint
y = smf(x, a, b);
plot(x, y), grid on
xline(a, ‘–‘)
xline(b, ‘–‘)
title("S-curve piecewise function")
xlabel("x")
ylabel("Amplitude")
ylim([-0.05 1.05])
%% S-curve piecewise function
function y = smf(x, a, b)
m = (a + b)/2;
y = (x > a & x <= m) .* ( 2*((x-a)/(b-a)).^2) + …
(x > m & x <= b) .* (1-2*((x-b)/(b-a)).^2) + …
(x > b);
endI need help creating a function for an s curve ramp. The code below will create the inserted picture below. However, this code only works for a constant ramp block (connected to x). This code from the piecewise function on the Matlab smf() help file page.
I need two additional inputs (acceleration rate and jerk rate). The output should ramp the input velocity (x) signal based on the acceleration rate (a), and jerk rate (j). I need the block or code to be dynamic. I do not want to put a time value inside of my code. I will be exporting the code to structure text and input the code into a Siemens PLC.
I don’t want to include a fixed dt in my code because I will be running the code in a PLC. Maybe it would be better to design this function in simulink and set a fixed time solver and use integrator blocks?
x = 0:0.01:10; % domain
a = 1; % unsaturated interval’s left endpoint
b = 8; % unsaturated interval’s right endpoint
y = smf(x, a, b);
plot(x, y), grid on
xline(a, ‘–‘)
xline(b, ‘–‘)
title("S-curve piecewise function")
xlabel("x")
ylabel("Amplitude")
ylim([-0.05 1.05])
%% S-curve piecewise function
function y = smf(x, a, b)
m = (a + b)/2;
y = (x > a & x <= m) .* ( 2*((x-a)/(b-a)).^2) + …
(x > m & x <= b) .* (1-2*((x-b)/(b-a)).^2) + …
(x > b);
end I need help creating a function for an s curve ramp. The code below will create the inserted picture below. However, this code only works for a constant ramp block (connected to x). This code from the piecewise function on the Matlab smf() help file page.
I need two additional inputs (acceleration rate and jerk rate). The output should ramp the input velocity (x) signal based on the acceleration rate (a), and jerk rate (j). I need the block or code to be dynamic. I do not want to put a time value inside of my code. I will be exporting the code to structure text and input the code into a Siemens PLC.
I don’t want to include a fixed dt in my code because I will be running the code in a PLC. Maybe it would be better to design this function in simulink and set a fixed time solver and use integrator blocks?
x = 0:0.01:10; % domain
a = 1; % unsaturated interval’s left endpoint
b = 8; % unsaturated interval’s right endpoint
y = smf(x, a, b);
plot(x, y), grid on
xline(a, ‘–‘)
xline(b, ‘–‘)
title("S-curve piecewise function")
xlabel("x")
ylabel("Amplitude")
ylim([-0.05 1.05])
%% S-curve piecewise function
function y = smf(x, a, b)
m = (a + b)/2;
y = (x > a & x <= m) .* ( 2*((x-a)/(b-a)).^2) + …
(x > m & x <= b) .* (1-2*((x-b)/(b-a)).^2) + …
(x > b);
end s curve MATLAB Answers — New Questions