0% found this document useful (0 votes)
27 views75 pages

Spacecraft Dynamics: MRPs for Yaw

The document outlines a series of experiments focused on the numerical integration of Ordinary Differential Equations (ODEs) using Modified Rodrigues Parameters (MRPs) and stereographic projections to analyze spacecraft motion. Each section details objectives, theoretical background, procedures, results, and discussions for yaw, pitch, and roll angles, emphasizing the use of MATLAB for visualization and integration. Key findings highlight the significance of initial conditions and numerical methods in accurately modeling rotational dynamics.

Uploaded by

neethu velangi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views75 pages

Spacecraft Dynamics: MRPs for Yaw

The document outlines a series of experiments focused on the numerical integration of Ordinary Differential Equations (ODEs) using Modified Rodrigues Parameters (MRPs) and stereographic projections to analyze spacecraft motion. Each section details objectives, theoretical background, procedures, results, and discussions for yaw, pitch, and roll angles, emphasizing the use of MATLAB for visualization and integration. Key findings highlight the significance of initial conditions and numerical methods in accurately modeling rotational dynamics.

Uploaded by

neethu velangi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Numerical Integration of ODE Functions Using Modified Rodrigues Parameters for


Yaw and 3D Visualization of SpacecraftMotion

Objective:

To perform numerical integration of Ordinary Differential Equations (ODEs) using Modified


Rodrigues Parameters (MRPs), plot the yaw angle over time, and visualize the resulting Spacecraftor
spacecraft motion in 3D using MATLAB.

Introduction:

- Introduce Modified Rodrigues Parameters (MRPs) as a method for representing the orientation of a
Spacecraftor spacecraft.

- Explain the significance of yaw, along with pitch and roll, in the context of spacecraft or
Spacecraftdynamics.

- Discuss the importance of numerical integration in solving ODEs that describe rotational motion.

Theory:

- Present the mathematical formulation of MRPs and their relationship with the angular velocity of a
rigid body.

- Derive the ODEs governing the motion in terms of MRPs, focusing on the yaw angle.

- Outline the numerical integration method (e.g., Runge-Kutta) used to solve the ODEs.

Apparatus/Software:

- MATLAB R2024a (or the version you are using)

- A computer with MATLAB installed

Procedure:

1. Define the ODEs:

Formulate the system of ODEs describing the dynamics of the Spacecraftusing MRPs, with an
emphasis on the yaw angle.

2. Set Initial Conditions:

Specify initial conditions for yaw, pitch, and roll using MRPs, as these will influence the resulting
motion.

3. Numerical Integration:

Use MATLAB’s ODE solver (e.g., `ode45`) to integrate the equations over the chosen time interval.

4. Plotting Yaw:

Extract and plot the yaw angle over time from the integrated results.
5. 3D Visualization:

Visualize the 3D motion of the Spacecraftor spacecraft using MATLAB’s `plot3` function, showing
the evolution of yaw, pitch, and roll.

6. Analysis:

Analyze the results, focusing on the behavior of the yaw angle and the overall 3D motion. Discuss
the influence of initial conditions and any numerical issues encountered.

Results:

- Provide a plot of yaw versus time.

- Include a 3D plot illustrating the trajectory of the Spacecraftor spacecraft.

Discussion:

- Discuss how the initial conditions and integration parameters affect the yaw angle and the overall
trajectory.

- Consider the accuracy and stability of the numerical integration process, and comment on the
effectiveness of MRPs in representing rotational dynamics.

Conclusion:

- Summarize the key findings, particularly regarding the behavior of the yaw angle and the utility of
MRPs in modeling rotational motion.

Example MATLAB Code

```matlab

% Define the ODE function for MRPs with a focus on yaw

function dydt = mrp_ode_yaw(t, y)

% Example parameters (these should be adjusted based on the specific problem)

omega = [0.1; 0.2; 0.3]; % Angular velocity vector

dydt = zeros(3,1);

% Modified Rodrigues Parameters (MRPs) ODEs

sigma = y; % MRPs

s2 = dot(sigma, sigma); % Norm squared of MRPs


% MRP differential equations

B = (1 - s2)eye(3) + 2skew(sigma) + 2(sigmasigma');

dydt = 0.25 B omega;

end

% Skew-symmetric matrix function

function S = skew(v)

S=[ 0 -v(3) v(2);

v(3) 0 -v(1);

-v(2) v(1) 0 ];

end

% Set initial conditions (yaw, pitch, roll using MRPs)

y0 = [0.1; 0.1; 0.1];

% Define time span for integration

tspan = [0 10]; % from 0 to 10 seconds

% Perform numerical integration using ode45

[t, y] = ode45(@mrp_ode_yaw, tspan, y0);

% Plotting Yaw over time

figure;

plot(t, y(:,1)); % assuming y(:,1) corresponds to the MRP component related to yaw

xlabel('Time (s)');

ylabel('Yaw Angle (MRP)');

title('Yaw Angle vs Time (MRP)');

grid on;
% 3D Visualization of the resulting motion

figure;

plot3(y(:,1), y(:,2), y(:,3)); % Plotting MRPs in 3D space

xlabel('MRP1');

ylabel('MRP2');

zlabel('MRP3');

title('3D Trajectory of SpacecraftMotion (MRP)');

grid on;

axis equal;

```

Output:
2. Numerical Integration of ODE Functions Using Modified Rodrigues Parameters for
Pitch and 3D Visualization of SpacecraftMotion

Objective:

To perform numerical integration of Ordinary Differential Equations (ODEs) using Modified


Rodrigues Parameters (MRPs), plot the pitch angle over time, and visualize the resulting Spacecraftor
spacecraft motion in 3D using MATLAB.

Introduction:

- Introduce Modified Rodrigues Parameters (MRPs) as a representation for the orientation of a


Spacecraftor spacecraft.

- Explain the significance of pitch, along with yaw and roll, in the dynamics of a rigid body.

- Discuss the importance of numerical integration for solving ODEs that describe rotational motion.

Theory:

- Present the mathematical formulation of MRPs and how they relate to the angular velocity of a rigid
body.

- Derive the ODEs governing the motion using MRPs, with a focus on the pitch angle.

- Explain the numerical integration method (e.g., Runge-Kutta) used to solve these ODEs.

Apparatus/Software:

- MATLAB R2024a (or the version you are using)

- A computer with MATLAB installed

Procedure:

1. Define the ODEs:

Formulate the system of ODEs that describe the dynamics of the Spacecraftusing MRPs, focusing
on the pitch angle.

2. Set Initial Conditions:

Set initial conditions for pitch, yaw, and roll using MRPs, as these will determine the motion of the
rigid body.

3. Numerical Integration:

Apply MATLAB’s ODE solver (e.g., `ode45`) to integrate the equations over the specified time
period.

4. Plotting Pitch:

Extract and plot the pitch angle over time from the integrated results.
5. 3D Visualization:

Visualize the 3D motion of the Spacecraftor spacecraft using MATLAB’s `plot3` function, showing
the evolution of pitch, yaw, and roll.

6. Analysis:

Analyze the results, focusing on the behavior of the pitch angle and the overall 3D motion. Discuss
the influence of initial conditions and any numerical issues encountered.

Results:

- Provide a plot of pitch versus time.

- Include a 3D plot illustrating the trajectory of the Spacecraftor spacecraft.

Discussion:

- Discuss how the initial conditions and integration parameters affect the pitch angle and the overall
trajectory.

- Comment on the accuracy and stability of the numerical integration process, and the effectiveness of
MRPs in representing rotational dynamics.

Conclusion:

- Summarize the key findings, particularly regarding the behavior of the pitch angle and the utility of
MRPs in modeling rotational motion.

Example MATLAB Code

```matlab

% Define the ODE function for MRPs with a focus on pitch

function dydt = mrp_ode_pitch(t, y)

% Example parameters (these should be adjusted based on the specific problem)

omega = [0.2; 0.1; 0.3]; % Angular velocity vector

dydt = zeros(3,1);

% Modified Rodrigues Parameters (MRPs) ODEs

sigma = y; % MRPs

s2 = dot(sigma, sigma); % Norm squared of MRPs


% MRP differential equations

B = (1 - s2)eye(3) + 2skew(sigma) + 2(sigmasigma');

dydt = 0.25 B omega;

end

% Skew-symmetric matrix function

function S = skew(v)

S=[ 0 -v(3) v(2);

v(3) 0 -v(1);

-v(2) v(1) 0 ];

end

% Set initial conditions (yaw, pitch, roll using MRPs)

y0 = [0.1; 0.1; 0.1];

% Define time span for integration

tspan = [0 10]; % from 0 to 10 seconds

% Perform numerical integration using ode45

[t, y] = ode45(@mrp_ode_pitch, tspan, y0);

% Plotting Pitch over time

figure;

plot(t, y(:,2)); % assuming y(:,2) corresponds to the MRP component related to pitch

xlabel('Time (s)');

ylabel('Pitch Angle (MRP)');

title('Pitch Angle vs Time (MRP)');


grid on;

% 3D Visualization of the resulting motion

figure;

plot3(y(:,1), y(:,2), y(:,3)); % Plotting MRPs in 3D space

xlabel('MRP1');

ylabel('MRP2');

zlabel('MRP3');

title('3D Trajectory of SpacecraftMotion (MRP)');

grid on;

axis equal;

```

Output:
3. Numerical Integration of ODE Functions Using Modified Rodrigues Parameters for
Roll and 3D Visualization of SpacecraftMotion

Objective:

To perform numerical integration of Ordinary Differential Equations (ODEs) using Modified


Rodrigues Parameters (MRPs), plot the roll angle over time, and visualize the resulting Spacecraftor
spacecraft motion in 3D using MATLAB.

Introduction:

- Introduce Modified Rodrigues Parameters (MRPs) as an efficient method for representing the
rotational dynamics of a Spacecraftor spacecraft.

- Explain the significance of roll, along with pitch and yaw, in the overall orientation of a rigid body.

- Discuss the importance of numerical integration in solving ODEs that describe such rotational
motion.

Theory:

- Provide a mathematical background of MRPs and their relation to angular velocity and
Spacecraftmotion.

- Derive the ODEs governing the motion using MRPs, emphasizing the roll component.

- Explain the numerical integration technique (e.g., Runge-Kutta method) used to solve these ODEs.

Apparatus/Software:

- MATLAB R2024a (or the version you are using)

- A computer with MATLAB installed

Procedure:

1. Define the ODEs:

Formulate the system of ODEs using MRPs that describe the rigid body's dynamics, focusing on the
roll angle.

2. Set Initial Conditions:

Set the initial conditions for yaw, pitch, and roll using MRPs.

3. Numerical Integration:

Use MATLAB’s ODE solver (e.g., `ode45`) to integrate the ODEs over a given time period.

4. Plotting Roll:

Extract and plot the roll angle over time from the integrated results.
5. 3D Visualization:

Visualize the rigid body's 3D motion using MATLAB’s `plot3` function to show the trajectory of
the yaw, pitch, and roll parameters.

6. Analysis:

Analyze the results, focusing on the roll dynamics and the 3D motion of the rigid body. Discuss any
trends, behaviors, or numerical issues encountered.

Results:

- Present the plot of roll versus time.

- Provide a 3D plot showing the rigid body's or spacecraft's trajectory using MRPs.

Discussion:

- Discuss the impact of the initial conditions on the roll angle and the overall motion.

- Address the stability and accuracy of the numerical integration process, commenting on the
effectiveness of MRPs in describing rotational motion.

Conclusion:

- Summarize the key outcomes, particularly the behavior of the roll angle and the application of MRPs
in rotational dynamics.

Example MATLAB Code

```matlab

% Define the ODE function for MRPs with a focus on roll

function dydt = mrp_ode_roll(t, y)

% Example parameters (these should be adjusted based on the specific problem)

omega = [0.3; 0.1; 0.2]; % Angular velocity vector

dydt = zeros(3,1);

% Modified Rodrigues Parameters (MRPs) ODEs

sigma = y; % MRPs

s2 = dot(sigma, sigma); % Norm squared of MRPs


% MRP differential equations

B = (1 - s2)eye(3) + 2skew(sigma) + 2(sigmasigma');

dydt = 0.25 B omega;

end

% Skew-symmetric matrix function

function S = skew(v)

S=[ 0 -v(3) v(2);

v(3) 0 -v(1);

-v(2) v(1) 0 ];

end

% Set initial conditions (yaw, pitch, roll using MRPs)

y0 = [0.1; 0.1; 0.1];

% Define time span for integration

tspan = [0 10]; % from 0 to 10 seconds

% Perform numerical integration using ode45

[t, y] = ode45(@mrp_ode_roll, tspan, y0);

% Plotting Roll over time

figure;

plot(t, y(:,3)); % assuming y(:,3) corresponds to the MRP component related to roll

xlabel('Time (s)');

ylabel('Roll Angle (MRP)');

title('Roll Angle vs Time (MRP)');

grid on;
% 3D Visualization of the resulting motion

figure;

plot3(y(:,1), y(:,2), y(:,3)); % Plotting MRPs in 3D space

xlabel('MRP1');

ylabel('MRP2');

zlabel('MRP3');

title('3D Trajectory of SpacecraftMotion (MRP)');

grid on;

axis equal;

```

Output:
4. Numerical Integration of ODE Functions Using Stereographic Projections for Yaw and
3D Visualization of SpacecraftMotion

Objective:

To perform numerical integration of Ordinary Differential Equations (ODEs) related to stereographic


projections, plot the yaw angle over time, and visualize the resulting Spacecraftor spacecraft motion
in 3D using MATLAB.

Introduction:

- Briefly explain the concept of stereographic projections and their significance in representing
rotational motion.

- Discuss the importance of yaw, pitch, and roll in spacecraft dynamics.

- Describe the role of numerical integration in solving ODEs and its application in simulating the
motion of a rigid body.

Theory:

- Provide the mathematical formulation of stereographic projections.

- Derive the ODEs related to stereographic projections for a Spacecraft in motion.

- Explain the method of numerical integration (e.g., Runge-Kutta method) used in the experiment.

Apparatus/Software:

- MATLAB R2024a (or the version you are using)

- Computer with sufficient processing power

- MATLAB scripts for ODE integration and 3D visualization

Procedure:

1. Define the ODEs:

Define the system of ODEs representing the stereographic projections of the Spacecraft motion.

2. Set Initial Conditions:

Set the initial conditions for the state variables (e.g., initial yaw, pitch, and roll angles).

3. Numerical Integration:

Use MATLAB's ODE solver (e.g., `ode45`, `ode23`) to perform the numerical integration over the
specified time interval.

4. Plotting Yaw:

Extract the yaw angle from the integrated state variables and plot it as a function of time.
5. 3D Visualization:

Visualize the 3D motion of the Spacecraftusing MATLAB's `plot3` or similar functions, showing
the trajectory in space.

6. Analysis:

Analyze the results, discuss the accuracy and stability of the numerical integration, and interpret the
physical meaning of the yaw angle and 3D trajectory.

Results:

- Include the plot of yaw versus time.

- Provide screenshots or figures of the 3D visualization.

Discussion:

- Discuss how the initial conditions and parameters affect the yaw and 3D motion.

- Address any numerical issues encountered (e.g., stability, accuracy).

Conclusion:

- Summarize the key findings from the experiment.

- Comment on the effectiveness of stereographic projections in representing rotational dynamics.

Example MATLAB Code

```matlab

% Define the ODE function for stereographic projections

function dydt = stereographic_ode(t, y)

% Example parameters (these should be customized based on the specific problem)

omega = [0.1; 0.2; 0.3]; % Angular velocity vector

dydt = zeros(3,1);

% Stereographic projection equations (simplified example)

dydt(1) = omega(1) - y(2)omega(3) + y(3)omega(2);

dydt(2) = omega(2) - y(3)omega(1) + y(1)omega(3);

dydt(3) = omega(3) - y(1)omega(2) + y(2)omega(1);


end

% Set initial conditions (yaw, pitch, roll)

y0 = [0.1; 0.1; 0.1];

% Define time span for integration

tspan = [0 10]; % from 0 to 10 seconds

% Perform numerical integration using ode45

[t, y] = ode45(@stereographic_ode, tspan, y0);

% Plotting Yaw over time

figure;

plot(t, y(:,1)); % assuming y(:,1) corresponds to yaw

xlabel('Time (s)');

ylabel('Yaw Angle (radians)');

title('Yaw Angle vs Time');

grid on;

% 3D Visualization of the resulting motion

figure;

plot3(y(:,1), y(:,2), y(:,3)); % Plotting yaw, pitch, roll in 3D space

xlabel('Yaw');

ylabel('Pitch');

zlabel('Roll');

title('3D Trajectory of SpacecraftMotion');

grid on;

axis equal;
Output:
5. Numerical Integration of ODE Functions Using Stereographic Projections for Pitch and
3D Visualization of SpacecraftMotion

Objective:

To perform numerical integration of Ordinary Differential Equations (ODEs) related to stereographic


projections, plot the pitch angle over time, and visualize the resulting Spacecraftor spacecraft motion
in 3D using MATLAB.

Introduction:

- Provide an overview of stereographic projections and their application in representing rotational


dynamics.

- Discuss the importance of pitch, yaw, and roll in the context of spacecraft or Spacecraftmotion.

- Introduce numerical integration as a method to solve ODEs that describe the system's behavior over
time.

Theory:

- Derive the mathematical equations of stereographic projections for a rotating rigid body.

- Formulate the ODEs governing the motion in terms of pitch, yaw, and roll.

- Explain the method used for numerical integration (e.g., Runge-Kutta) and its significance in this
context.

Apparatus/Software:

- MATLAB R2024a (or the version you are using)

- Computer with MATLAB installed

Procedure:

1. Define the ODEs:

Formulate the system of ODEs that describe the stereographic projection, focusing on the pitch
angle.

2. Set Initial Conditions:

Choose initial conditions for pitch, yaw, and roll angles, which will influence the resulting motion.

3. Numerical Integration:

Apply MATLAB’s ODE solver (e.g., `ode45`) to integrate the equations over the desired time
period.

4. Plotting Pitch:

Extract and plot the pitch angle over time from the integrated solution.
5. 3D Visualization:

Visualize the Spacecraftor spacecraft's trajectory in 3D using MATLAB’s `plot3` function, showing
the evolution of pitch, yaw, and roll.

6. Analysis:

Discuss the results, focusing on the behavior of the pitch angle and the overall 3D motion. Analyze
any trends or patterns observed in the data.

Results:

- Provide a plot of the pitch angle versus time.

- Include a 3D plot showing the motion of the Spacecraftor spacecraft.

Discussion:

- Discuss the impact of initial conditions on the pitch and overall motion.

- Address the accuracy and stability of the numerical integration process.

Conclusion:

- Summarize the key outcomes, including the behavior of the pitch angle and the effectiveness of
stereographic projections in representing the motion.

Example MATLAB Code

```matlab

% Define the ODE function for stereographic projections with a focus on pitch

function dydt = stereographic_ode_pitch(t, y)

% Example parameters (these should be adjusted based on the specific problem)

omega = [0.2; 0.1; 0.3]; % Angular velocity vector

dydt = zeros(3,1);

% Stereographic projection equations (example)

dydt(1) = omega(1) - y(2)omega(3) + y(3)omega(2); % Yaw component

dydt(2) = omega(2) - y(3)omega(1) + y(1)omega(3); % Pitch component

dydt(3) = omega(3) - y(1)omega(2) + y(2)omega(1); % Roll component

end
% Set initial conditions (yaw, pitch, roll)

y0 = [0.1; 0.1; 0.1];

% Define time span for integration

tspan = [0 10]; % from 0 to 10 seconds

% Perform numerical integration using ode45

[t, y] = ode45(@stereographic_ode_pitch, tspan, y0);

% Plotting Pitch over time

figure;

plot(t, y(:,2)); % assuming y(:,2) corresponds to pitch

xlabel('Time (s)');

ylabel('Pitch Angle (radians)');

title('Pitch Angle vs Time');

grid on;

% 3D Visualization of the resulting motion

figure;

plot3(y(:,1), y(:,2), y(:,3)); % Plotting yaw, pitch, roll in 3D space

xlabel('Yaw');

ylabel('Pitch');

zlabel('Roll');

title('3D Trajectory of SpacecraftMotion');

grid on;

axis equal;

```
Output:
6. Numerical Integration of ODE Functions Using Stereographic Projections for Roll and
3D Visualization of SpacecraftMotion

Objective:

To perform numerical integration of Ordinary Differential Equations (ODEs) related to stereographic


projections, plot the roll angle over time, and visualize the resulting Spacecraftor spacecraft motion in
3D using MATLAB.

Introduction:

- Introduce stereographic projections and their relevance in representing rotational motion.

- Explain the significance of roll, along with yaw and pitch, in describing the orientation of a
Spacecraftor spacecraft.

- Discuss the necessity of numerical integration in solving ODEs for dynamic systems.

Theory:

- Present the mathematical background of stereographic projections for a rotating body.

- Derive the ODEs that describe the motion, focusing on the roll angle.

- Outline the numerical integration method used (e.g., Runge-Kutta) and its application to solving
these ODEs.

Apparatus/Software:

- MATLAB R2024a (or the version you are using)

- A computer with MATLAB installed

Procedure:

1. Define the ODEs:

Formulate the system of ODEs describing the stereographic projection, particularly emphasizing the
roll angle.

2. Set Initial Conditions:

Specify initial conditions for yaw, pitch, and roll, as these will influence the motion of the rigid
body.

3. Numerical Integration:

Utilize MATLAB’s ODE solver (e.g., `ode45`) to integrate the equations over the selected time
interval.

4. Plotting Roll:

Extract and plot the roll angle over time from the solution of the ODEs.
5. 3D Visualization:

Visualize the Spacecraftor spacecraft’s motion in 3D using MATLAB’s `plot3` function,


highlighting the relationship between roll, yaw, and pitch.

6. Analysis:

Analyze the results, focusing on the behavior of the roll angle and the overall 3D motion of the
system. Discuss any patterns or anomalies observed.

Results:

- Include a plot of roll versus time.

- Provide a 3D plot illustrating the motion of the Spacecraftor spacecraft.

Discussion:

- Discuss how initial conditions and parameters affect the roll angle and the overall trajectory.

- Consider the accuracy and stability of the numerical integration process and any potential sources of
error.

Conclusion:

- Summarize the key findings, particularly focusing on the behavior of the roll angle and the
usefulness of stereographic projections in this context.

Example MATLAB Code

```matlab

% Define the ODE function for stereographic projections with a focus on roll

function dydt = stereographic_ode_roll(t, y)

% Example parameters (these should be adjusted based on the specific problem)

omega = [0.3; 0.2; 0.1]; % Angular velocity vector

dydt = zeros(3,1);

% Stereographic projection equations (example)

dydt(1) = omega(1) - y(2)omega(3) + y(3)omega(2); % Yaw component

dydt(2) = omega(2) - y(3)omega(1) + y(1)omega(3); % Pitch component

dydt(3) = omega(3) - y(1)omega(2) + y(2)omega(1); % Roll component


end

% Set initial conditions (yaw, pitch, roll)

y0 = [0.1; 0.1; 0.1];

% Define time span for integration

tspan = [0 10]; % from 0 to 10 seconds

% Perform numerical integration using ode45

[t, y] = ode45(@stereographic_ode_roll, tspan, y0);

% Plotting Roll over time

figure;

plot(t, y(:,3)); % assuming y(:,3) corresponds to roll

xlabel('Time (s)');

ylabel('Roll Angle (radians)');

title('Roll Angle vs Time');

grid on;

% 3D Visualization of the resulting motion

figure;

plot3(y(:,1), y(:,2), y(:,3)); % Plotting yaw, pitch, roll in 3D space

xlabel('Yaw');

ylabel('Pitch');

zlabel('Roll');

title('3D Trajectory of SpacecraftMotion');

grid on;

axis equal;
```

Output:
7. Numerical Integration of ODE Functions of Cayley-Klein Parameters plotting the yaw
angle motion and Visualization of Spacecraft Motion

Objective:

1. To perform numerical integration of Ordinary Differential Equations (ODE) using Cayley-Klein


parameters.

2. To plot the yaw angle as a function of time.

3. To create a 3D visualization of the resulting Spacecraftor spacecraft motion.

Theory:

The Cayley-Klein parameters are used in representing rotations in three-dimensional space. These
parameters are particularly useful in aerospace applications for representing the orientation of
spacecraft. This experiment involves the numerical integration of the ODEs associated with these
parameters and analyzing the resulting motion.

Equipment and Software:

- MATLAB software

- Computer with MATLAB installed

Procedure:

1. Set Up the MATLAB Environment:

- Open MATLAB.

- Create a new script file for the experiment.

2. Define the ODEs:

- Write the system of ODEs representing the Cayley-Klein parameters. These equations govern the
rotational dynamics of the spacecraft.

3. Numerical Integration:

- Implement the numerical integration using MATLAB's built-in functions like `ode45` or `ode23`.

- Set the initial conditions for the Cayley-Klein parameters.

- Define the time span over which the integration will be performed.

4. Plotting Yaw Angle:

- Extract the yaw angle from the integrated results.

- Plot the yaw angle against time.

5. 3D Visualization:
- Use the integrated Cayley-Klein parameters to calculate the orientation of the spacecraft over time.

- Create a 3D plot that visualizes the motion of the spacecraft.

- Use MATLAB's plotting functions such as `plot3`, `quiver3`, or `surf` to visualize the spacecraft's
orientation and motion.

6. Analysis:

- Analyze the plots and the 3D visualization to understand the behavior of the spacecraft.

7. Conclusion:

- Summarize the findings from the experiment.

- Discuss any discrepancies or interesting observations in the behavior of the spacecraft.

MATLAB Code:

% Define the system of ODEs for Cayley-Klein parameters

function dydt = cayley_klein_ode(t, y)

% Example ODEs (these should be replaced with the actual equations)

% y(1), y(2), y(3), y(4) are the Cayley-Klein parameters

% omega_x, omega_y, omega_z are the angular velocities

omega_x = 0.1; % Angular velocity in the x direction

omega_y = 0.2; % Angular velocity in the y direction

omega_z = 0.3; % Angular velocity in the z direction

dydt = zeros(4,1);

dydt(1) = -0.5(omega_xy(2) + omega_yy(3) + omega_zy(4));

dydt(2) = 0.5(omega_xy(1) + omega_zy(3) - omega_yy(4));

dydt(3) = 0.5(omega_yy(1) - omega_zy(2) + omega_xy(4));

dydt(4) = 0.5(omega_zy(1) + omega_yy(2) - omega_xy(3));

end

% Initial conditions for Cayley-Klein parameters


y0 = [1; 0; 0; 0]; % Initial quaternion (example)

% Time span for the integration

tspan = [0 10];

% Perform numerical integration

[t, y] = ode45(@cayley_klein_ode, tspan, y0);

% Extract yaw angle (Example: assuming yaw = atan2(2(q1q4 + q2q3), 1 - 2(q3^2 + q4^2)))

yaw = atan2(2(y(:,1).y(:,4) + y(:,2).y(:,3)), 1 - 2(y(:,3).^2 + y(:,4).^2));

% Plot yaw angle

figure;

plot(t, yaw);

xlabel('Time (s)');

ylabel('Yaw Angle (rad)');

title('Yaw Angle vs Time');

% 3D Visualization of spacecraft motion

% (Assuming the spacecraft is represented by a vector in 3D space)

figure;

for i = 1:length(t)

clf;

% Calculate the rotation matrix from Cayley-Klein parameters

R = quat2rotm([y(i,1) y(i,2) y(i,3) y(i,4)]);

% Define the spacecraft's body frame axes (example: a unit vector along the x-axis)

body_frame = [1; 0; 0];


% Rotate the body frame vector

rotated_vector = R body_frame;

% Plot the rotated vector

quiver3(0, 0, 0, rotated_vector(1), rotated_vector(2), rotated_vector(3), 'r');

axis equal;

axis([-1 1 -1 1 -1 1]);

grid on;

xlabel('X');

ylabel('Y');

zlabel('Z');

title(sprintf('Spacecraft Orientation at t = %.2f s', t(i)));

pause(0.1);

end

Results:

- Include plots of yaw angle versus time.

- Include screenshots or figures from the 3D visualization.

- Discuss the behavior observed in the yaw angle plot.

- Analyze the motion of the spacecraft as visualized in 3D.

- Relate the findings to the theoretical expectations.


Output:

Conclusion:

Summarize the key results and observations from the experiment, highlighting any significant
conclusions regarding the spacecraft's rotational dynamics.

Questions:

1. What role do the Cayley-Klein parameters play in the representation of rotational dynamics?

2. How does the yaw angle behave over time based on the integration results?

3. What are the potential sources of error in this experiment?


8. Numerical Integration of ODE Functions of Cayley-Klein Parameters plotting the pitch
angle motion and Visualization of Spacecraft Motion

Objective:

1. To perform numerical integration of Ordinary Differential Equations (ODE) using Cayley-Klein


parameters.

2. To plot the pitch angle as a function of time.

3. To create a 3D visualization of the resulting Spacecraftor spacecraft motion.

Theory:

The Cayley-Klein parameters provide a compact representation of rotations in three-dimensional


space. These parameters are especially useful in aerospace applications to represent the orientation of
a spacecraft. This experiment involves solving the ODEs associated with these parameters, analyzing
the pitch behavior over time, and visualizing the spacecraft's motion in 3D.

Equipment and Software:

- MATLAB software

- Computer with MATLAB installed

Procedure:

1. Set Up the MATLAB Environment:

- Open MATLAB.

- Create a new script file for the experiment.

2. Define the ODEs:

- Write the system of ODEs representing the Cayley-Klein parameters, which govern the rotational
dynamics of the spacecraft.

3. Numerical Integration:

- Implement the numerical integration using MATLAB's built-in functions like `ode45`.

- Set the initial conditions for the Cayley-Klein parameters.

- Define the time span over which the integration will be performed.

4. Plotting Pitch Angle:

- Extract the pitch angle from the integrated results.

- Plot the pitch angle against time.

5. 3D Visualization:
- Use the integrated Cayley-Klein parameters to calculate the orientation of the spacecraft over time.

- Create a 3D plot that visualizes the motion of the spacecraft.

- Use MATLAB's plotting functions such as `plot3`, `quiver3`, or `surf` to visualize the spacecraft's
orientation and motion.

6. Analysis:

- Analyze the plots and the 3D visualization to understand the behavior of the spacecraft.

7. Conclusion:

- Summarize the findings from the experiment.

- Discuss any discrepancies or interesting observations in the behavior of the spacecraft.

MATLAB Code:

% Define the system of ODEs for Cayley-Klein parameters

function dydt = cayley_klein_ode(t, y)

% Example ODEs (these should be replaced with the actual equations)

% y(1), y(2), y(3), y(4) are the Cayley-Klein parameters

% omega_x, omega_y, omega_z are the angular velocities

omega_x = 0.1; % Angular velocity in the x direction

omega_y = 0.2; % Angular velocity in the y direction

omega_z = 0.3; % Angular velocity in the z direction

dydt = zeros(4,1);

dydt(1) = -0.5(omega_xy(2) + omega_yy(3) + omega_zy(4));

dydt(2) = 0.5(omega_xy(1) + omega_zy(3) - omega_yy(4));

dydt(3) = 0.5(omega_yy(1) - omega_zy(2) + omega_xy(4));

dydt(4) = 0.5(omega_zy(1) + omega_yy(2) - omega_xy(3));

end

% Initial conditions for Cayley-Klein parameters

y0 = [1; 0; 0; 0]; % Initial quaternion (example)


% Time span for the integration

tspan = [0 10];

% Perform numerical integration

[t, y] = ode45(@cayley_klein_ode, tspan, y0);

% Extract pitch angle (Example: assuming pitch = asin(2(q1q3 - q4q2)))

pitch = asin(2(y(:,1).y(:,3) - y(:,4).y(:,2)));

% Plot pitch angle

figure;

plot(t, pitch);

xlabel('Time (s)');

ylabel('Pitch Angle (rad)');

title('Pitch Angle vs Time');

% 3D Visualization of spacecraft motion

% (Assuming the spacecraft is represented by a vector in 3D space)

figure;

for i = 1:length(t)

clf;

% Calculate the rotation matrix from Cayley-Klein parameters

R = quat2rotm([y(i,1) y(i,2) y(i,3) y(i,4)]);

% Define the spacecraft's body frame axes (example: a unit vector along the x-axis)

body_frame = [1; 0; 0];


% Rotate the body frame vector

rotated_vector = R body_frame;

% Plot the rotated vector

quiver3(0, 0, 0, rotated_vector(1), rotated_vector(2), rotated_vector(3), 'b');

axis equal;

axis([-1 1 -1 1 -1 1]);

grid on;

xlabel('X');

ylabel('Y');

zlabel('Z');

title(sprintf('Spacecraft Orientation at t = %.2f s', t(i)));

pause(0.1);

end

Results:

- Include plots of pitch angle versus time.

- Include screenshots or figures from the 3D visualization.

Discussion:

- Discuss the behavior observed in the pitch angle plot.

- Analyze the motion of the spacecraft as visualized in 3D.

- Relate the findings to the theoretical expectations.


Output:

Conclusion:

Summarize the key results and observations from the experiment, highlighting any significant
conclusions regarding the spacecraft's rotational dynamics.

Questions:

1. What role do the Cayley-Klein parameters play in the representation of rotational dynamics?

2. How does the pitch angle behave over time based on the integration results?

3. What are the potential sources of error in this experiment?


9. Numerical Integration of ODE Functions of Cayley-Klein Parameters plotting the roll
angle motion and Visualization of Spacecraft Motion

Objective:

1. To perform numerical integration of Ordinary Differential Equations (ODE) using Cayley-Klein


parameters.

2. To plot the roll angle as a function of time.

3. To create a 3D visualization of the resulting Spacecraftor spacecraft motion.

Theory:

The Cayley-Klein parameters are a set of four parameters that can represent the orientation of a
Spacecraftin three-dimensional space. These parameters are particularly useful in aerospace
applications for describing the rotation and orientation of spacecraft. This experiment focuses on
solving the ODEs related to the Cayley-Klein parameters, analyzing the behavior of the roll angle
over time, and visualizing the spacecraft's motion in 3D.

Equipment and Software:

- MATLAB software

- Computer with MATLAB installed

Procedure:

1. Set Up the MATLAB Environment:

- Open MATLAB.

- Create a new script file for the experiment.

2. Define the ODEs:

- Write the system of ODEs representing the Cayley-Klein parameters. These equations govern the
rotational dynamics of the spacecraft.

3. Numerical Integration:

- Implement the numerical integration using MATLAB's built-in functions like `ode45`.

- Set the initial conditions for the Cayley-Klein parameters.

- Define the time span over which the integration will be performed.

4. Plotting Roll Angle:

- Extract the roll angle from the integrated results.

- Plot the roll angle against time.


5. 3D Visualization:

- Use the integrated Cayley-Klein parameters to calculate the orientation of the spacecraft over time.

- Create a 3D plot that visualizes the motion of the spacecraft.

- Use MATLAB's plotting functions such as `plot3`, `quiver3`, or `surf` to visualize the spacecraft's
orientation and motion.

6. Analysis:

- Analyze the plots and the 3D visualization to understand the behavior of the spacecraft.

7. Conclusion:

- Summarize the findings from the experiment.

- Discuss any discrepancies or interesting observations in the behavior of the spacecraft.

MATLAB Code:

% Define the system of ODEs for Cayley-Klein parameters

function dydt = cayley_klein_ode(t, y)

% Example ODEs (these should be replaced with the actual equations)

% y(1), y(2), y(3), y(4) are the Cayley-Klein parameters

% omega_x, omega_y, omega_z are the angular velocities

omega_x = 0.1; % Angular velocity in the x direction

omega_y = 0.2; % Angular velocity in the y direction

omega_z = 0.3; % Angular velocity in the z direction

dydt = zeros(4,1);

dydt(1) = -0.5(omega_xy(2) + omega_yy(3) + omega_zy(4));

dydt(2) = 0.5(omega_xy(1) + omega_zy(3) - omega_yy(4));

dydt(3) = 0.5(omega_yy(1) - omega_zy(2) + omega_xy(4));

dydt(4) = 0.5(omega_zy(1) + omega_yy(2) - omega_xy(3));

end

% Initial conditions for Cayley-Klein parameters


y0 = [1; 0; 0; 0]; % Initial quaternion (example)

% Time span for the integration

tspan = [0 10];

% Perform numerical integration

[t, y] = ode45(@cayley_klein_ode, tspan, y0);

% Extract roll angle (Example: assuming roll = atan2(2(q1q2 + q3q4), 1 - 2(q2^2 + q3^2)))

roll = atan2(2(y(:,1).y(:,2) + y(:,3).y(:,4)), 1 - 2(y(:,2).^2 + y(:,3).^2));

% Plot roll angle

figure;

plot(t, roll);

xlabel('Time (s)');

ylabel('Roll Angle (rad)');

title('Roll Angle vs Time');

% 3D Visualization of spacecraft motion

% (Assuming the spacecraft is represented by a vector in 3D space)

figure;

for i = 1:length(t)

clf;

% Calculate the rotation matrix from Cayley-Klein parameters

R = quat2rotm([y(i,1) y(i,2) y(i,3) y(i,4)]);

% Define the spacecraft's body frame axes (example: a unit vector along the x-axis)

body_frame = [1; 0; 0];


% Rotate the body frame vector

rotated_vector = R body_frame;

% Plot the rotated vector

quiver3(0, 0, 0, rotated_vector(1), rotated_vector(2), rotated_vector(3), 'g');

axis equal;

axis([-1 1 -1 1 -1 1]);

grid on;

xlabel('X');

ylabel('Y');

zlabel('Z');

title(sprintf('Spacecraft Orientation at t = %.2f s', t(i)));

pause(0.1);

end

Results:

- Include plots of roll angle versus time.

- Include screenshots or figures from the 3D visualization.

Discussion:

- Discuss the behavior observed in the roll angle plot.

- Analyze the motion of the spacecraft as visualized in 3D.

- Relate the findings to the theoretical expectations.


Output:

Conclusion:

Summarize the key results and observations from the experiment, highlighting any significant
conclusions regarding the spacecraft's rotational dynamics.

Questions:

1. What role do the Cayley-Klein parameters play in the representation of rotational dynamics?

2. How does the roll angle behave over time based on the integration results?

3. What are the potential sources of error in this experiment?


10. Numerical Integration of ODE Functions of Euler ANGLES for ROLL and 3D
Visualization of Spacecraft Motion

Lab Manual Format: Numerical Integration of ODE Function of Euler Angles

1. Introduction

This lab aims to numerically integrate the equations of motion using Euler angles to describe the
attitude dynamics of a spacecraft. The focus will be on plotting the roll angle over time and
visualizing the spacecraft’s 3D motion based on these Euler angles.

2. Objectives

- To understand the use of Euler angles (yaw, pitch, roll) in representing spacecraft orientation.

- To numerically integrate the ODEs for Euler angles using MATLAB.

- To plot the roll angle over time from the integrated data.

- To create a 3D visualization of the spacecraft’s orientation using the Euler angles.

3. Theory

Euler angles describe the orientation of a rigid body in space using three angles: yaw (rotation about
the z-axis), pitch (rotation about the y-axis), and roll (rotation about the x-axis). The dynamic
equations for Euler angles describe how these angles evolve based on the body’s angular velocity
components ( p ), ( q ), and ( r ).

The rate of change of Euler angles is given by:

4. Apparatus/Software

- MATLAB

- Computer with MATLAB installed


5. Procedure

1. Step 1: Define angular velocity components

Specify the angular velocities ( p ), ( q ), and ( r ) in the body frame of the spacecraft.

2. Step 2: Define initial conditions

Set initial conditions for the Euler angles

(roll, pitch, yaw).

3. Step 3: Write the ODE function for Euler angles

Implement the kinematic equations for Euler angles in MATLAB

4. Step 4: Perform numerical integration

Use MATLAB’s `ode45` solver to numerically integrate the equations of motion for Euler angles
over a time span.

5. Step 5: Extract roll angle

Plot the roll angle \( \phi \) as a function of time to observe how it evolves during the spacecraft’s
motion.

6. Step 6: Plot roll over time

Plot the roll angle as a function of time.

7. Step 7: Visualize 3D motion

Use the Euler angles to create a 3D visualization of the spacecraft’s orientation during its motion.

6. Observations

- Plot the variation of the roll angle with time.

- Visualize the spacecraft's 3D orientation based on Euler angles.


7. Conclusion

Discuss the behavior of the roll angle and how Euler angles provide a convenient means of
representing and visualizing the spacecraft's orientation.

---

MATLAB Example Code: Numerical Integration of Euler Angles for Roll and 3D Visualization

```matlab

% Define the angular velocity components (p, q, r)

omega = [0.1; 0.2; 0.3]; % Example angular velocity in rad/s

% Initial Euler angles [roll, pitch, yaw] (in radians)

euler0 = [0; 0; 0]; % Initial orientation (roll, pitch, yaw)

% Time span

tspan = [0 10]; % From 0 to 10 seconds

% ODE function for Euler angles kinematics

function deulerdt = euler_kinematics(t, euler)

omega = [0.1; 0.2; 0.3]; % Example angular velocity

p = omega(1); q = omega(2); r = omega(3);

roll = euler(1);

pitch = euler(2);

% Transformation matrix for Euler angles

T = [1, sin(roll)tan(pitch), cos(roll)tan(pitch);

0, cos(roll), -sin(roll);
0, sin(roll)/cos(pitch), cos(roll)/cos(pitch)];

% Euler angles rates

deulerdt = T [p; q; r];

end

% Solve the ODE

[t, euler] = ode45(@euler_kinematics, tspan, euler0);

% Extract roll from the Euler angles

roll = euler(:,1);

% Plot the roll over time

figure;

plot(t, roll);

title('Roll vs Time');

xlabel('Time (s)');

ylabel('Roll (rad)');

% 3D visualization of the spacecraft orientation

figure;

for i = 1:length(t)

roll = euler(i,1);

pitch = euler(i,2);

yaw = euler(i,3);

% Create the rotation matrix from Euler angles

R = eul2rotm([yaw, pitch, roll]);


% Plot the spacecraft body axes

plot3([0 R(1,1)], [0 R(2,1)], [0 R(3,1)], 'r', 'LineWidth', 2); hold on;

plot3([0 R(1,2)], [0 R(2,2)], [0 R(3,2)], 'g', 'LineWidth', 2);

plot3([0 R(1,3)], [0 R(2,3)], [0 R(3,3)], 'b', 'LineWidth', 2);

axis equal;

grid on;

xlabel('X'); ylabel('Y'); zlabel('Z');

title('3D Spacecraft Orientation');

pause(0.1);

hold off;

end

% Function to convert Euler angles to rotation matrix

function R = eul2rotm(eul)

yaw = eul(1); pitch = eul(2); roll = eul(3);

Rz = [cos(yaw), -sin(yaw), 0;

sin(yaw), cos(yaw), 0;

0, 0, 1];

Ry = [cos(pitch), 0, sin(pitch);

0, 1, 0;

-sin(pitch), 0, cos(pitch)];

Rx = [1, 0, 0;

0, cos(roll), -sin(roll);

0, sin(roll), cos(roll)];

R = Rz Ry Rx;

end

```
Output:

This MATLAB code performs the numerical integration of Euler angle kinematic equations,
computes the roll angle, and generates a 3D visualization of the spacecraft's orientation over time.
11. Numerical Integration of ODE Functions of Euler ANGLES for PITCH and 3D
Visualization of Spacecraft Motion

1. Introduction

This lab focuses on numerically integrating the equations of motion using Euler angles to describe the
spacecraft's attitude dynamics. Specifically, it involves plotting the pitch angle over time and
visualizing the spacecraft's 3D motion based on Euler angles.

2. Objectives

- To understand the use of Euler angles (yaw, pitch, roll) in representing spacecraft orientation.

- To numerically integrate the ODEs for Euler angles using MATLAB.

- To plot the pitch angle over time from the integrated data.

- To create a 3D visualization of the spacecraft's orientation using Euler angles.

3. Theory

Euler angles describe the orientation of a rigid body in space using three angles: yaw (rotation about
the z-axis), pitch (rotation about the y-axis), and roll (rotation about the x-axis). The dynamic
equations for Euler angles describe how these angles evolve based on the body’s angular velocity
components ( p ), ( q ), and ( r ).

The rate of change of Euler angles is given by:

4. Apparatus/Software

- MATLAB

- Computer with MATLAB installed


5. Procedure

1. Step 1: Define angular velocity components

Specify the angular velocities ( p ), ( q ), and ( r ) in the body frame of the spacecraft.

2. Step 2: Define initial conditions

Set initial conditions for the Euler angles

(roll, pitch, yaw).

3. Step 3: Write the ODE function for Euler angles

Implement the kinematic equations for Euler angles in MATLAB.

4. Step 4: Perform numerical integration

Use MATLAB’s `ode45` solver to integrate the equations of motion for Euler angles over a
specified time span.

5. Step 5: Extract pitch angle

From the integrated solution, extract and plot the pitch angle \( \theta \) as a function of time.

6. Step 6: Plot pitch over time

Plot the pitch angle \( \theta \) as a function of time.

7. Step 7: Visualize 3D motion

Use the Euler angles to generate a 3D visualization of the spacecraft’s orientation over time.

6. Observations

- Plot the variation of the pitch angle over time.

- Visualize the spacecraft’s 3D orientation based on the integrated Euler angles.


7. Conclusion

Discuss the evolution of the pitch angle and how Euler angles offer a practical way to represent and
visualize the spacecraft’s attitude.

---

MATLAB Example Code: Numerical Integration of Euler Angles for Pitch and 3D Visualization

```matlab

% Define the angular velocity components (p, q, r)

omega = [0.1; 0.2; 0.3]; % Example angular velocity in rad/s

% Initial Euler angles [roll, pitch, yaw] (in radians)

euler0 = [0; 0; 0]; % Initial orientation (roll, pitch, yaw)

% Time span

tspan = [0 10]; % From 0 to 10 seconds

% ODE function for Euler angles kinematics

function deulerdt = euler_kinematics(t, euler)

omega = [0.1; 0.2; 0.3]; % Example angular velocity

p = omega(1); q_ang = omega(2); r = omega(3);

roll = euler(1);

pitch = euler(2);

% Transformation matrix for Euler angles

T = [1, sin(roll)tan(pitch), cos(roll)tan(pitch);


0, cos(roll), -sin(roll);

0, sin(roll)/cos(pitch), cos(roll)/cos(pitch)];

% Euler angles rates

deulerdt = T [p; q_ang; r];

end

% Solve the ODE

[t, euler] = ode45(@euler_kinematics, tspan, euler0);

% Extract pitch from the Euler angles

pitch = euler(:,2);

% Plot the pitch over time

figure;

plot(t, pitch);

title('Pitch vs Time');

xlabel('Time (s)');

ylabel('Pitch (rad)');

% 3D visualization of the spacecraft orientation

figure;

for i = 1:length(t)

roll = euler(i,1);

pitch = euler(i,2);

yaw = euler(i,3);

% Create the rotation matrix from Euler angles


R = eul2rotm([yaw, pitch, roll]);

% Plot the spacecraft body axes

plot3([0 R(1,1)], [0 R(2,1)], [0 R(3,1)], 'r', 'LineWidth', 2); hold on;

plot3([0 R(1,2)], [0 R(2,2)], [0 R(3,2)], 'g', 'LineWidth', 2);

plot3([0 R(1,3)], [0 R(2,3)], [0 R(3,3)], 'b', 'LineWidth', 2);

axis equal;

grid on;

xlabel('X'); ylabel('Y'); zlabel('Z');

title('3D Spacecraft Orientation');

pause(0.1);

hold off;

end

% Function to convert Euler angles to rotation matrix

function R = eul2rotm(eul)

yaw = eul(1); pitch = eul(2); roll = eul(3);

Rz = [cos(yaw), -sin(yaw), 0;

sin(yaw), cos(yaw), 0;

0, 0, 1];

Ry = [cos(pitch), 0, sin(pitch);

0, 1, 0;

-sin(pitch), 0, cos(pitch)];

Rx = [1, 0, 0;

0, cos(roll), -sin(roll);

0, sin(roll), cos(roll)];

R = Rz Ry Rx;

end
```

Output:

This MATLAB code performs the numerical integration of Euler angle kinematic equations,
computes the pitch angle, and generates a 3D visualization of the spacecraft's orientation over time.
12. Numerical Integration of ODE Functions of Euler ANGLES for YAW and 3D
Visualization of Spacecraft Motion

1. Introduction

This lab focuses on the numerical integration of Euler angles to model the attitude dynamics of a
spacecraft. The objective is to plot the yaw angle over time and visualize the spacecraft’s 3D motion
based on these Euler angles.

2. Objectives

- To understand the use of Euler angles (yaw, pitch, roll) in representing spacecraft orientation.

- To numerically integrate the ODEs for Euler angles using MATLAB.

- To plot the yaw angle over time from the integrated data.

- To create a 3D visualization of the spacecraft’s orientation using Euler angles.

3. Theory

Euler angles describe the orientation of a rigid body in space using three angles: yaw (rotation about
the z-axis), pitch (rotation about the y-axis), and roll (rotation about the x-axis). The dynamic
equations for Euler angles describe how these angles evolve based on the body’s angular velocity
components ( p ), ( q ), and ( r ).

The rate of change of Euler angles is given by:

4. Apparatus/Software

- MATLAB

- Computer with MATLAB installed


5. Procedure

1. Step 1: Define angular velocity components

Specify the angular velocities ( p ), ( q ), and ( r ) in the body frame of the spacecraft.

2. Step 2: Define initial conditions

Set initial conditions for the Euler angles

(roll, pitch, yaw).

3. Step 3: Write the ODE function for Euler angles

Implement the kinematic equations for Euler angles in MATLAB.

4. Step 4: Perform numerical integration

Use MATLAB’s `ode45` solver to integrate the equations of motion for Euler angles over a
specified time span.

5. Step 5: Extract yaw angle

Extract and plot the yaw angle \( \psi \) as a function of time from the integrated data.

6. Step 6: Plot yaw over time

Plot the yaw angle as a function of time.

7. Step 7: Visualize 3D motion

Use the Euler angles to generate a 3D visualization of the spacecraft’s orientation over time.

6. Observations

- Plot the variation of the yaw angle with time.

- Visualize the spacecraft’s 3D orientation based on the Euler angles.


7. Conclusion

Discuss the evolution of the yaw angle and how Euler angles offer a practical way to represent and
visualize the spacecraft’s attitude.

MATLAB Example Code: Numerical Integration of Euler Angles for Yaw and 3D Visualization

```matlab

% Define the angular velocity components (p, q, r)

omega = [0.1; 0.2; 0.3]; % Example angular velocity in rad/s

% Initial Euler angles [roll, pitch, yaw] (in radians)

euler0 = [0; 0; 0]; % Initial orientation (roll, pitch, yaw)

% Time span

tspan = [0 10]; % From 0 to 10 seconds

% ODE function for Euler angles kinematics

function deulerdt = euler_kinematics(t, euler)

omega = [0.1; 0.2; 0.3]; % Example angular velocity

p = omega(1); q_ang = omega(2); r = omega(3);

roll = euler(1);

pitch = euler(2);

% Transformation matrix for Euler angles

T = [1, sin(roll)tan(pitch), cos(roll)tan(pitch);

0, cos(roll), -sin(roll);

0, sin(roll)/cos(pitch), cos(roll)/cos(pitch)];
% Euler angles rates

deulerdt = T [p; q_ang; r];

end

% Solve the ODE

[t, euler] = ode45(@euler_kinematics, tspan, euler0);

% Extract yaw from the Euler angles

yaw = euler(:,3);

% Plot the yaw over time

figure;

plot(t, yaw);

title('Yaw vs Time');

xlabel('Time (s)');

ylabel('Yaw (rad)');

% 3D visualization of the spacecraft orientation

figure;

for i = 1:length(t)

roll = euler(i,1);

pitch = euler(i,2);

yaw = euler(i,3);

% Create the rotation matrix from Euler angles

R = eul2rotm([yaw, pitch, roll]);


% Plot the spacecraft body axes

plot3([0 R(1,1)], [0 R(2,1)], [0 R(3,1)], 'r', 'LineWidth', 2); hold on;

plot3([0 R(1,2)], [0 R(2,2)], [0 R(3,2)], 'g', 'LineWidth', 2);

plot3([0 R(1,3)], [0 R(2,3)], [0 R(3,3)], 'b', 'LineWidth', 2);

axis equal;

grid on;

xlabel('X'); ylabel('Y'); zlabel('Z');

title('3D Spacecraft Orientation');

pause(0.1);

hold off;

end

% Function to convert Euler angles to rotation matrix

function R = eul2rotm(eul)

yaw = eul(1); pitch = eul(2); roll = eul(3);

Rz = [cos(yaw), -sin(yaw), 0;

sin(yaw), cos(yaw), 0;

0, 0, 1];

Ry = [cos(pitch), 0, sin(pitch);

0, 1, 0;

-sin(pitch), 0, cos(pitch)];

Rx = [1, 0, 0;

0, cos(roll), -sin(roll);

0, sin(roll), cos(roll)];

R = Rz Ry Rx;

End

```
Output:
This MATLAB script numerically integrates the Euler angle kinematic equations, computes the yaw
angle, and generates a 3D visualization of the spacecraft's orientation over time.

13. Numerical Integration of ODE Functions of Euler Parameters for YAW and 3D
Visualization of Spacecraft Motion

1. Introduction

The objective of this lab experiment is to perform numerical integration of the equations of motion
using Euler parameters (quaternions) for spacecraft attitude dynamics, specifically focusing on
plotting the yaw angle over time and visualizing the resulting 3D motion of the spacecraft.

2. Objectives

- To understand the representation of spacecraft orientation using Euler parameters (quaternions).

- To numerically integrate the quaternion kinematic equations in MATLAB.

- To plot the yaw angle from quaternion data.

- To visualize the 3D motion of the spacecraft using MATLAB.

3. Theory

Euler parameters (quaternions) are a set of four parameters used to describe the orientation of a rigid
body in three-dimensional space. They do not suffer from the singularities associated with Euler
angles and are commonly used in spacecraft attitude control.

The kinematic equations for quaternions are:


where ( q = [q0, q1, q2, q3] ) is the quaternion vector, and ( Omega ) is the angular velocity matrix
derived from the angular velocity components ( p ), ( q ), and ( r) about the body axes.

4. Apparatus/Software

- MATLAB

- Computer with MATLAB installed

5. Procedure

1. Step 1: Define angular velocity components

Specify the angular velocities ( p ), ( q ), and ( r) (body axis rates) in the spacecraft's frame.

2. Step 2: Define initial conditions

Initialize the quaternion ( q = [q0, q1, q2, q3] ) representing the spacecraft's initial orientation.

3. Step 3: Define the ODE function for quaternion kinematics

Develop the ODE function based on the quaternion differential equations.

4. Step 4: Perform numerical integration

Use MATLAB’s ODE solver (`ode45`) to numerically integrate the quaternion kinematic equations.

5. Step 5: Extract yaw angle

Calculate the yaw angle from the quaternion components using the following formula:

6. Step 6: Plot yaw over time

Plot the yaw angle as a function of time to visualize how it evolves during the motion.
7. Step 7: Visualize 3D motion

Using the quaternion data, create a 3D visualization of the spacecraft's orientation over time.

6. Observations

- Plot the yaw angle over time.

- Visualize the spacecraft's 3D orientation.

7. Conclusion

Summarize the results of the experiment, including insights on the evolution of yaw and how Euler
parameters facilitate the smooth representation of 3D orientation.

MATLAB Example Code: Numerical Integration of Euler Parameters for Yaw and 3D
Visualization

```matlab

% Define the angular velocity components (p, q, r)

omega = [0.1; 0.2; 0.3]; % Example angular velocity in rad/s

% Initial quaternion [q0, q1, q2, q3]

q0 = [1; 0; 0; 0]; % Initial orientation (unit quaternion)

% Time span

tspan = [0 10]; % From 0 to 10 seconds

% ODE function for quaternion kinematics

function dqdt = quaternion_kinematics(t, q)

omega = [0.1; 0.2; 0.3]; % Example angular velocity


p = omega(1); q_ang = omega(2); r = omega(3);

dqdt = 0.5 [-pq(2) - q_angq(3) - rq(4);

pq(1) + rq(3) - q_angq(4);

q_angq(1) - rq(2) + pq(4);

rq(1) + q_angq(2) - pq(3)];

end

% Solve the ODE

[t, q] = ode45(@quaternion_kinematics, tspan, q0);

% Compute the yaw from the quaternion

yaw = atan2(2 (q(:,2) . q(:,3) + q(:,1) . q(:,4)), q(:,1).^2 + q(:,2).^2 - q(:,3).^2 - q(:,4).^2);

% Plot the yaw over time

figure;

plot(t, yaw);

title('Yaw vs Time');

xlabel('Time (s)');

ylabel('Yaw (rad)');

% 3D visualization of the spacecraft orientation

figure;

for i = 1:length(t)

% Extract the rotation matrix from quaternion

R = quat2rotm(q(i,:));

% Plot the spacecraft body axes


plot3([0 R(1,1)], [0 R(2,1)], [0 R(3,1)], 'r', 'LineWidth', 2); hold on;

plot3([0 R(1,2)], [0 R(2,2)], [0 R(3,2)], 'g', 'LineWidth', 2);

plot3([0 R(1,3)], [0 R(2,3)], [0 R(3,3)], 'b', 'LineWidth', 2);

axis equal;

grid on;

xlabel('X'); ylabel('Y'); zlabel('Z');

title('3D Spacecraft Orientation');

pause(0.1);

hold off;

end

% Quaternion to rotation matrix conversion function

function R = quat2rotm(q)

q0 = q(1); q1 = q(2); q2 = q(3); q3 = q(4);

R = [1 - 2(q2^2 + q3^2), 2(q1q2 - q0q3), 2(q1q3 + q0q2);

2(q1q2 + q0q3), 1 - 2(q1^2 + q3^2), 2(q2q3 - q0q1);

2(q1q3 - q0q2), 2(q2q3 + q0q1), 1 - 2(q1^2 + q2^2)];

end

```

Output:
This MATLAB code performs the numerical integration of quaternion kinematic equations, computes
the yaw angle, and provides a 3D visualization of the spacecraft's orientation.

14. Numerical Integration of ODE Functions of Euler Parameters for YAW and 3D
Visualization of Spacecraft Motion

1. Introduction

The objective of this lab is to perform the numerical integration of the equations of motion using
Euler parameters (quaternions) to describe spacecraft attitude dynamics, focusing on plotting the roll
angle over time and visualizing the resulting 3D spacecraft motion.

2. Objectives

- To understand the use of Euler parameters (quaternions) in representing spacecraft orientation.

- To numerically integrate the quaternion kinematic equations using MATLAB.

- To plot the roll angle over time from quaternion data.


- To visualize the 3D motion of the spacecraft based on quaternion calculations.

3. Theory

Euler parameters, also known as quaternions, are a set of four parameters ( q0, q1, q2, q3 ) that
represent the orientation of a rigid body in three-dimensional space. They are useful for avoiding the
singularities associated with Euler angles and provide an efficient way to represent rotation.

The kinematic equation for quaternions is:

where ( q = [q0, q1, q2, q3] ) is the quaternion vector, and ( Omega ) is the angular velocity matrix
derived from the angular velocity components ( p ), ( q ), and ( r) about the body axes.

4. Apparatus/Software

- MATLAB

- Computer with MATLAB installed

5. Procedure

1. Step 1: Define angular velocity components

Specify the angular velocities ( p ), ( q ), and ( r ) representing the body axis rates of the spacecraft.

2. Step 2: Define initial conditions

Initialize the quaternion ( q = [q0, q1, q2, q3] ) to represent the initial orientation of the spacecraft.

3. Step 3: Write the ODE function for quaternion kinematics

Create the ODE function in MATLAB to model the quaternion kinematic equations.
4. Step 4: Perform numerical integration

Use MATLAB's `ode45` to integrate the quaternion differential equations over a specified time
span.

5. Step 5: Extract roll angle

From the quaternion solution, calculate the roll angle using the following formula:

6. Step 6: Plot roll over time

Plot the roll angle as a function of time to visualize how it evolves during the spacecraft’s motion.

7. Step 7: Visualize 3D motion

Using the quaternion data, generate a 3D visualization of the spacecraft’s orientation over time.

6. Observations

- Plot the roll angle over time.

- Visualize the spacecraft’s 3D motion based on the quaternion data.

7. Conclusion

Summarize the results of the experiment, discussing the evolution of roll and the benefits of using
Euler parameters for attitude representation in space.

MATLAB Example Code:

```matlab

% Define the angular velocity components (p, q, r)

omega = [0.1; 0.2; 0.3]; % Example angular velocity in rad/s

% Initial quaternion [q0, q1, q2, q3]

q0 = [1; 0; 0; 0]; % Initial orientation (unit quaternion)


% Time span

tspan = [0 10]; % From 0 to 10 seconds

% ODE function for quaternion kinematics

function dqdt = quaternion_kinematics(t, q)

omega = [0.1; 0.2; 0.3]; % Example angular velocity

p = omega(1); q_ang = omega(2); r = omega(3);

dqdt = 0.5 [-pq(2) - q_angq(3) - rq(4);

pq(1) + rq(3) - q_angq(4);

q_angq(1) - rq(2) + pq(4);

rq(1) + q_angq(2) - pq(3)];

end

% Solve the ODE

[t, q] = ode45(@quaternion_kinematics, tspan, q0);

% Compute the roll from the quaternion

roll = atan2(2 (q(:,3) . q(:,2) + q(:,1) . q(:,4)), q(:,1).^2 + q(:,2).^2 - q(:,3).^2 - q(:,4).^2);

% Plot the roll over time

figure;

plot(t, roll);

title('Roll vs Time');

xlabel('Time (s)');

ylabel('Roll (rad)');
% 3D visualization of the spacecraft orientation

figure;

for i = 1:length(t)

% Extract the rotation matrix from quaternion

R = quat2rotm(q(i,:));

% Plot the spacecraft body axes

plot3([0 R(1,1)], [0 R(2,1)], [0 R(3,1)], 'r', 'LineWidth', 2); hold on;

plot3([0 R(1,2)], [0 R(2,2)], [0 R(3,2)], 'g', 'LineWidth', 2);

plot3([0 R(1,3)], [0 R(2,3)], [0 R(3,3)], 'b', 'LineWidth', 2);

axis equal;

grid on;

xlabel('X'); ylabel('Y'); zlabel('Z');

title('3D Spacecraft Orientation');

pause(0.1);

hold off;

end

% Quaternion to rotation matrix conversion function

function R = quat2rotm(q)

q0 = q(1); q1 = q(2); q2 = q(3); q3 = q(4);

R = [1 - 2(q2^2 + q3^2), 2(q1q2 - q0q3), 2(q1q3 + q0q2);

2(q1q2 + q0q3), 1 - 2(q1^2 + q3^2), 2(q2q3 - q0q1);

2(q1q3 - q0q2), 2(q2q3 + q0q1), 1 - 2(q1^2 + q2^2)];

end

```

Output:
This MATLAB script performs the numerical integration of quaternion kinematic equations,
computes the roll angle, and generates a 3D visualization of the spacecraft's orientation over time.

15. Numerical Integration of ODE Functions of Euler Parameters for pitch and 3D
Visualization of Spacecraft Motion

1. Introduction

The aim of this experiment is to understand spacecraft attitude dynamics using Euler parameters
(quaternions) for numerical integration of ODEs. This method avoids singularities associated with
Euler angles, making it suitable for describing the orientation of a spacecraft or rigid body in space.
The experiment includes plotting the pitch angle from the quaternion data and visualizing the 3D
orientation of the spacecraft using MATLAB.

2. Objectives

- To understand the concept of Euler parameters (quaternions) and their role in representing spacecraft
orientation.
- To numerically integrate the quaternion kinematic equations using MATLAB.

- To plot the pitch angle from the quaternion data.

- To visualize the 3D motion of a spacecraft.

3. Theory

Euler parameters (quaternions) are four parameters ( q0, q1, q2, q3 ) that represent orientation without
the singularities of Euler angles. They follow the kinematic differential equation:

Where ( q = [q0, q1, q2, q3] ) is the quaternion, and ( Omega) is the angular velocity matrix derived
from the angular velocity components ( p, q, r ).

The quaternion kinematic equations are given by:

Where \( p, q, r \) are the angular velocity components in the body frame.

4. Apparatus/Software

- MATLAB

- Computer with MATLAB installed

5. Procedure

1. Step 1: Define angular velocity components


Specify the angular velocities ( p, q, r) in the body frame of the spacecraft.

2. Step 2: Define initial conditions

Initialize the quaternion ( q = [q0, q1, q2, q3]) representing the spacecraft's initial orientation.

3. Step 3: Define the ODE function for quaternion kinematics

Write the ODE function based on quaternion differential equations using MATLAB.

4. Step 4: Perform numerical integration

Use MATLAB's `ode45` function to solve the quaternion kinematic equations over a time span.

5. Step 5: Extract pitch angle

From the quaternion solution, calculate the pitch angle using the equation:

6. Step 6: Plot pitch over time

Plot the pitch angle as a function of time.

7. Step 7: Visualize 3D motion

Using MATLAB, create a 3D visualization of the spacecraft's motion by transforming the


quaternion data into rotation matrices.

6. Observations

- Plot the variation of pitch angle with time.

- Visualize the spacecraft’s 3D orientation in space.

7. Conclusion

Summarize the behavior of the spacecraft's attitude and the advantages of using Euler parameters for
representing orientation in space.
MATLAB Example Code:

```matlab

% Define the angular velocity components (p, q, r)

omega = [0.1; 0.2; 0.3]; % Example angular velocity in rad/s

% Initial quaternion [q0, q1, q2, q3]

q0 = [1; 0; 0; 0]; % Initial orientation (unit quaternion)

% Time span

tspan = [0 10]; % From 0 to 10 seconds

% ODE function for quaternion kinematics

function dqdt = quaternion_kinematics(t, q)

omega = [0.1; 0.2; 0.3]; % Example angular velocity

p = omega(1); q_ang = omega(2); r = omega(3);

dqdt = 0.5 [-pq(2) - q_angq(3) - rq(4);

pq(1) + rq(3) - q_angq(4);

q_angq(1) - rq(2) + pq(4);

rq(1) + q_angq(2) - pq(3)];

end

% Solve the ODE

[t, q] = ode45(@quaternion_kinematics, tspan, q0);

% Compute the pitch from the quaternion

pitch = asin(2 (q(:,3) . q(:,4) + q(:,1) . q(:,2)));


% Plot the pitch over time

figure;

plot(t, pitch);

title('Pitch vs Time');

xlabel('Time (s)');

ylabel('Pitch (rad)');

% 3D visualization of the spacecraft orientation

figure;

for i = 1:length(t)

% Extract the rotation matrix from quaternion

R = quat2rotm(q(i,:));

% Plot the spacecraft body axes

plot3([0 R(1,1)], [0 R(2,1)], [0 R(3,1)], 'r', 'LineWidth', 2); hold on;

plot3([0 R(1,2)], [0 R(2,2)], [0 R(3,2)], 'g', 'LineWidth', 2);

plot3([0 R(1,3)], [0 R(2,3)], [0 R(3,3)], 'b', 'LineWidth', 2);

axis equal;

grid on;

xlabel('X'); ylabel('Y'); zlabel('Z');

title('3D Spacecraft Orientation');

pause(0.1);

hold off;

end

% Quaternion to rotation matrix conversion function

function R = quat2rotm(q)
q0 = q(1); q1 = q(2); q2 = q(3); q3 = q(4);

R = [1 - 2(q2^2 + q3^2), 2(q1q2 - q0q3), 2(q1q3 + q0q2);

2(q1q2 + q0q3), 1 - 2(q1^2 + q3^2), 2(q2q3 - q0q1);

2(q1q3 - q0q2), 2(q2q3 + q0q1), 1 - 2(q1^2 + q2^2)];

end

```

Output:
This MATLAB code numerically integrates the quaternion kinematic equations, computes the pitch
angle, and provides a 3D visualization of the spacecraft's orientation.

You might also like