⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit_test.m

📁 四元数表示的
💻 M
字号:
%UNIT_TEST runs unit tests for the Quaternion SIMULINK Library.% $Source: /home/stpierre/cvsroot/matlab/simulink/qlib/test/unit_test.m,v $% $Revision: 1.3 $% $Date: 2001/12/15 01:23:42 $% Copyright (C) 2001 by Jay A. St. Pierre.  All rights reserved.if ~exist('check_value','file')  error(['You do not appear to have the test_tools toolbox installed,', 10,...         'which is necessary to run these unit tests.  You should be', 10,...         'able to get the test_tools toolbox from the same place you', 10,...         'obtained this toolbox.']);endunix('rm -f test.out')diary test.outtest_title = 'Quaternion SIMULINK Library blocks';disp_test_title(test_title);%%% Quaternionq=[1 2 3 4];sim_q=q;%%% Vectorv=[1 2 3];sim_v=v;%%% Run first test modelqtest1sim('qtest1')%%% Check resultsfailures=0;disp_test_name('Quaternion Normalize');truth_value = 'qnorm(sim_q)';test_value  = 'sim_qnorm';failures=failures+check_value(truth_value, test_value);disp_test_name('Quaternion Conjugate');truth_value = 'qconj(sim_q)';test_value  = 'sim_qconj';failures=failures+check_value(truth_value, test_value);disp_test_name('Quaternion Multiply');truth_value = 'qmult(sim_q,sim_q)';test_value  = 'sim_qmult';failures=failures+check_value(truth_value, test_value);disp_test_name('Quaternion Decomposition');[v,phi]=qdecomp(qnorm(sim_q))truth_value = '[v phi]';test_value  = '[sim_vector sim_phi]';failures=failures+check_value(truth_value, test_value);disp_test_name('Quaternion Vector Transform');truth_value = 'qvxform(qnorm(sim_q),sim_v)';test_value  = 'sim_qvxform';failures=failures+check_value(truth_value, test_value);disp_test_name('Quaternion Vector Rotation');truth_value = 'qvrot(qnorm(sim_q),sim_v)';test_value  = 'sim_qvrot';failures=failures+check_value(truth_value, test_value);disp_test_name('Quaternion to DCM');dcm='q2dcm(qnorm(sim_q))',disp(' ')dcm=eval(dcm);truth_value = '[dcm(1,:) dcm(2,:) dcm(3,:)]';test_value  = 'sim_q2dcm';failures=failures+check_value(truth_value, test_value);disp_test_name('DCM to Quaternion');truth_value = 'dcm2q(dcm)';test_value  = 'sim_dcm2q';failures=failures+check_value(truth_value, test_value);%%% Run second test modeldisp_test_name('Quaternion Integration');step_size=0.01, disp(' ')stop_time=10, disp(' ')decimation=100, disp(' ')set_val('t', '0:step_size*decimation:stop_time')set_val('zero_col', 'zeros(length(t), 1)')qtest2sim('qtest2')%%% Check resultsdisp_test_name('Quaternion Integration: X Rotation');truth_value = '[sin(t/2).'' zero_col zero_col cos(t/2).'']';test_value  = 'xrot';failures=failures+check_value(truth_value, test_value, 5e-15);disp_test_name('Quaternion Integration: Y Rotation');truth_value = '[zero_col sin(t/2).'' zero_col cos(t/2).'']';test_value  = 'yrot';failures=failures+check_value(truth_value, test_value, 5e-15);disp_test_name('Quaternion Integration: Z Rotation');truth_value = '[zero_col zero_col sin(t/2).'' cos(t/2).'']';test_value  = 'zrot';failures=failures+check_value(truth_value, test_value, 5e-15);disp_num_failures(test_title, failures)diary off

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -