really basic and bad NON PID controller

This commit is contained in:
Franchioping 2025-12-09 15:47:53 +00:00
parent 3e331d9b83
commit 937a203e15
3 changed files with 24 additions and 7 deletions

View File

@ -1,7 +1,7 @@
use macroquad::prelude::*; use macroquad::prelude::*;
const MOVE_SPEED: f32 = 1.0; const MOVE_SPEED: f32 = 1.0;
const LOOK_SPEED: f32 = 0.1; const LOOK_SPEED: f32 = 0.01;
pub struct FirstPersonCamera { pub struct FirstPersonCamera {
pub position: Vec3, pub position: Vec3,

View File

@ -4,6 +4,7 @@ use rapier3d::prelude as rp;
use crate::engine::{ColliderExtraData, World}; use crate::engine::{ColliderExtraData, World};
pub mod controller; pub mod controller;
pub mod fpvcontroller;
use controller::*; use controller::*;
pub struct MotorCharacteristics { pub struct MotorCharacteristics {
@ -17,6 +18,9 @@ impl Default for MotorCharacteristics {
Self { Self {
/* /*
* Motor position indices * Motor position indices
* ^ - Front
* |
* |
* 1 --- 0 * 1 --- 0
* | | * | |
* | | * | |
@ -125,6 +129,8 @@ impl Drone {
rp::vector![0.0, -torque, 0.0] rp::vector![0.0, -torque, 0.0]
}; };
drone_rb.add_torque(torque, true); drone_rb.add_torque(torque, true);
println!("Torque: \n{:?}", torque);
println!("Thrust: \n{:?}", thrust);
} }
} }

View File

@ -10,7 +10,7 @@ mod rendering;
mod graphics_util; mod graphics_util;
use crate::rendering::Renderer; use crate::{drone::fpvcontroller::JoystickInput, rendering::Renderer};
fn window_conf() -> mq::Conf { fn window_conf() -> mq::Conf {
mq::Conf { mq::Conf {
@ -18,7 +18,7 @@ fn window_conf() -> mq::Conf {
window_resizable: true, window_resizable: true,
// fullscreen: true, // fullscreen: true,
platform: mq::miniquad::conf::Platform { platform: mq::miniquad::conf::Platform {
linux_backend: mq::miniquad::conf::LinuxBackend::WaylandOnly, // linux_backend: mq::miniquad::conf::LinuxBackend::WaylandOnly,
..Default::default() ..Default::default()
}, },
..Default::default() ..Default::default()
@ -44,11 +44,19 @@ async fn main() {
None, None,
); );
let mut controller = drone::fpvcontroller::FPVController::default();
controller.set_input(JoystickInput {
throttle_input: 0.25,
yaw_input: 0.0,
roll_input: 0.0,
pitch_input: 0.05,
});
let mut drone = drone::Drone::new( let mut drone = drone::Drone::new(
&mut world, &mut world,
Box::new(drone::controller::DefaultController::new(1.0)), Box::new(controller),
drone::MotorCharacteristics { drone::MotorCharacteristics {
max_thrust: 2.0 * 3.5 * 0.25, max_thrust: 20.0,
max_torque: 2.0,
..Default::default() ..Default::default()
}, },
0.350, 0.350,
@ -76,13 +84,16 @@ async fn main() {
// Physics // Physics
world.step(); world.step();
drone.process_tick(&mut world);
let _ = clearscreen::clear(); let _ = clearscreen::clear();
drone.process_tick(&mut world);
println!( println!(
"{:}", "{:}",
world.bodies.get(drone.rb_handle).unwrap().translation() world.bodies.get(drone.rb_handle).unwrap().translation()
); );
println!("{:?}", drone.controller.get_motor_throttles()); println!(
"Motor Throttles: {:?}",
drone.controller.get_motor_throttles()
);
// Rendering // Rendering
renderer.draw(&mut world); renderer.draw(&mut world);