Add propeller spin direction
This commit is contained in:
parent
6862712551
commit
78f5db1a9e
4 changed files with 11 additions and 1 deletions
|
|
@ -1 +1,6 @@
|
||||||
pub const g: f64 = 9.80665;
|
pub const g: f64 = 9.80665;
|
||||||
|
|
||||||
|
pub const PropSpinDirection = enum(i8) {
|
||||||
|
cw = 1,
|
||||||
|
ccw = -1,
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
const vec3 = @import("./vec3.zig");
|
const vec3 = @import("./vec3.zig");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const constants = @import("./constants.zig");
|
||||||
|
|
||||||
pub const Drone = struct {
|
pub const Drone = struct {
|
||||||
mass_kg: f64,
|
mass_kg: f64,
|
||||||
|
|
@ -19,6 +20,7 @@ pub const Propeller = struct {
|
||||||
angular_velocity: f64,
|
angular_velocity: f64,
|
||||||
thrust_coefficient: f64,
|
thrust_coefficient: f64,
|
||||||
moment_coefficient: f64,
|
moment_coefficient: f64,
|
||||||
|
direction: constants.PropSpinDirection,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const QuadCopterSim = struct {
|
pub const QuadCopterSim = struct {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ pub fn propThrust(attitude: vec3.QuatF64, p: drone.Propeller) struct { vec3.Vec3
|
||||||
const drag_moment = vec3.Vec3F64.init(
|
const drag_moment = vec3.Vec3F64.init(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
p.moment_coefficient * p.angular_velocity * p.angular_velocity,
|
@intFromEnum(p.direction) * p.moment_coefficient * p.angular_velocity * p.angular_velocity,
|
||||||
);
|
);
|
||||||
|
|
||||||
return .{ force, vec3.vec3Add(force_moment, drag_moment) };
|
return .{ force, vec3.vec3Add(force_moment, drag_moment) };
|
||||||
|
|
@ -55,6 +55,7 @@ test "thrust is correct" {
|
||||||
.angular_velocity = 100,
|
.angular_velocity = 100,
|
||||||
.thrust_coefficient = 1,
|
.thrust_coefficient = 1,
|
||||||
.moment_coefficient = 2,
|
.moment_coefficient = 2,
|
||||||
|
.direction = constants.PropSpinDirection.cw,
|
||||||
};
|
};
|
||||||
|
|
||||||
const expected_thrust_mag = -100 * 100;
|
const expected_thrust_mag = -100 * 100;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
const drone = @import("./drone.zig");
|
const drone = @import("./drone.zig");
|
||||||
const vec3 = @import("./vec3.zig");
|
const vec3 = @import("./vec3.zig");
|
||||||
const forces = @import("./forces.zig");
|
const forces = @import("./forces.zig");
|
||||||
|
const constants = @import("constants.zig");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub fn timestep(dt: f64, d: drone.Drone, props: []const drone.Propeller, s: *drone.State) void {
|
pub fn timestep(dt: f64, d: drone.Drone, props: []const drone.Propeller, s: *drone.State) void {
|
||||||
|
|
@ -62,6 +63,7 @@ test "Validate timesteps" {
|
||||||
.cg_to_prop = .init(1, 0, 0),
|
.cg_to_prop = .init(1, 0, 0),
|
||||||
.moment_coefficient = 0.1,
|
.moment_coefficient = 0.1,
|
||||||
.thrust_coefficient = 0.5,
|
.thrust_coefficient = 0.5,
|
||||||
|
.direction = constants.PropSpinDirection.cw,
|
||||||
};
|
};
|
||||||
const props: [1]drone.Propeller = .{prop};
|
const props: [1]drone.Propeller = .{prop};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue