On Sliding Mode Control of Spacecrafts for sEnglish Agents

S. M. Veres and N. K. Lincoln
University of Southampton, UK, Email: s.m.veres@soton.ac.uk

2008/10/10

sEnglish for Scientist, Engineers and Agents

This document is understandable by any agent produced by the Cognitive Agents Toolbox (http://www.cognitive-agents-toolbox.com) and by any sEnglish Agent (http://www.system-english.com).


This paper is an HTML document that can be read and understood by any sEnglish Agent (available from system-english.com) that has the ability to interpret English sentences. Paragraphs in italics, such as this, are informal English inserted by the human author of this document to enhance understanding by human readers. All non-italics text, including titles of sections, are read by the agent, this is not an annotated document with hidden markers of meanings.


CONTENTS

1. Conceptual structures used

2. Sliding mode control

Application of sliding mode control

3. Demo of SMC

Demonstration of sliding mode control of spacecraft
Imagining of spacecraft movements
Spacecraft state change

4. Simple actions

Computation of attitude error
Computation of control torque and force
Computation of dynamical state derivative
Computation of errors to guidance
Computation of gradients to guidance potentials
Computation of position error
Computation of special dynamical force matrix
Definition of joint sliding surface
Definition of sliding surface weights
Forgetting the past
Initializing dynamical guidance state

5. Inputs & Displays

Display of imagined movements
Getting the desired dynamical state
Getting the spacecraft data

6. Appendix

Computation of inverse matrix
Computation of smoothed sign function
Concatenation of vectors
Definition of class
Definition of global variables
Definition of object by property value
Definition of property as given object
Initializing matrix
Truth value of strings are equal


Conceptual structures used in this paper

This section first outlines the main concepts and objects used, then the basic data object constraints and finally the attributes of concepts and objects that make up the substance of their meaning.

The main concept and their relationships

The main concepts are : algebraic equation, algebraic function, algebraic term, attitude error, desired attitude, desired dynamical state, desired position, numerical function, position error, set, spacecaft movements, spacecraft movements, variable . These do not have any sup classes, they represent root concepts.

The concepts that are subclasses of larger complex classes

An kernel is a special case of m-function and numerical function.

The special cases of the most significant concept classes

Attributes of an algebraic definition

An 'algebraic definition' has the following properties: its 'defined variable' that is a variable, its 'left hand side' that is an algebraic term, its 'right hand side' that is an algebraic term and its 'unkowns' that is a set of variables.

Attributes of an algebraic equation

An 'algebraic equation' has the following properties: its 'left hand side' that is an algebraic term, its 'right hand side' that is an algebraic term and its 'unkowns' that is a set of variables.

Attributes of an algebraic function

An 'algebraic function' has the following properties: its 'input variables' that is a set of char and its 'formula' that is a text.

Attributes of an algebraic term

An 'algebraic term' has the following properties: its 'member variables' that is a set of char, its 'formula' that is a text and its 'reduced form' that is a text.

Attributes of an attitude error

An 'attitude error' has the following properties: its 'dimension' that can be one of a \{'euler angles', 'quaternion'\}, its 'values' that is a vector and its 'reference frame' that is a text.

Attributes of a desired attitude

A 'desired attitude' has the following properties: its 'dimension' that can be one of a \{'euler angles', 'quaternion'\}, its 'values' that is a vector and its 'reference frame' that is a text.

Attributes of a desired dynamical state

A 'desired dynamical state' has the following properties: its 'dimensions' that is a set of char, its 'values' that is a vector, its 'reference frame' that is a text and its 'time horizon' that is a number array.

Attributes of a desired position

A 'desired position' has the following properties: its 'dimension' that can be one of a \{'km','m','mm'\}, its 'values' that is a vector and its 'reference frame' that is a text.

Attributes of a kernel

A 'kernel' has the following properties: its 'file name' that is a text, its 'input variables' that is a set of char, its 'output variables' that is a set of char and its 'name' that is a text.

Attributes of an m-function

An 'm-function' has the following properties: its 'file name' that is a text, its 'input variables' that is a set of char, its 'output variables' that is a set of char and its 'name' that is a text.

Attributes of a matrix variable

A 'matrix variable' has the following properties: its 'notation' that is a text, its 'assigment' that is a text and its 'domain' that is a set.

Attributes of a numerical function

A 'numerical function' has the following properties: its 'name' that is a text.

Attributes of a position error

A 'position error' has the following properties: its 'dimension' that can be one of a \{'km','m','mm'\}, its 'values' that is a vector and its 'reference frame' that is a text.

Attributes of an scalar complex variable

An 'scalar complex variable' has the following properties: its 'notation' that is a text, its 'assigment' that is a text and its 'domain' that is a set.

Attributes of an scalar real variable

An 'scalar real variable' has the following properties: its 'notation' that is a text, its 'assigment' that is a text and its 'domain' that is a set.

Attributes of a set

A 'set' has the following properties: its 'members' that is a text and its 'members list' that is a cell array.

Attributes of an spacecaft movements

An 'spacecaft movements' has the following properties: its 'craft name' that is a text, its 'data' that is a number array, its 'data labels' that is a set of char, its 'time dimension' that can be one of a \{'s','h','ms'\} and its 'data dimensions' that is a set of char.

Attributes of an spacecraft movements

An 'spacecraft movements' has the following properties: its 'time axis' that is a number array, its 'rotations' that is a set of quaternions and its 'translation' that is a set of vectors.

Attributes of a variable

A 'variable' has the following properties: its 'notation' that is a text, its 'assigment' that is a text and its 'domain' that is a set.

Attributes of a vector variable

A 'vector variable' has the following properties: its 'notation' that is a text, its 'assigment' that is a text and its 'domain' that is a set.


Sliding mode control

Application of sliding mode control

This SMC algorithm was developed by N K Lincoln & S M Veres, April 2008.

Sentences to use: Use 'smc01-control' to obtain control torque T and control force U for spacecraft Spc01 from dynamical state X and guidance reference Xnow and Diffdot .

Available things are: U_( quote) , Xnow( guidance reference) , Spc01( spacecraft) , X( dynamical state) , Diffdot( *) ,

Details of the meaning: If U_ is 'smc01-control', then do the following. Define surface weights Alpha as "[0.5, 0.5]". Initialise matrix Phi as a 'unit matrix'. Define J as the 'inertia matrix' of Spc01. Compute matrix J2 as the inverse of J . Compute position velocity error Ve and angular velocity error Oe from dynamical state X, guidance reference Xnow . Define the joint sliding surface G2 from the position velocity error Ve and angular velocity error Oe using the surface weights Alpha. Compute the smoothed sign function SG2 from the joint sliding surface G2 with sign threshold 0.01. Compute special dynamical force F from dynamical state X and surface weights Alpha. Execute "Diffdot=zeros(6,1);". Compute control torque T and control force U from matrix J2, surface weights Alpha, special dynamical force F , smoothed sign function SG2 and Diffdot. Finish conditional actions.

Resulting things are: T(control torque) , U(control force) .


Demo of SMC

Demonstration of sliding mode control of spacecraft

sEnglish sentences explaining how the complex demonstration is done including simulation.

Sentences to use: Demonstrate sliding mode control .

Details of the meaning: Get data for spacecraft Sc01 by 'human input'. Get desired dynamical state Xd of Sc01. Define dynamical state X0 as 'current dynamical state' of Sc01. Imagine spacecraft movements XX of spacecraft Sc01 for initial dynamical state X0 and desired dynamical state Xd. Display spacecraft movements XX in 'graphs of variables'.

Imagining of spacecraft movements

Imagine is actually simulation if a human observes it. For an agent it is indeed a computation to predict, imagine what will happen. When the simulation is displayed in animation, using the geometric data stored in the spacecraft object, the analogy is even more obvious to human imagination.

Sentences to use: Imagine spacecraft movements XX of spacecraft Spc01 for initial dynamical state X0 and desired dynamical state Xd .

Available things are: Spc01( spacecraft) , X0( dynamical state) , Xd( desired dynamical state) ,

Details of the meaning: Execute "global Xdes;global Sc01;global Diffdot; Xdes=Xd;Sc01=Spc01". Define X0 as the 'current dynamical state' of Sc01. Define Tspan as the 'time horizon' of Xdes. Execute "Options=odeset('RelTol',1e-6,'AbsTol',1e-8,'InitialStep',0.025);Diffdot=zeros(6,1); [t,X]=ode11_Euler('spacecraft_state_change',Tspan,X0,Options,[]); XX.data_labels={'x','y','z','vx','vy','vz', 'q1','q2','q3','q0','ox','oy','oz'}; XX.time_dimension=t;XX.data=X;".

Resulting things are: XX(spacecraft movements) .

Spacecraft state change

Description of complex operations of spacecraft simulation in terms sEnglish sentences.

Sentences to use: Compute dynamical state derivative Xdot for Time , from dynamical state X with numerical Options and Flag .

Available things are: Time( scalar) , X( dynamical state) , Options( vector) , Flag( vector) ,

Details of the meaning: Execute "global Xdes; global Sc01;global Diffdot". Compute position error Xe from desired position Xdes and dynamical state X. Compute attitude error Qe from desired position Xdes and dynamical state X . Compute guidance omega gradient Vom and guidance direction Vx from attitude error Qe and position error Xe. Concatenate Vx and Vom to get guidance reference Xnow. Use 'smc01-control' to obtain control torque T and control force U for spacecraft Sc01 from dynamical state X and guidance reference Xnow and Diffdot. Compute dynamical state derivative Xdot from dynamical state X for spacecraft Sc01 using control force U, control torque T and guidance reference Xnow.

Resulting things are: Xdot(dynamical state derivative) .


Simple actions

Computation of attitude error

Special m-function was written to compute attiude error.

Sentences to use: Compute attitude error Qe from desired position Xdes and dynamical state X .

Available things are: Xdes( desired position) , X( dynamical state) ,

Details of the meaning: Execute code "Qe=QuatError(X(7:10),Xdes.values(7:10));".

Resulting things are: Qe(attitude error) .

Computation of control torque and force

Special code was written to compute control torque and force.

Sentences to use: Compute control torque T and control force U from matrix J2 , surface weights Alpha , special dynamical force F , smoothed sign function SG2 and Diffdot .

Available things are: J2( matrix) , Alpha( surface weights) , F( special dynamical force) , SG2( smoothed sign function) , Diffdot( *) ,

Details of the meaning: Execute code " B=[Alpha(1)*eye(3), zeros(3,3); zeros(3,3), Alpha(2)*J2]; Uin=pinv(B)*(Diffdot-F-SG2);U=Tbound(Uin(1:3),1,0);T=Tbound(Uin(4:6),1,0);".

Resulting things are: T(control torque) , U(control force) .

Computation of dynamical state derivative

The dynamical state derviative is obtained by computing the right hand side of the nonlinear state-space equation of spacecraft motion.

Sentences to use: Compute dynamical state derivative Xdot from dynamical state X for spacecraft Sc01 using control force U , control torque T and guidance reference Xnow .

Available things are: X( dynamical state) , Sc01( spacecraft) , U( control force) , T( control torque) , Xnow( guidance reference) ,

Details of the meaning: Let J be the 'inertia matrix' of spacecraft Sc01. Define M as the 'total mass' of Sc01. Execute code " F1= -crossM(X(11:13))*X(1:3) + X(4:6); F2= -crossM(X(11:13))*X(4:6); F3=0.5*crossMM(X(11:13))*X(7:10); F4=inv(J)*crossM(X(11:13))*J*X(11:13);F=[F1;F2;F3;F4];". Execute code " B=[zeros(3,3), zeros(3,3); (1/M)*eye(3,3), zeros(3,3); zeros(4,3), zeros(4,3); zeros(3,3), inv(J) ];". Execute code " Xdot=[F+B*[U;T]]; ".

Resulting things are: Xdot(dynamical state derivative) .

Computation of errors to guidance

Special code was written to compute the errors relative to the guidance vector.

Sentences to use: Compute position velocity error Ve and angular velocity error Oe from dynamical state X , guidance reference Xnow .

Available things are: X( dynamical state) , Xnow( guidance reference) ,

Details of the meaning: Execute "V=X(4:6,1); Vg=Xnow(1:3); Ve=V-Vg;". Execute " Om=X(11:13,1); Og=Xnow(4:6); Oe=Om-Og;".

Resulting things are: Ve(position velocity error) , Oe(angular velocity error) .

Computation of gradients to guidance potentials

Special m-function was written to compute the gradient t of guidance potentials that is used as control reference.

Sentences to use: Compute guidance omega gradient Vom and guidance direction Vx from attitude error Qe and position error Xe .

Available things are: Qe( attitude error) , Xe( position error) ,

Details of the meaning: Execute "[Vx,Vom]=Potentials(Xe,Qe);".

Resulting things are: Vom(guidance omega gradient) , Vx(guidance direction) .

Computation of position error

Simple code to get the position error vector.

Sentences to use: Compute position error Xe from desired position Xdes and dynamical state X .

Available things are: Xdes( desired position) , X( dynamical state) ,

Details of the meaning: Execute "Xe=X(1:3)-Xdes.values(1:3);".

Resulting things are: Xe(position error) .

Computation of special dynamical force matrix

A special matrix F occuring the in the state space model is computed here.

Sentences to use: Compute special dynamical force F from dynamical state X and surface weights Alpha .

Available things are: X( dynamical state) , Alpha( surface weights) ,

Details of the meaning: Execute " pos=X(1:3); vel=X(4:6); omega=X(11:13); F1=-crossM(omega)*pos + vel; F2=-crossM(omega)*vel; F=[Alpha(1)*F1; Alpha(2)*F2];".

Resulting things are: F(special dynamical force) .

Definition of joint sliding surface

Special code for sliding surface definition.

Sentences to use: Define the joint sliding surface G2 from the position velocity error Ve and angular velocity error Oe using the surface weights Alpha .

Available things are: Ve( position velocity error) , Oe( angular velocity error) , Alpha( surface weights) ,

Details of the meaning: Execute " G2=[Alpha(1)*Ve; Alpha(2)*Oe];".

Resulting things are: G2(joint sliding surface) .

Definition of sliding surface weights

Trivial assigment.

Sentences to use: Define surface weights Alpha as "[0.5, 0.5]" .

Available things are: L_( matlab code) ,

Details of the meaning: Execute "Alpha=L_;".

Resulting things are: Alpha(surface weights) .

Forgetting the past

Trivial meta operation with serious consequences. This is to be used to erase all past memory of the agent.

Sentences to use: Forget the past . Do not remember any past objects . Forget all past objects .

Details of the meaning: Execute "global local_memory;local_memory=cell(0,3);".

Initializing dynamical guidance state

Trivial assignment. This can be used for dynamical guidance state only.

Sentences to use: Initialize dynamical guidance state X0 with matlab code "[0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0]" .

Available things are: U_( matlab code) ,

Details of the meaning: Execute "X0=U_;".

Resulting things are: X0(dynamical guidance state) .


Inputs & Displays

Display of imagined movements

Display of graphs of states using simpel code.

Sentences to use: Display spacecraft movements XX in 'graphs of variables' . Show spacecraft movements XX in 'animation' .

Available things are: XX( spacecraft movements) , U_( quote) ,

Details of the meaning: If U_ is 'graphs of variables', then do the following. Define Label as the 'data labels' of XX. Define Mov as the 'data' of XX . Define Td as the 'time dimension' of XX. Execute code " figure; t=Td; tL=' time (s) '; subplot(311), plot(t,Mov(:,1),'-b'); xlabel(tL); ylabel(Label{1}); subplot(312), plot(t,Mov(:,2),'-r'); xlabel(tL); ylabel(Label{2}); subplot(313), plot(t,Mov(:,3),'-g'); xlabel(tL); ylabel(Label{3}); figure; subplot(411), plot(t,Mov(:,7),'-b'); xlabel(tL); ylabel(Label{7}); subplot(412), plot(t,Mov(:,8),'-r'); xlabel(tL); ylabel(Label{8}); subplot(413), plot(t,Mov(:,9),'-g'); xlabel(tL); ylabel(Label{9}); subplot(414), plot(t,Mov(:,10),'-k'); xlabel(tL); ylabel(Label{10}); ". Finish conditional actions.

Getting the desired dynamical state

The desired dynamical state contains position, attitude and their derivatives. It can be obtained in several ways such as by 'human input' at a GUI or by 'plan P2' where the plan P2 may have been prepared by the agent itself.

Sentences to use: Get desired dynamical state Xd of spacecraft Sc01 .

Available things are: Sc01( spacecraft) ,

Details of the meaning: Define Xd as the 'desired state' of spacecraft Sc01. Set the class of 'Xd' to 'desired dynamical state'.

Resulting things are: Xd(desired dynamical state) .

Getting the spacecraft data

Spacecraft data can be typed in thgrough a GUI but in general it should be in the agent's memory that keeps updating it if the spacecraft suffers changes.

Sentences to use: Get data for spacecraft Sc01 by 'human input' .

Available things are: U_( quote) ,

Details of the meaning: Execute " DesX=object_definition('desired dynamical state','DesX'); Sc01=object_definition('spacecraft','Sc01');". Define the 'desired state' of Sc01 by DesX.

Resulting things are: Sc01(spacecraft) .


Appendix

Computation of inverse matrix

Trivial numerical algorithm.

Sentences to use: Compute matrix J2 as the inverse of J .

Available things are: J( matrix) ,

Details of the meaning: Execute code "J2=pinv(J);".

Resulting things are: J2(matrix) .

Computation of smoothed sign function

Special m-function was written to compute the smoothed sign function for SMC.

Sentences to use: Compute the smoothed sign function SG2 from the joint sliding surface G2 with sign threshold 0.02 .

Available things are: G2( joint sliding surface) , Q_( number) ,

Details of the meaning: Execute "Sth=Q_;SG2=SatFunc(G2,Sth);" .

Resulting things are: SG2(smoothed sign function) .

Concatenation of vectors

Trivial concatenation operation.

Sentences to use: Concatenate vector Vx and vector Vom to get vector Xnow .

Available things are: Vx( vector) , Vom( vector) ,

Details of the meaning: Execute " try Xnow=[Vx;Vom];catch Xnow=[Vx,Vom];end ".

Resulting things are: Xnow(vector) .

Definition of class

Trivial meta operation.

Sentences to use: Set the class of 'Sc1' to 'spacecraft' . Define the class of 'Sc1' as 'spacecraft' .

Available things are: U1_( quote) , U2_( quote) ,

Details of the meaning: Execute "set_object_class(U2_,U1_);".

Definition of global variables

Trivial memory handling operation.

Sentences to use: Define 'bac, cop' as global variables . Let 'bac, cop' be global variables .

Available things are: U_( quote) ,

Details of the meaning: Execute " gv=separc(U_); for k=1:length(gv), eval(['global ',gv{k}]);end ".

Definition of object by property value

Trivial meta operation by code.

Sentences to use: Define O as the 'property' of O2 . Define O by 'property' of O2 . Let O be the 'property' of O2 .

Available things are: U1_( quote) , O2( *) ,

Details of the meaning: Execute code "O=getfield(O2,fillin(U1_));".

Resulting things are: O(*) .

Definition of property as given object

Trivial meta operation by code.

Sentences to use: Let 'property' of Obj become P . Define the 'property' of Obj by P . Make P be the 'property' of Obj .

Available things are: P( *) , U1_( quote) , Obj( *) ,

Details of the meaning: Execute code "Obj=setfield(Obj,fillin(U1_),P)".

Resulting things are: Obj(*) .

Initializing matrix

Trivial initialisation undercondition.

Sentences to use: Initialise matrix Phi as a 'unit matrix' .

Available things are: U_( quote) ,

Details of the meaning: if U_ is 'unit matrix', then execute "Phi=eye(3);".

Resulting things are: Phi(matrix) .

Truth value of strings are equal

Trvial string comparison. Tests whether two strings are identical.

Sentences to use: Quote Q is 'dingo' .

Available things are: Q( quote) , U_( quote) ,

Details of the meaning: Execute code "B=strcmp(Q,U_);".

Resulting things are: B(relation Boolean) .


The special data types of numerical arrays, cell arrays and text with constraints

'angular velocity' which is an array of numbers .
'angular velocity error' which is an array of numbers .
'array' which is an array of numbers .
'classification surface' which is an array of numbers .
'complex number' which is an array of numbers with constraints: {\it imag(x)~=0, max(size(x))==1} .
'control force' which is an array of numbers .
'control torque' which is an array of numbers .
'dynamical guidance state' which is an array of numbers .
'dynamical state' which is an array of numbers .
'dynamical state derivative' which is an array of numbers .
'equation' which is text .
'guidance direction' which is an array of numbers .
'guidance omega gradient' which is an array of numbers .
'guidance reference' which is an array of numbers .
'image' which is text .
'imaginary number' which is an array of numbers with constraints: {\it imag(x)~=0 \& real(x)==0, max(size(x))==1} .
'integer' which is an array of numbers with constraints: {\it round(x)==x, max(size(x))==1} .
'joint sliding surface' which is an array of numbers .
'learning rate' which is an array of numbers with constraints: {\it x>0, max(size(x))==1} .
'matlab code' which is text .
'matrix' which is an array of numbers with constraints: {\it min(size(x))>1} .
'negative number' which is an array of numbers with constraints: {\it x<0, max(size(x))==1} .
'nonnegative number' which is an array of numbers with constraints: {\it x>=0, max(size(x))==1} .
'number' which is an array of numbers .
'periodic time axis' which is an array of numbers with constraints: {\it min(size(x))==1 \& length(size(x))==2} .
'physical quantity' which is text .
'position velocity' which is an array of numbers .
'position velocity error' which is an array of numbers .
'positive number' which is an array of numbers with constraints: {\it x>0, max(size(x))==1} .
'quaternion' which is an array of numbers .
'quote' which is text .
'real number' which is an array of numbers with constraints: {\it imag(x)~=0, max(size(x))==1} .
'regressor vector' which is an array of numbers .
'scalar' which is an array of numbers with constraints: {\it max(size(x))==1} .
'sentence' which is text .
'sign threshold' which is an array of numbers with constraints: {\it max(size(x))==1} .
'smoothed sign function' which is an array of numbers .
'spacecraft' which is a physical object .
'special dynamical force' which is an array of numbers with constraints: {\it min(size(x))>1} .
'string' which is text with constraints: {\it size(x,1)==1} .
'surface weights' which is an array of numbers .
'symmetric matrix' which is an array of numbers with constraints: {\it min(size(x))>1} .
'text' which is text .
'time lagged array' which is an array of numbers .
'time period' which is a physical quantity .
'unit matrix' which is an array of numbers with constraints: {\it min(size(x))>1} .
'vector' which is an array of numbers .


Primitives: M-functions of hardware handling, signal processing and basic modelling

function Mx=crossM(o);
Mx=[0 -o(3) o(2); o(3), 0, -o(1);-o(2) o(1) 0];

function MMx=crossMM(o);
MMx=[0, o(3), -o(2), o(1);
-o(3), 0, o(1), o(2);
o(2), -o(1), 0, o(3);
-o(1),-o(2), -o(3), 0];

function Qout=Euler2Quat3(angs)
Xrot=angs(1);
Yrot=angs(2);
Zrot=angs(3);
A=deg2rad(Xrot);
B=deg2rad(Yrot);
C=deg2rad(Zrot);
EulerM=[ cos(B)*cos(A), cos(B)*sin(A), -sin(B);
-cos(C)*sin(A)+sin(C)*sin(B)*cos(A), cos(C)*cos(A)+sin(C)*sin(B)*sin(A), sin(C)*cos(B);
sin(C)*sin(A)+cos(C)*sin(B)*cos(A), -sin(C)*cos(A)+cos(C)*sin(B)*sin(A), cos(C)*cos(B)];
q0=0.5*sqrt(1+EulerM(1,1)+EulerM(2,2)+EulerM(3,3));
q1=0.5*sqrt(1+EulerM(1,1)-EulerM(2,2)-EulerM(3,3));
q2=0.5*sqrt(1-EulerM(1,1)+EulerM(2,2)-EulerM(3,3));
q3=0.5*sqrt(1-EulerM(1,1)-EulerM(2,2)+EulerM(3,3));
if q0 >=q1 && q0>q2 && q0>q3
Q0=q0;
Q1=(EulerM(2,3)-EulerM(3,2))/(4*q0);
Q2=(EulerM(3,1)-EulerM(1,3))/(4*q0);
Q3=(EulerM(1,2)-EulerM(2,1))/(4*q0);
elseif q1 >=q0 && q1>q2 && q1>q3
Q1=q1;
Q2=(EulerM(1,2)+EulerM(2,1))/(4*q0);
Q3=(EulerM(1,3)+EulerM(3,1))/(4*q0);
Q0=(EulerM(2,3)+EulerM(3,2))/(4*q0);
elseif q2 >=q0 && q2>q1 && q2>q3
Q2=q2;
Q1=(EulerM(1,2)+EulerM(2,1))/(4*q0);
Q3=(EulerM(2,3)+EulerM(3,2))/(4*q0);
Q0=(EulerM(3,1)-EulerM(1,3))/(4*q0);
elseif q3 >=q0 && q3>q2 && q3>q1
Q3=q3;
Q1=(EulerM(1,3)+EulerM(3,1))/(4*q0);
Q2=(EulerM(2,3)+EulerM(3,2))/(4*q0);
Q0=(EulerM(1,2)-EulerM(2,1))/(4*q0);
end
Qout=[Q1;Q2;Q3;Q0];

function Gps = getting_gps;
Gps=[];
Gps=get_gps;

function Ss = getting_star_sensor_data;
Ss=[];
Ss=star_sensor_data;

function [t,X]=ode11_Euler(txt,Tspan,X0,Options,Xtra);
global Flag
global recentdir
dt=Options.InitialStep;
t=[0:dt:Tspan]';
X=zeros(size(t,1),length(X0));
if size(X0,1)==1, x=X0';elseif size(X0,2)==1, x=X0;else
disp('ERROR: wring initial state dimensions in ODE11_EULER');
end
X(1,:)=x';
gui_active(1);
tit='ODE solution' ;
h = progressbar( [],0,'progress in solution time',tit);
pause(0.001);
od=cd;
eval(['cd(',char(39),recentdir,char(39),');']);
for k=1:length(t)-1,
eval(['dx=ML_function(',char(39),txt,'___',char(39),',t(k+1),x,Options,Flag);']);
x=x+dt*dx;
X(k+1,:)=x';
if mod(k,10)==0,
h = progressbar( h,10/length(t) );
end
if ~gui_active, break; end
end
eval(['cd(',char(39),od,char(39),');']);
progressbar( h,-1 )

function [Vx,Vomega]=Potentials(Xe,Qe)
Xscale=norm(Xe,inf);
if Xscale==0;Xscale=eps;end
Xdir=Xe/Xscale;
Xmag=norm(Xe);
Vx=-0.05*Xdir*Xmag;
Ox=Qe(1)*Qe(4);
Oy=Qe(2)*Qe(4);
Oz=Qe(3)*Qe(4);
Vomega=0.05*[Ox;Oy;Oz];

function Qe=QuatError(Qnow,Qdes)
QT=[ Qdes(4), Qdes(3), -Qdes(2), Qdes(1);
-Qdes(3), Qdes(4), Qdes(1), Qdes(2);
Qdes(2), -Qdes(1), Qdes(4), Qdes(3);
-Qdes(1), -Qdes(2), -Qdes(3), Qdes(4)];
QS=[-Qnow(1),-Qnow(2),-Qnow(3),Qnow(4)]';
Qe=QT*QS;

function Qx=quatM(om);
Qx=0.5*[0, om(3), -om(2), om(1);
-om(3), 0, om(1), om(2);
om(2), -om(1), 0, om(3);
-om(1), -om(2), -om(3), 0];

function Sout=SatFunc(S,E)
for i=1:length(S),
if abs(S(i))>E
Sout(i,1)=sign(S(i));
elseif abs(S(i)) <= E,
Sout(i,1)=S(i)/E;
end
end

function Tout=Tbound(T,Tmax,Tmin)
for i=1:length(T)
dir=sign(T(i,1));
req=abs(T(i,1));
if req>=Tmax,call=Tmax;
elseif req call=0;
else
call=req;
end
Tout(i,1)=dir*call;
end


Ontology source text used

% ID : agent ontology
% Author : S M Veres, 29 March 2008

% ALGEBRAIC AND NUMERICAL CONCEPTS

>variable
@notation: char
@assigment: char
@domain : set
>>scalar real variable
>>scalar complex variable
>>vector variable
>>matrix variable

>set -- {1,'a',[2,3]}
@members: char
@@members: char
@members list: cell

>algebraic term
@member variables: set of char
@formula : char
@reduced form: char

>algebraic equation
@left hand side : algebraic term
@right hand side : algebraic term
@unkowns: set of variables
>>algebraic definition
@defined variable: variable

>algebraic function
@input variables: set of char
@formula: char

>numerical function
@name: char
>>m-function
@file name: char
@input variables: set of char
@output variables: set of char
>>>kernel

>text : char
>>sentence
>>string -- char(round(66+rand(1,20)*30))
@@..: size(..,1)==1

>array : double -- s=rand(10,2)
>>periodic time axis -- s=0.1*(1:1000)
@@..: min(size(..))==1 & length(size(..))==2
>>vector
>>>regressor vector
>>>classification surface
>>matrix -- rand(2,2)
@@..:min(size(..))>1
>>>symmetric matrix -- [3 1; 1 2]
>>time lagged array
>>>scalar -- s=1000*randn(1)
@@..: max(size(..))==1
>>>>learning rate -- rand(1)
@@..: ..>0
>>>>integer -- s=round(1000*randn(1))
@@..:round(..)==..
>>>>positive number -- s=round(1000*rand(1))
@@..: ..>0
>>>>nonnegative number -- s=round(1000*randn(1))
@@..: ..>=0
>>>>negative number -- s=-round(1000*randn(1))
@@..: ..<0
>>>>imaginary number -- s=sqrt(-1)*round(1000*randn(1))
@@..: imag(..)~=0 & real(..)==0
>>>>complex number -- s=round(1000*randn(1))+sqrt(-1)*round(1000*randn(1))
@@..: imag(..)~=0
>>>>real number -- s=-round(1000*randn(1))
@@..: imag(..)~=0

>time period : physical quantity

>quaternion: vector
>unit matrix : matrix


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SPACECRAFT SPECIFIC CONCEPTS

>spacecraft : physical object
@coordinate frames : set of char
@inertia matrix : matrix
@inertia matrix dimension: char
@total mass : double
@current dynamical state : dynamical state
@desired state: desired dynamical state

>spacecraft movements
@time axis : double
@rotations : set of quaternions
@translation : set of vectors

>desired attitude
@dimension : {'Euler angles', 'quaternion'}
@values : vector
@reference frame : char

>desired dynamical state
@dimensions: set of char
@values : vector
@reference frame : char
@time horizon: double

>attitude error
@dimension : {'Euler angles', 'quaternion'}
@values : vector
@reference frame : char

>desired position
@dimension : {'km','m','mm'}
@values : vector
@reference frame : char


>position error
@dimension : {'km','m','mm'}
@values : vector
@reference frame : char

>guidance omega gradient : vector
>guidance direction : vector
>guidance reference : vector

>dynamical state: vector
>dynamical state derivative: vector
>dynamical guidance state : vector

>surface weights : vector
>joint sliding surface : vector
>smoothed sign function : vector

>position velocity : vector
>position velocity error : vector
>angular velocity : vector
>angular velocity error : vector

>special dynamical force : matrix
>sign threshold : scalar
>control torque : vector
>control force : vector

>spacecaft movements
@craft name: char
@data : double
@data labels : set of char
@time dimension: {'s','h','ms'}
@data dimensions: set of char