← Projects

Lunar CubeSat simulation / AEM 4305 · 2026

How does a spacecraft turn from photographing the Moon to relaying data and then recharging its batteries?

Explore the pointing modes
Lunar nadir Camera · +b₁ Illustrative geometry · Target directions shown in a common view
0–2,500 s

Keep the camera facing the Moon.

The camera looks out along the positive first body axis. As the spacecraft travels around the Moon, the controller turns this face toward the lunar center so the camera looks down at the surface.

Gateway Antenna · −b₁ Illustrative geometry · Target directions shown in a common view
2,500–5,000 s

Aim the antenna at Gateway.

The antenna sits opposite the camera. The reference direction now follows the line from the CubeSat to Gateway, so the controller turns the antenna face toward the relay target.

Sun Solar panel · +b₂ shown Illustrative geometry · Target directions shown in a common view
5,000–7,500 s

Turn a solar panel into sunlight.

The solar panels occupy the two faces perpendicular to the second body axis. For recharge, the spacecraft turns a panel’s outward normal toward the Sun.

Implementation

Building the MATLAB model

Start with the body frame

I defined the geometry of a 4 kg, MinXSS-inspired spacecraft and assigned an axis to each pointing task. I wrote and checked conversions between direction cosine matrices, quaternions and 3-2-1 Euler angles so the orbit, sensors and controller could share a consistent frame.

Original sketch of the 10 by 10 by 30 cm body, with a centered origin, opposing camera and antenna, and panel locations on the second axis.
Fig. 1 Body frame and payload layoutExpand ↗

Couple translation and rotation

I integrated a two-body lunar orbit with MATLAB’s ode45, then propagated angular velocity with Euler’s rigid-body equations and attitude with quaternion kinematics. I joined the two models and added gravity-gradient torque so the spacecraft’s orientation and position both affected the rotational dynamics.

Estimate attitude and close the loop

I used TRIAD to estimate orientation from noisy Sun-sensor and lunar-horizon measurements. I built moving reference frames for the three targets, tested a detumble controller and used gyro feedback and gravity-gradient compensation to command torque during pointing.

Verification

Check what should stay constant

In a two-body orbit, total orbital energy should stay constant. I plotted the difference from its initial value over 12,000 seconds. At a solver tolerance of 10⁻² the energy drifts downward. The 10⁻⁶ and 10⁻¹² traces overlap near zero at the scale shown.

Energy change versus seconds. The 10⁻² tolerance curve drifts down toward −3.5 kg km²/s² by 12,000 s. The tighter curves overlap near zero.
Fig. 3 Orbital energy errorExpand ↗

I made a separate conservation check with gravity-gradient and control torques switched off. Rotational kinetic energy should remain constant as angular velocity changes in the body frame. I also checked quaternion magnitude during propagation.

Simulation results

The 7,500-second mission

I carried the final state of each phase into the next. At each handoff the spacecraft kept its attitude and angular velocity while the controller received a new pointing reference.

0–2,500 sImagingCamera → Lunar nadir
2,500–5,000 sRelayAntenna → Gateway
5,000–7,500 sRechargeSolar panel → Sun
Three torque components in newton-metres versus time in seconds, with brief excursions at startup, both dashed phase boundaries and within phases.
Fig. 23 Control torque through the missionExpand ↗

When the controller worked hardest

Figure 23 shows the three commanded torque components in N·m. Short bursts appear at startup and at the dashed switches at 2,500 and 5,000 seconds. Additional spikes occur within the relay and recharge phases. Between bursts the commands lie close to zero on this scale.

Scalar and three vector components of the attitude-error quaternion. Large transient excursions recover toward scalar one and smaller vector components. The source crop omits the horizontal tick labels.
Fig. 24 Reference error quaternionExpand ↗

How the pointing error evolved

Figure 24 shows the dimensionless scalar and three vector components of the error quaternion. The scalar returns toward one after large excursions, while the vector components shrink with some residual offsets. The original image crops the time-axis labels. Figure 23 supplies the phase timing.

Assumptions

Reading the results

The model treats the spacecraft as a rigid body in a two-body lunar orbit with gravity-gradient torque, modeled actuators and simulated sensor noise. Gateway position data and a Sun direction define the relay and recharge targets.

The plots describe simulated attitude error and control effort. Assessing image quality, data throughput or battery charge would require separate payload, link or power models.

← All projects

Open original image ↗