Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spacecraft orientation determination #21

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- [x] Impulse Maneuvers
- [x] Phase Maneuvers
- [x] Plane Change Maneuvers
- [x] Orientation Determination

#### Astronomical

Expand Down Expand Up @@ -80,6 +81,8 @@ exe.root_module.addImport("astroz", astroz_mod);

- #### [Orbit Phase Change](examples/orbit_phase_change.zig)

- #### [Orbit Orientation Determination](examples/simple_spacecraft_orientation.zig)

- #### [Parse Vita49](examples/parse_vita49.zig)

- #### [Parse Vita49 with Callback](examples/parse_vita49_callback.zig)
Expand Down
65 changes: 65 additions & 0 deletions examples/simple_spacecraft_orientation.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const std = @import("std");
const astroz = @import("astroz");
const constants = astroz.constants;
const TLE = astroz.tle.TLE;
const spacecraft = astroz.spacecraft;
const Spacecraft = spacecraft.Spacecraft;

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();

const raw_tle =
\\1 55909U 23035B 24187.51050877 .00023579 00000+0 16099-2 0 9998
\\2 55909 43.9978 311.8012 0011446 278.6226 81.3336 15.05761711 71371
;
var test_tle = try TLE.parse(raw_tle, allocator);
defer test_tle.deinit();
var sc = Spacecraft.init("dummy_sc", test_tle, 300.000, spacecraft.SatelliteSize.Cube, constants.earth, allocator);
defer sc.deinit();

sc.angular_velocity = .{ 0.0, 0.0, 0.0 };

const dt = 120.0; // 2 mins time step
const simulation_time = 3 * 24 * 60 * 60.0; // 3 days in seconds
const orbital_period = 90 * 60.0; // 90 minutes orbital period
var t: f64 = 0;

while (t < simulation_time) : (t += dt) {
// Simulate a dramatic torque effect
const torque_x = 0.001 * @sin(2 * std.math.pi * t / (orbital_period * 2));
const torque_y = 0.0005 * @cos(2 * std.math.pi * t / (orbital_period * 3));
const torque_z = 0.0002 * @sin(2 * std.math.pi * t / orbital_period);

// Update angular velocity based on torque (simplified)
sc.angular_velocity[0] += torque_x * dt;
sc.angular_velocity[1] += torque_y * dt;
sc.angular_velocity[2] += torque_z * dt;

// Update attitude
sc.updateAttitude();
sc.propagateAttitude(dt);

// Simulate simple circular orbit
const orbit_radius = 7000.0;
const x = orbit_radius * @cos(2 * std.math.pi * t / orbital_period);
const y = orbit_radius * @sin(2 * std.math.pi * t / orbital_period);
const z = 0.0;

std.log.debug("Showing orbiting info: {d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d}\n", .{
t,
sc.quaternion[0],
sc.quaternion[1],
sc.quaternion[2],
sc.quaternion[3],
sc.angular_velocity[0],
sc.angular_velocity[1],
sc.angular_velocity[2],
x,
y,
z,
});
}
}

Loading