Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
friend0 committed Nov 17, 2024
1 parent 4f55f5b commit d5e6980
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 157 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ rayon = "1.10.0"
rand_chacha = "0.3.1"
tokio = { version = "1.41.0", features = ["full"] }
binrw = "0.14.1"
cyber_rc = { git = "https://github.com/friend0/CyberRC.git" }
cyber_rc = { git = "https://github.com/friend0/CyberRC.git", rev = "2d842110d6e0" }
serialport = "4.6.0"
tempfile = "3.14.0"
prost = "0.13.3"
4 changes: 2 additions & 2 deletions config/liftoff_quad.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use_rerun: true # Enable visualization using rerun.io
use_rerun: false # Enable visualization using rerun.io
render_depth: true # Enable rendering depth
use_multithreading_depth_rendering: true # Enable multithreading for depth rendering for large resolution (above 32x24)
real_time: true # Enable real time mode. If not enabled, sim will run in fast time.
Expand All @@ -23,7 +23,7 @@ quadrotor:
max_thrust_kg: .5
arm_length_m: .065
yaw_torque_constant: .0052
serial_port: null
serial_port: "/dev/tty.usbserial-B001JE6N"

pid_controller:
pos_gains: # PID gains for position control
Expand Down
8 changes: 0 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ impl QuadrotorConfig {
"Failed to invert inertia matrix".to_string(),
))?)
}

/// Calculate all maximum torques and return them as a tuple
pub fn max_torques(&self) -> (f32, f32, f32) {
let motor_thrust = self.max_thrust_kg / 4.0;
let max_rp_torque = 2.0 * self.arm_length_m * motor_thrust;
let yaw_torque = 2.0 * self.yaw_torque_constant * motor_thrust;
(max_rp_torque, max_rp_torque, yaw_torque)
}
}

#[derive(Clone, Debug, serde::Deserialize)]
Expand Down
15 changes: 14 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use rand::SeedableRng;
use rayon::prelude::*;
pub mod config;
pub mod quadrotor;
use nalgebra::{Matrix3, Quaternion, Rotation3, SMatrix, UnitQuaternion, Vector3};
use nalgebra::{Matrix3, Quaternion, Rotation3, SMatrix, UnitQuaternion, Vector, Vector3};
use quadrotor::{QuadrotorInterface, QuadrotorState};
use rand_chacha::ChaCha8Rng;
use rand_distr::{Distribution, Normal};
Expand Down Expand Up @@ -143,6 +143,7 @@ impl QuadrotorInterface for Quadrotor {
}
Ok(())
}

fn observe(&mut self) -> Result<QuadrotorState, SimulationError> {
return Ok(QuadrotorState {
position: self.position,
Expand All @@ -153,6 +154,18 @@ impl QuadrotorInterface for Quadrotor {
});
}

fn max_thrust(&self) -> f32 {
2.5 * self.gravity
}

// TDO: need a method to retrieve quadrotor physical constants
fn max_torque(&self) -> Vector3<f32> {
let motor_thrust = self.max_thrust() / 4.0;
let max_rp_torque = 2.0 * 0.65 * motor_thrust;
let yaw_torque = 2.0 * 0.005 * motor_thrust;
Vector3::new(max_rp_torque, max_rp_torque, yaw_torque)
}

//TODO: replace this method in main with observe
/// Simulates IMU readings
/// # Returns
Expand Down
Loading

0 comments on commit d5e6980

Please sign in to comment.