Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/ans-33
Browse files Browse the repository at this point in the history
  • Loading branch information
ATTron committed Jul 16, 2024
2 parents 197c9fe + 2170cbe commit 46b9f00
Show file tree
Hide file tree
Showing 28 changed files with 3,732 additions and 1,174 deletions.
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 @@ -84,6 +85,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
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@ const EXAMPLE_NAMES = &.{
"parse_vita49_callback",
"parse_vita49",
"precess_star",
"simple_spacecraft_orientation",
};
4 changes: 2 additions & 2 deletions examples/create_ccsds_packet.zig
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const std = @import("std");
const astroz = @import("astroz");
const CCSDS = astroz.ccsds.CCSDS;
const Ccsds = astroz.Ccsds;

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

const raw_test_packet: [16]u8 = .{ 0x78, 0x97, 0xC0, 0x00, 0x00, 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A };
var converted_test_packet = try CCSDS.init(&raw_test_packet, allocator, null);
var converted_test_packet = try Ccsds.init(&raw_test_packet, allocator, null);
defer converted_test_packet.deinit();

std.debug.print("CCSDS Packet Created:\n{any}", .{converted_test_packet});
Expand Down
9 changes: 4 additions & 5 deletions examples/create_ccsds_packet_config.zig
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const std = @import("std");
const astroz = @import("astroz");
const ccsds = astroz.ccsds;
const CCSDS = ccsds.CCSDS;
const Config = ccsds.Config;
const Ccsds = astroz.Ccsds;
const Config = Ccsds.Config;

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
Expand All @@ -12,10 +11,10 @@ pub fn main() !void {
const config_file = try std.fs.cwd().readFileAlloc(allocator, "examples/create_ccsds_packet_config.json", 512);
defer allocator.free(config_file);

const config = try ccsds.parseConfig(config_file, allocator);
const config = try Ccsds.parseConfig(config_file, allocator);

const raw_test_packet: [16]u8 = .{ 0x78, 0x97, 0xC0, 0x00, 0x00, 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A };
var converted_test_packet = try CCSDS.init(&raw_test_packet, allocator, config);
var converted_test_packet = try Ccsds.init(&raw_test_packet, allocator, config);
defer converted_test_packet.deinit();

std.debug.print("\nCCSDS Packet Created:\n{any}", .{converted_test_packet});
Expand Down
11 changes: 5 additions & 6 deletions examples/orbit_phase_change.zig
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const std = @import("std");
const math = std.math;
const astroz = @import("astroz");
const TLE = astroz.tle.TLE;
const Tle = astroz.Tle;
const Impulse = Spacecraft.Impulse;
const constants = astroz.constants;
const Impulse = spacecraft.Impulse;
const spacecraft = astroz.spacecraft;
const Spacecraft = spacecraft.Spacecraft;
const Spacecraft = astroz.Spacecraft;

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
Expand All @@ -17,10 +16,10 @@ pub fn main() !void {
\\2 55909 43.9978 311.8012 0011446 278.6226 81.3336 15.05761711 71371
;

var tle = try TLE.parse(test_tle, allocator);
var tle = try Tle.parse(test_tle, allocator);
defer tle.deinit();

var test_sc = Spacecraft.init("dummy_sc", tle, 300.000, spacecraft.SatelliteSize.Cube, constants.earth, allocator);
var test_sc = Spacecraft.init("dummy_sc", tle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
defer test_sc.deinit();

const phase_maneuver = Impulse{
Expand Down
11 changes: 5 additions & 6 deletions examples/orbit_plane_change.zig
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const std = @import("std");
const math = std.math;
const astroz = @import("astroz");
const TLE = astroz.tle.TLE;
const Tle = astroz.Tle;
const constants = astroz.constants;
const Impulse = spacecraft.Impulse;
const spacecraft = astroz.spacecraft;
const Spacecraft = spacecraft.Spacecraft;
const Impulse = Spacecraft.Impulse;
const Spacecraft = astroz.Spacecraft;

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
Expand All @@ -17,10 +16,10 @@ pub fn main() !void {
\\2 55909 43.9978 311.8012 0011446 278.6226 81.3336 15.05761711 71371
;

var tle = try TLE.parse(test_tle, allocator);
var tle = try Tle.parse(test_tle, allocator);
defer tle.deinit();

var test_sc = Spacecraft.init("dummy_sc", tle, 300.000, spacecraft.SatelliteSize.Cube, constants.earth, allocator);
var test_sc = Spacecraft.init("dummy_sc", tle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
defer test_sc.deinit();

const plane_change_maneuver = Impulse{
Expand Down
9 changes: 4 additions & 5 deletions examples/orbit_prop.zig
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const std = @import("std");
const math = std.math;
const astroz = @import("astroz");
const TLE = astroz.tle.TLE;
const Tle = astroz.Tle;
const constants = astroz.constants;
const spacecraft = astroz.spacecraft;
const Spacecraft = spacecraft.Spacecraft;
const Spacecraft = astroz.Spacecraft;

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
Expand All @@ -16,10 +15,10 @@ pub fn main() !void {
\\2 55909 43.9978 311.8012 0011446 278.6226 81.3336 15.05761711 71371
;

var tle = try TLE.parse(test_tle, allocator);
var tle = try Tle.parse(test_tle, allocator);
defer tle.deinit();

var test_sc = Spacecraft.init("dummy_sc", tle, 300.000, spacecraft.SatelliteSize.Cube, constants.earth, allocator);
var test_sc = Spacecraft.init("dummy_sc", tle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
defer test_sc.deinit();

try test_sc.propagate(
Expand Down
11 changes: 5 additions & 6 deletions examples/orbit_prop_impulse.zig
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const std = @import("std");
const math = std.math;
const astroz = @import("astroz");
const TLE = astroz.tle.TLE;
const Tle = astroz.Tle;
const constants = astroz.constants;
const spacecraft = astroz.spacecraft;
const Spacecraft = spacecraft.Spacecraft;
const Spacecraft = astroz.Spacecraft;

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
Expand All @@ -16,13 +15,13 @@ pub fn main() !void {
\\2 55909 43.9978 311.8012 0011446 278.6226 81.3336 15.05761711 71371
;

var tle = try TLE.parse(test_tle, allocator);
var tle = try Tle.parse(test_tle, allocator);
defer tle.deinit();

var test_sc = Spacecraft.init("dummy_sc", tle, 300.000, spacecraft.SatelliteSize.Cube, constants.earth, allocator);
var test_sc = Spacecraft.init("dummy_sc", tle, 300.000, Spacecraft.SatelliteSize.Cube, constants.earth, allocator);
defer test_sc.deinit();

const impulses = [_]spacecraft.Impulse{
const impulses = [_]Spacecraft.Impulse{
.{ .time = 3600.0, .delta_v = .{ 0.05, 0.03, 0.01 }, .mode = .Absolute },
.{ .time = 7200.0, .delta_v = .{ 1.1, -0.05, 0.02 }, .mode = .Absolute },
.{ .time = 10800.0, .delta_v = .{ -0.03, 0.08, -0.01 }, .mode = .Absolute },
Expand Down
6 changes: 3 additions & 3 deletions examples/parse_ccsds.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const std = @import("std");
const astroz = @import("astroz");
const CCSDS = astroz.ccsds.CCSDS;
const Parser = astroz.parsers.Parser;
const Ccsds = astroz.Ccsds;
const Parser = astroz.Parser;

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
Expand All @@ -10,7 +10,7 @@ pub fn main() !void {

const file_name = "./test/ccsds.bin".*;

const P = Parser(CCSDS);
const P = Parser(Ccsds);
var parser = try P.init(null, null, 1024, allocator);
defer parser.deinit();

Expand Down
6 changes: 3 additions & 3 deletions examples/parse_ccsds_file_sync.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const std = @import("std");
const astroz = @import("astroz");
const CCSDS = astroz.ccsds.CCSDS;
const Parser = astroz.parsers.Parser;
const Ccsds = astroz.Ccsds;
const Parser = astroz.Parser;

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
Expand All @@ -11,7 +11,7 @@ pub fn main() !void {
const file_name = "./test/ccsds.bin".*;
const sync_pattern = .{ 0x78, 0x97, 0xC0, 0x00, 0x00, 0x0A, 0x01, 0x02 };

const P = Parser(CCSDS);
const P = Parser(Ccsds);
var parser = try P.init(null, null, 1024, allocator);
defer parser.deinit();

Expand Down
4 changes: 2 additions & 2 deletions examples/parse_tle.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");
const astroz = @import("astroz");
const TLE = astroz.tle.TLE;
const Tle = astroz.Tle;

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
Expand All @@ -12,7 +12,7 @@ pub fn main() !void {
\\2 55909 43.9978 311.8012 0011446 278.6226 81.3336 15.05761711 71371
;

var tle = try TLE.parse(test_tle, allocator);
var tle = try Tle.parse(test_tle, allocator);
defer tle.deinit();

tle.output();
Expand Down
4 changes: 2 additions & 2 deletions examples/parse_vita49.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const std = @import("std");
const astroz = @import("astroz");
const Vita49 = astroz.vita49.Vita49;
const Parser = astroz.parsers.Parser;
const Vita49 = astroz.Vita49;
const Parser = astroz.Parser;

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
Expand Down
4 changes: 2 additions & 2 deletions examples/parse_vita49_callback.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const std = @import("std");
const astroz = @import("astroz");
const Vita49 = astroz.vita49.Vita49;
const Parser = astroz.parsers.Parser;
const Vita49 = astroz.Vita49;
const Parser = astroz.Parser;

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
Expand Down
10 changes: 5 additions & 5 deletions examples/precess_star.zig
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const std = @import("std");
const astroz = @import("astroz");
const Datetime = astroz.time.Datetime;
const coordinates = astroz.coordinates;
const Datetime = astroz.Datetime;
const EquatorialCoordinateSystem = astroz.EquatorialCoordinateSystem;

pub fn main() !void {
const declination = coordinates.Declination.init(40, 10, 10);
const ra = coordinates.RightAscension.init(19, 52, 2);
const j2000 = coordinates.EquatorialCoordinateSystem.init(declination, ra);
const declination = EquatorialCoordinateSystem.Declination.init(40, 10, 10);
const ra = EquatorialCoordinateSystem.RightAscension.init(19, 52, 2);
const j2000 = EquatorialCoordinateSystem.init(declination, ra);

std.debug.print("Precessed to July 30, 2005:\n{any}", .{j2000.precess(Datetime.initDate(2005, 7, 30))});
}
63 changes: 63 additions & 0 deletions examples/simple_spacecraft_orientation.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const std = @import("std");
const astroz = @import("astroz");
const Tle = astroz.Tle;
const constants = astroz.constants;
const Spacecraft = astroz.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

0 comments on commit 46b9f00

Please sign in to comment.