Position error of motor shaft

I want to obtain the position error of motor shaft so I subtracted the estimated position from the measured position. modulus function is used so the estimated and the measured positions vary between 0 to 2pi (electrical radians) as shown in the figures attached. the problem is that the error becomes 2pi at instant times. What can I do to not show this big error (2pi) in the figure?

 Accepted Answer

Mathieu NOE
Mathieu NOE on 13 Dec 2022
Moved: Joel Van Sickel on 15 Dec 2022
hello
you can make 2 pi complements on the error signal , following that logic
if error < -pi then error = error + 2pi
if error > pi then error = error - 2pi
goal is to keep error witin -pi / + pi bounds

13 Comments

Thank you for your answer as I conducted all my experiments and saved all data (results) in the workspace as shown in the attached. All position error data is saved as in the figure I sent to you. How can I use the data saved in the workspace to implement your suggestion? In other words, can I use the command window to write a code or algorithm to redraw all position error data by using your idea?
hello
I was meaning that this logic must be implemented directly in your simulink model
where I draw the red rectangle
Hi Mathieu, Thank you for reply. I now that but to do that I need to conduct the experiment again for all results and this will cost me a lot of time. I saved all my results (position errors) as workspace. So the position_error where you draw the red rectangle is saved in the workspace as I showed you in the figure. My question is how can I implement the logic to this saved position error data in the command window to redraw the position error?
ok I understand
my remark was triggered by the fact that you may use error psoition signal in a feedback loop and of course those angle jumps will affect the entire system behaviour
if this error position signal is simply for visualization,why not simply make a matlab script and run it on your already available data ?
What do you mean by matlab script and how can I do it?
can you share the data ? (as mat file)
I got it but I had an error when I tried to plot the position error (Operator '>' is not supported for operands of type 'timeseries') as shown in the attached
convert your timeseries data to a standard numerical array
If M is your time series
V=M.Data
I tried it but it gave me the position error without removing 2pi see attached it seems that the code in the script was not excuted. I sent you the script file and error position data.
yes , I understand
the way you wrote your function is ok if you do it for one sample at a time (like you would implement if in a simulink block)
as we deal here with a long array (record) you have to it differently :
load('matlab_error.mat')
t = pos_error_reg.time;
err = pos_error_reg.Data;
err2 = pos_error(err);
plot(t,err,'b',t,err2,'r')
%%%%%%%%%%%%%%%%%%%%%
function r = pos_error(a)
r = a; % replaces "else" case
% if a > pi % condition 1
id1 = a > pi;
r(id1) = r(id1) -2*pi;
% elseif a < -pi % condition 2
id2 = a < -pi;
r(id2) = r(id2) +2*pi;
end
Thank you very much Mathieu it is working properly.
My pleasure !

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Products

Release

R2021a

Tags

Community Treasure Hunt

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

Start Hunting!