步进电机的MATLAB仿真程序分享(采用了卡尔曼滤波,对定子电流进行估计,并估算出转子的位置和速度)

news2024/10/7 5:57:27

两相步进电机的连续时间延长卡尔曼滤波器仿真, 根据定子电流的噪声测量,估计定子电流以及转子位置和速度。

主程序:

function MotorKalman

% 两相步进电机的连续时间延长卡尔曼滤波器仿真
% 根据定子电流的噪声测量,估计定子电流以及转子位置和速度

Ra = 1.9; % 绕组电阻
L = 0.003; % 绕组电感
lambda = 0.1; % 电机常数
J = 0.00018; % 转动惯量
B = 0.001; % 粘性摩擦系数

ControlNoise = 0.01; % std dev of uncertainty in control inputs
AccelNoise = 0.5; % std dev of shaft acceleration noise

MeasNoise = 0.1; % standard deviation of measurement noise
R = [MeasNoise^2 0; 0 MeasNoise^2]; % Measurement noise covariance
xdotNoise = [ControlNoise/L ControlNoise/L 0.5 0];
Q = [xdotNoise(1)^2 0 0 0; 0 xdotNoise(2)^2 0 0; 0 0 xdotNoise(3)^2 0; 0 0 0 xdotNoise(4)^2]; % Process noise covariance
P = 1*eye(4); % Initial state estimation covariance

dt = 0.0005; % Integration step size
tf = 1.5; % Simulation length

x = [0; 0; 0; 0]; % Initial state
xhat = x; % State estimate
w = 2 * pi; % Control input frequency

dtPlot = 0.01; % How often to plot results
tPlot = -inf;

% Initialize arrays for plotting at the end of the program
xArray = [];
xhatArray = [];
trPArray = [];
tArray = [];

% Begin simulation loop
for t = 0 : dt : tf
    if t >= tPlot + dtPlot
        % Save data for plotting
        tPlot = t + dtPlot - eps;
        xArray = [xArray x];
        xhatArray = [xhatArray xhat];
        trPArray = [trPArray trace(P)];
        tArray = [tArray t];
    end
    % Nonlinear simulation
    ua0 = sin(w*t);
    ub0 = cos(w*t);
    xdot = [-Ra/L*x(1) + x(3)*lambda/L*sin(x(4)) + ua0/L;
        -Ra/L*x(2) - x(3)*lambda/L*cos(x(4)) + ub0/L;
        -3/2*lambda/J*x(1)*sin(x(4)) + 3/2*lambda/J*x(2)*cos(x(4)) - B/J*x(3);
        x(3)];
    xdot = xdot + [xdotNoise(1)*randn; xdotNoise(2)*randn; xdotNoise(3)*randn; xdotNoise(4)*randn];
    x = x + xdot * dt;
    x(4) = mod(x(4), 2*pi);
    % Kalman filter
    F = [-Ra/L 0 lambda/L*sin(xhat(4)) xhat(3)*lambda/L*cos(xhat(4));
        0 -Ra/L -lambda/L*cos(xhat(4)) xhat(3)*lambda/L*sin(xhat(4));
        -3/2*lambda/J*sin(xhat(4)) 3/2*lambda/J*cos(xhat(4)) -B/J -3/2*lambda/J*(xhat(1)*cos(xhat(4))+xhat(2)*sin(xhat(4)));
        0 0 1 0];
    H = [1 0 0 0; 0 1 0 0];
    z = H * x + [MeasNoise*randn; MeasNoise*randn];
    xhatdot = [-Ra/L*xhat(1) + xhat(3)*lambda/L*sin(xhat(4)) + ua0/L;
        -Ra/L*xhat(2) - xhat(3)*lambda/L*cos(xhat(4)) + ub0/L;
        -3/2*lambda/J*xhat(1)*sin(xhat(4)) + 3/2*lambda/J*xhat(2)*cos(xhat(4)) - B/J*xhat(3);
        xhat(3)];
    xhat = xhat + xhatdot * dt;
    Pdot = F * P + P * F' + Q - P * H' * inv(R) * H * P;
    P = P + Pdot * dt;
    K = P * H' * inv(H * P * H' + R);
    xhat = xhat + K * (z - H * xhat);
    xhat(4) = mod(xhat(4), 2*pi);
end

作图程序:

close all;
figure;
plot(tArray, xArray(1,:), tArray,xhatArray(1,:),'r:')
set(gca,'FontSize',12); set(gcf,'Color','White');
xlabel('Time (Seconds)'); ylabel('Winding A Current (Amps)');
legend('True', 'Estimated');

figure;
plot(tArray, xArray(2,:), tArray,xhatArray(2,:),'r:')
set(gca,'FontSize',12); set(gcf,'Color','White');
xlabel('Time (Seconds)'); ylabel('Winding B Current (Amps)');
legend('True', 'Estimated');

figure;
plot(tArray, xArray(3,:), tArray,xhatArray(3,:),'r:')
set(gca,'FontSize',12); set(gcf,'Color','White');
xlabel('Time (Seconds)'); ylabel('Rotor Speed (Radians / Sec)');
legend('True', 'Estimated');

figure;
plot(tArray, xArray(4,:), tArray,xhatArray(4,:),'r:')
set(gca,'FontSize',12); set(gcf,'Color','White');
xlabel('Time (Seconds)'); ylabel('Rotor Position (Radians)');
legend('True', 'Estimated');

figure;
plot(tArray, trPArray); title('Trace(P)', 'FontSize', 12);
set(gca,'FontSize',12); set(gcf,'Color','White');
xlabel('Seconds');

误差计算程序:

N = size(xArray, 2);
N2 = round(N / 2);
xArray = xArray(:,N2:N);
xhatArray = xhatArray(:,N2:N);
iaEstErr = sqrt(norm(xArray(1,:)-xhatArray(1,:))^2 / size(xArray,2));
ibEstErr = sqrt(norm(xArray(2,:)-xhatArray(2,:))^2 / size(xArray,2));
wEstErr = sqrt(norm(xArray(3,:)-xhatArray(3,:))^2 / size(xArray,2));
thetaEstErr = sqrt(norm(xArray(4,:)-xhatArray(4,:))^2 / size(xArray,2));
disp(['Std Dev of Estimation Errors = ',num2str(iaEstErr),', ',num2str(ibEstErr),', ',num2str(wEstErr),', ',num2str(thetaEstErr)]);

% Display the P version of the estimation error standard deviations
disp(['Sqrt(P) = ',num2str(sqrt(P(1,1))),', ',num2str(sqrt(P(2,2))),', ',num2str(sqrt(P(3,3))),', ',num2str(sqrt(P(4,4)))]);

运行结果:

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/740252.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

为什么InnoDB存储引擎选择使用B+tree索引结构?

🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉欢迎光临🎉🎉🎉🎉🎉&…

CS231W assignment3 RNN

对作业进行一些形象的解释 首先是def rnn_step_forward: 这里的t时刻其实就是一个句子里面的单词数,为了方便会统一到一个最长长度,对于比这个长度短的部分用null进行填充,并且在方法内部会让Null不进行传播和梯度计算。 我们最…

Simpleitk简单应用-python版本

安装: pip install simpletik读取 目前主流的医疗图像格式是nifti格式,相比于dicom格式更加简单和更加容易读取和操作。后缀名为nii或者nii.gz(nii为原格式,gz结尾的是经过压缩格式,因为医疗图像的重复像素特别多,通…

【Hello mysql】 mysql的基本查询(二)

Mysql专栏:Mysql 本篇博客简介:介绍mysql的基本查询 mysql的基本查询(二) 将筛选出来的数据插入到数据库中(insertselect)聚合函数统计班级共有多少同学统计班级手机的qq号有多少统计本次考试去重的数学成绩…

Xcode doesn’t support iPhone’s iOS 15.7.3 (19H307).

Xcode真机调试时,出现了Xcode doesn’t support iPhone’s iOS 15.7.3 (19H307).,Xcode不支持iPhone的版本。升级Xcode太耗时,用了找支持SDK文件方式解决了此问题。下图是本地的SDK支持文件。 从GitHub下载了15.7的设备支持文件&#xff0c…

N-123基于springboot房屋租赁管理系统

开发工具:IDEA,jdk1.8 服务器:tomcat9.0 数据库:mysql5.7 前端:jsp、bootstrap 技术: springbootmybatis-plus 系统主要分前台和后台,分租客、房东、管理员三个角色 系统功能介绍说明&am…

19 动态库和静态库

文章目录 静态库动态库dll模块入口函数 静态库 选择桌面向导里面的静态库 设置为发布版,设置重新生成 创建文件夹放入库和头文件 将库放入工程目录下面 在属性中选择C/C附加包含目录&#xff0c;选择include 属性中链接器选择附加目录将lib选中 #include <stdio.h> #i…

八数码问题-c语言

八数码问题 每个局面是三行三列的数字方阵&#xff0c;每个位置为0-8的一个数码且互不相同&#xff0c;求从初始局面&#xff08;自己设定&#xff09;如何“最快”移动到终止局面&#xff08;自己设定&#xff09;。 移动规则&#xff1a;每次只能0与其上下左右四个方向相邻…

91. 解码方法

91. 解码方法 原题链接&#xff1a;完成情况&#xff1a;解题思路&#xff1a;参考代码&#xff1a; 原题链接&#xff1a; 91. 解码方法 https://leetcode.cn/problems/decode-ways/ 完成情况&#xff1a; 解题思路&#xff1a; 参考代码&#xff1a; package 西湖算法题解…

LLM 与架构新纪元:适应代码生成模式,突破软件开发瓶颈

TL;DR 版本&#xff1a; 今年 2 月&#xff0c;我们在 QCon 上分享了《组织级架构治理的正确落地方式》&#xff0c;其背后的一个核心思想是&#xff1a;架构即代码。围绕这个核心思想&#xff0c;我们构建了 ArchGuard 的治理功能&#xff0c;即架构规范转换为代码。 今年 5 月…

【Qt QML入门】Rectangle

Rectangle是用来在QML窗口上绘制一个可带边框、和可填充的矩形局域。 如效果图&#xff1a; QML代码如下&#xff1a; import QtQuick 2.15 import QtQuick.Window 2.15Window {width: 640height: 480visible: truetitle: qsTr("Hello World")//绘制一个可填充的矩…

开源堡垒机Guacamole二次开发记录之一

简介 项目中需要用到堡垒机功能&#xff0c;调研了一大圈&#xff0c;发现了Apache Guacamole这个开源项目。 Apache Guacamole 是一个无客户端的远程桌面网关&#xff0c;它支持众多标准管理协议&#xff0c;例如 VNC(RFB)&#xff0c;RDP&#xff0c;SSH 等等。该项目是Apa…

LabVIEW-模拟传感器采集数据并预测数据

一、题目 已知某传感器过去的一段时间内采集的数据为d1,d2,d3,......,dn&#xff0c;现欲以m点的数据宽度&#xff0c;预测 tao 步后的数据值&#xff0c;即将一维的时间序列数据重构为如下m1列的形式&#xff1a; d(1) d(2 ) ....... d(m), d(mtao) d(2) d(…

Python第一天学习之Python数据类型

1.数据类型介绍 2.数据转换 money 50 money "giao" print(money)Python会进行自动的转换&#xff0c;但是&#xff0c;运算就错误,在赋值时可以直接转换&#xff0c;但是在计算时无法直接转换。 money 50 money "giao" print(money1)数据类型转换 …

OpenSSL安装使用(四):DES加解密功能测试

OpenSSL是一个开放源代码的安全套接字层密码库&#xff0c;它主要用于互联网安全协议的实现&#xff0c;具有加密&#xff0c;认证和安全访问等功能。OpenSSL由Eric Young和Tim Hudson共同开发&#xff0c;源自SSLeay开放源代码密码库&#xff0c;后来和内容安全管理密码库&…

探索基于VSCode的远程开发插件,进行远程指令和本地指令的运行

需求 最近在研究VSCode的插件的时候&#xff0c;使用了VSCode的远程开发套件&#xff0c;Remote - SSH可以在本地的VSCode上登录远程机器&#xff0c;打开远程机器的某个文件夹进行开发。并且在开发过程中&#xff0c;能够使用几乎所有的VSCode插件。 当你使用这个插件链接到远…

Python(三):Python开发环境搭建

❤️ 专栏简介&#xff1a;本专栏记录了我个人从零开始学习Python编程的过程。在这个专栏中&#xff0c;我将分享我在学习Python的过程中的学习笔记、学习路线以及各个知识点。 ☀️ 专栏适用人群 &#xff1a;本专栏适用于希望学习Python编程的初学者和有一定编程基础的人。无…

mybatis 注解方式操作 sql

前言:注解的方式在某些查询的时候还是比较方便的 mybatis注解配置 mapUnderscoreToCamelCase 配置Select 注解Insert 注解Delete 注解 和 Update 注解Provider 注解 mapUnderscoreToCamelCase 配置 别名设置&#xff0c;mapUnderscoreToCamelCase 配置 配置可以将 带下划线 sq…

python车牌识别

识别结果 蓝牌 绿牌 黄牌 环境 python:3.9\opencv:4.5.1 环境安装 pip3 install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple pip3 install hyperlpr -i https://pypi.tuna.tsinghua.edu.cn/simple 修改 cd /Library/Frameworks/Python.framework/Versi…