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

Fix acceleration reading from IMU #10

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add acceleration update in rk4
  • Loading branch information
makeecat committed Nov 5, 2024
commit f34ebc37ae12da2206a2c4486fef69357a4e2eea
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl Quadrotor {
/// let derivative = quadrotor.state_derivative(&state, control_thrust, &control_torque);
/// ```
pub fn state_derivative(
&self,
&mut self,
state: &[f32],
control_thrust: f32,
control_torque: &Vector3<f32>,
Expand All @@ -301,15 +301,15 @@ impl Quadrotor {
let gravity_force = Vector3::new(0.0, 0.0, -self.mass * self.gravity);
let drag_force = -self.drag_coefficient * velocity.norm() * velocity;
let thrust_world = orientation * Vector3::new(0.0, 0.0, control_thrust);
let acceleration = (thrust_world + gravity_force + drag_force) / self.mass;
self.acceleration = (thrust_world + gravity_force + drag_force) / self.mass;

let inertia_angular_velocity = self.inertia_matrix * angular_velocity;
let gyroscopic_torque = angular_velocity.cross(&inertia_angular_velocity);
let angular_acceleration = self.inertia_matrix_inv * (control_torque - gyroscopic_torque);

let mut derivative = [0.0; 13];
derivative[0..3].copy_from_slice(velocity.as_slice());
derivative[3..6].copy_from_slice(acceleration.as_slice());
derivative[3..6].copy_from_slice(self.acceleration.as_slice());
derivative[6..10].copy_from_slice(q_dot.coords.as_slice());
derivative[10..13].copy_from_slice(angular_acceleration.as_slice());
derivative
Expand Down