matlab面向对象设计---类的概念和使用
代码:
classdef MadgwickAHRS < handle
%MADGWICKAHRS Implementation of Madgwick's IMU and AHRS algorithms
%
% For more information see:
% http://www.x-io.co.uk/node/8#open_source_ahrs_and_imu_algorithms
%
% Date Author Notes
% 28/09/2011 SOH Madgwick Initial release %% Public properties
properties (Access = public)
SamplePeriod = 1/256;
Quaternion = [1 0 0 0]; % output quaternion describing the Earth relative to the sensor
Beta = 1; % algorithm gain
end %% Public methods
methods (Access = public)
function obj = MadgwickAHRS(varargin)
for i = 1:2:nargin
if strcmp(varargin{i}, 'SamplePeriod'), obj.SamplePeriod = varargin{i+1};
elseif strcmp(varargin{i}, 'Quaternion'), obj.Quaternion = varargin{i+1};
elseif strcmp(varargin{i}, 'Beta'), obj.Beta = varargin{i+1};
else error('Invalid argument');
end
end;
end
function obj = Update(obj, Gyroscope, Accelerometer, Magnetometer)
q = obj.Quaternion; % short name local variable for readability % Normalise accelerometer measurement
if(norm(Accelerometer) == 0), return; end % handle NaN
Accelerometer = Accelerometer / norm(Accelerometer); % normalise magnitude % Normalise magnetometer measurement
if(norm(Magnetometer) == 0), return; end % handle NaN
Magnetometer = Magnetometer / norm(Magnetometer); % normalise magnitude % Reference direction of Earth's magnetic feild
h = quaternProd(q, quaternProd([0 Magnetometer], quaternConj(q)));
b = [0 norm([h(2) h(3)]) 0 h(4)]; % Gradient decent algorithm corrective step
F = [2*(q(2)*q(4) - q(1)*q(3)) - Accelerometer(1)
2*(q(1)*q(2) + q(3)*q(4)) - Accelerometer(2)
2*(0.5 - q(2)^2 - q(3)^2) - Accelerometer(3)
2*b(2)*(0.5 - q(3)^2 - q(4)^2) + 2*b(4)*(q(2)*q(4) - q(1)*q(3)) - Magnetometer(1)
2*b(2)*(q(2)*q(3) - q(1)*q(4)) + 2*b(4)*(q(1)*q(2) + q(3)*q(4)) - Magnetometer(2)
2*b(2)*(q(1)*q(3) + q(2)*q(4)) + 2*b(4)*(0.5 - q(2)^2 - q(3)^2) - Magnetometer(3)];
J = [-2*q(3), 2*q(4), -2*q(1), 2*q(2)
2*q(2), 2*q(1), 2*q(4), 2*q(3)
0, -4*q(2), -4*q(3), 0
-2*b(4)*q(3), 2*b(4)*q(4), -4*b(2)*q(3)-2*b(4)*q(1), -4*b(2)*q(4)+2*b(4)*q(2)
-2*b(2)*q(4)+2*b(4)*q(2), 2*b(2)*q(3)+2*b(4)*q(1), 2*b(2)*q(2)+2*b(4)*q(4), -2*b(2)*q(1)+2*b(4)*q(3)
2*b(2)*q(3), 2*b(2)*q(4)-4*b(4)*q(2), 2*b(2)*q(1)-4*b(4)*q(3), 2*b(2)*q(2)];
step = (J'*F);
step = step / norm(step); % normalise step magnitude % Compute rate of change of quaternion
qDot = 0.5 * quaternProd(q, [0 Gyroscope(1) Gyroscope(2) Gyroscope(3)]) - obj.Beta * step'; % Integrate to yield quaternion
q = q + qDot * obj.SamplePeriod;
obj.Quaternion = q / norm(q); % normalise quaternion
end
function obj = UpdateIMU(obj, Gyroscope, Accelerometer)
q = obj.Quaternion; % short name local variable for readability % Normalise accelerometer measurement
if(norm(Accelerometer) == 0), return; end % handle NaN
Accelerometer = Accelerometer / norm(Accelerometer); % normalise magnitude % Gradient decent algorithm corrective step
F = [2*(q(2)*q(4) - q(1)*q(3)) - Accelerometer(1)
2*(q(1)*q(2) + q(3)*q(4)) - Accelerometer(2)
2*(0.5 - q(2)^2 - q(3)^2) - Accelerometer(3)];
J = [-2*q(3), 2*q(4), -2*q(1), 2*q(2)
2*q(2), 2*q(1), 2*q(4), 2*q(3)
0, -4*q(2), -4*q(3), 0 ];
step = (J'*F);
step = step / norm(step); % normalise step magnitude % Compute rate of change of quaternion
qDot = 0.5 * quaternProd(q, [0 Gyroscope(1) Gyroscope(2) Gyroscope(3)]) - obj.Beta * step'; % Integrate to yield quaternion
q = q + qDot * obj.SamplePeriod;
obj.Quaternion = q / norm(q); % normalise quaternion
end
end
end
matlab面向对象设计---类的概念和使用的更多相关文章
- day24 Pythonpython 面向对象设计 类
将一些相同特征和动作的成为类,现有类才能创建对象,对象就是特征和动作的结合体 类:把一类事物的相同特征和动作整合到一起就是类.类是一个抽象概念 对象:就是基于类而创建的一个具的事物(具体存在的),也是 ...
- js中的面向对象--类似于类的概念
创建对象的几种常用方式 1.使用Object或对象字面量创建对象 2.工厂模式创建对象 3.构造函数模式创建对象 4.原型模式创建对象 1.使用Object或对象字面量创建对象 使用object va ...
- python函数的面向对象——面向对象设计
通过几个函数式编号演进,理解面向对象设计 def01.py dog1 = { 'name':'元昊', 'gender':'母', 'type':'藏獒' } dog2 = { 'name':'李李' ...
- day24:面向对象设计与面向对象编程、类和对象
一.三大编程范式: 面向过程: 面向函数: 面向对象: 二.程序的进化论: 1.编程最开始就是无组织无结构,从简单控制流中按步写指令 2.从上述的指令中提取重复的代码块或逻辑,组织到一起(比方说,你定 ...
- UML类图与面向对象设计原则
1. 引言 从大一开始学习编程,到如今也已经有两年了.从最初学习的Html,Js,JaveSe,再到JavaEE,Android,自己也能写一些玩具.学习过程中也无意识的了解了一些所谓的设计模 ...
- <九>面向对象分析之UML核心元素之设计类,类,属性,方法,可见性
设计类
- 面向对象:MATLAB的自定义类 [MATLAB]
https://www.cnblogs.com/gentle-min-601/p/9785812.html 面向对象:MATLAB的自定义类 [MATLAB] 这几天刚刚开始学习MATLAB的面向 ...
- C#基础第八天-作业答案-设计类-面向对象方式实现两个帐户之间转账
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- C#基础第八天-作业-设计类-面向对象方式实现两个帐户之间转账
要求1:完成以下两种账户类型的编码.银行的客户分为两大类:储蓄账户(SavingAccount)和信用账户(CreditAccount),两种的账户类型的区别在于:储蓄账户不允许透支,而信用账户可以透 ...
随机推荐
- hdu 1728(搜索)
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- npm-debug.log文件出现原因
项目主目录下总是会出现这个文件,而且不止一个,原因是npm i 的时候,如果报错,就会增加一个此文件来显示报错信息,npm install的时候则不会出现.
- 关于Red5整合springMVC提示scope not found 的错误
https://www.cnblogs.com/qgc88:
- js-className修改class属性
1.修改className 1)修改class类名为p-a-0 2)在保留class="p1"的基础上再添加一个类名为p-a-0 2.删除className 1).结果需删除cla ...
- 2017CCPC 哈尔滨 B
这题没有考虑到m这个东西,所以就没有往二分答案的方向想 二分答案 check的时候,我们找的是大于等于x的数有多少个被加入到那个数组中.如果 >= m说明这个数可能是答案,否则就不是. 用尺取来 ...
- Oracle8i Internal Services
http://d.hatena.ne.jp/yohei-a/20091017/1255791152 第1回 Oracle8i Internal Services 1人読書会 Oracle 読んだところ ...
- Code Sign error: a valid provisioning profile matching the application's Identifier 'com. sensoSource.VoiceRecorder' could not be found
如果不是com. sensoSource.VoiceRecorder,在xxx-info.plist里Bundle identifier里替换成你的证书名 xxx是你的工程名 在Bundle iden ...
- tar命令中的-C作用
一直不知道解压命令如何指定文件夹,今天学到了一个 -C 参数 tar zxvf test.tar.gz -C test 注释:上面的命令将 test.tar.gz 这个压缩包解压到当前目录下的 tes ...
- hdu5384
题意:给你n个母串.m个匹配串,让你求出对于每一个母串 全部匹配串出现的次数和. 思路:完全然全邝斌的模板啊... 凝视掉一行代码就能a... . 代码: #include <algorithm ...
- 记一次CDH修改IP
因机房服务器搬迁,需要修改CDH ip ,集群中有6台服务器. 其中配置了ldap,其中卡在了ldap中的坑太深,所以记录一下. 一.服务器IP等地址修改 1.首先在安装cloudera-manage ...