Skip to content
Snippets Groups Projects
Commit bee97348 authored by Matt Rich's avatar Matt Rich
Browse files

Added a dummy 3d animation block

parent 9f56adf4
No related branches found
No related tags found
No related merge requests found
%**************************************************************************
% Project : Autonomous Helicopter
% Group : 05gr835
% Created : 2005-04-28
% Edited : 2005-05-25
% -------------------------------------------------------------------------
% The non-linear model contains the following files:
%
% thrusten.m : Main rotor thrust equations
% rigid.m : Rigid body equations
% parameters.m : Helicopter parameters
% mrflap.m : Main rotor flapping equations
% force_torque.m : Force and torque equations
% eigenaxis.m : Eigen axis rotation for use in VR toolbox
%**************************************************************************
% eigenaxis.m : This file contains the eigen axis rotation
%algorithm. This file is created by group 05gr830.
function y = eigenaxis(u)
if abs(u(1))< 0.0001
u(1) = 0.0001;
end
if abs(u(2))< 0.0001
u(2) = 0.0001;
end
if abs(u(3))< 0.0001
u(3) = 0.0001;
end
u = [ -u(1); -u(2); u(3) ];% [Pitch, Yaw, Roll]
C11 = cos(u(2))*cos(u(3));
C12 = cos(u(2))*sin(u(3));
C13 = -sin(u(2));
C21 = sin(u(1))*sin(u(2))*cos(u(3))-cos(u(1))*sin(u(3));
C22 = sin(u(1))*sin(u(2))*sin(u(3))+cos(u(1))*cos(u(3));
C23 = sin(u(1))*cos(u(2));
C31 = cos(u(1))*sin(u(2))*cos(u(3))+sin(u(1))*sin(u(3));
C32 = cos(u(1))*sin(u(2))*sin(u(3))-sin(u(1))*cos(u(3));
C33 = cos(u(1))*cos(u(2));
theta = acos(0.5*(C11+C22+C33-1));
e = [C23-C32; C31-C13; C12-C21]/(2*sin(theta));
y = [e; theta];
Copyright (c) 2009, The MathWorks, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution
* Neither the name of the The MathWorks, Inc. nor the names
of its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
This diff is collapsed.
#define S_FUNCTION_LEVEL 2
#define S_FUNCTION_NAME sfun_time
#define TIME_SCALE_FACTOR(S) ssGetSFcnParam(S,0)
/*
* Need to include simstruc.h for the definition of the SimStruct and
* its associated macro definitions.
*/
#include "simstruc.h"
/*
* Include the standard ANSI C header for handling time functions:
* ---------------------------------------------------------------
*/
#include <time.h>
static void mdlInitializeSizes(SimStruct *S)
{
ssSetNumSFcnParams(S, 1); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) return;
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 0)) return;
if (!ssSetNumOutputPorts(S, 0)) return;
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 1);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
ssSetOptions(S, 0);
}
#define MDL_INITIALIZE_SAMPLE_TIMES
static void mdlInitializeSampleTimes(SimStruct *S)
{
ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
}
#define MDL_START
static void mdlStart(SimStruct *S)
{
ssSetRWorkValue(S,0,ssGetTStart(S));
}
static void mdlOutputs(SimStruct *S, int_T tid)
{
real_T t_previousSimTime = ssGetRWorkValue(S,0);
const real_T *scaleFactor = mxGetPr(TIME_SCALE_FACTOR(S));
time_T t_SimTime = ssGetT(S);
real_T t_diff = 0.0;
real_T dt;
real_T t_current;
real_T t_0;
real_T t_previous;
real_T t_elapsed;
/* Desired Delta time */
dt = (t_SimTime - t_previousSimTime) * (scaleFactor[0]);
/* Get clock time at the beginning of this step*/
t_previous = (real_T)clock()/CLOCKS_PER_SEC;
t_0 = (real_T)clock()/CLOCKS_PER_SEC;
/* Wait to reach the desired time */
while (t_diff<dt){
t_current = (real_T) clock()/CLOCKS_PER_SEC;
/* Look for wrapup */
if (t_current<t_previous){
t_elapsed = t_previous - t_0;
t_0 = (real_T) clock()/CLOCKS_PER_SEC - t_elapsed;
}
t_diff = t_current - t_0;
t_previous = t_current;
}
/* Store current time to be used in next time step*/
ssSetRWorkValue(S, 0, t_SimTime);
}
static void mdlTerminate(SimStruct *S)
{
UNUSED_ARG(S); /* unused input argument */
}
/*
* Required S-function trailer:
* ----------------------------
*/
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */
#include "simulink.c" /* MEX-file interface mechanism */
#else
#include "cg_sfun.h" /* Code generation registration function */
#endif
File added
File added
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment