We finally have the first iteration of a counter

This commit is contained in:
Robert Schauklies 2026-03-07 20:59:32 +01:00
parent 808b44b1f4
commit 94f28e0034

View file

@ -43,12 +43,16 @@ use crate::dc_driver::dshot;
use crate::peripherals::ErrCommand; use crate::peripherals::ErrCommand;
use esp_hal::rmt::RxChannelConfig; use esp_hal::rmt::RxChannelConfig;
use esp_hal::rmt::RxChannelCreator; use esp_hal::rmt::RxChannelCreator;
use esp_hal::timer::timg::TimerGroup;
use esp_hal::timer::OneShotTimer;
use esp_hal::timer::Timer;
#[panic_handler] #[panic_handler]
fn panic(panic: &core::panic::PanicInfo) -> ! { fn panic(panic: &core::panic::PanicInfo) -> ! {
rprintln!("{}",panic.message()); rprintln!("{}",panic.message());
let trace = Backtrace::capture(); let trace = Backtrace::capture();
loop { loop {
// rprintln!("{}",panic.location().unwrap()) rprintln!("{}",panic.location().unwrap())
} }
} }
use alloc::format; use alloc::format;
@ -138,8 +142,13 @@ fn main() -> ! {
dshot_esc.arm(); dshot_esc.arm();
let mut rpm = 0; let mut rpm = 0;
let mut control: f32 = 200.0; let mut control: f32 = 200.0;
// let timestamp = Instant::now(); let mut timg0 = TimerGroup::new(peripherals.TIMG0);
loop { let timer0 = timg0.timer0;
// let now =timer.now();
//we need the explicit type here!
timer0.load_value(esp_hal::time::Duration::from_secs(10));
timer0.start();
while !timer0.is_interrupt_set() {
dshot_esc.process(); dshot_esc.process();
//let control_val = dc_driver:: //let control_val = dc_driver::
//this bad boy needs floats, this will be fun :) //this bad boy needs floats, this will be fun :)
@ -150,7 +159,7 @@ fn main() -> ! {
x x
} }
None => { None => {
rprintln!("NO RPM!"); // rprintln!("NO RPM!");
rpm rpm
} }
}; };
@ -160,9 +169,10 @@ fn main() -> ! {
let timestamp = esp_hal::time::Instant::now().duration_since_epoch().as_millis(); let timestamp = esp_hal::time::Instant::now().duration_since_epoch().as_millis();
(control, ctx) = controller.compute(ctx, rpm as _, set_point as _, Millis(timestamp), None); (control, ctx) = controller.compute(ctx, rpm as _, set_point as _, Millis(timestamp), None);
let dumped_context = ctx.last_time().expect("LAST TIME!"); let dumped_context = ctx.last_time().expect("LAST TIME!");
rprintln!("control:{},rpm:{}", control,rpm); // rprintln!("control:{},rpm:{}", control,rpm);
} }
rprintln!("Coating done!");
dshot_esc.set_throttle(0);
// rprintln!("RMT SENT!"); // rprintln!("RMT SENT!");
// let mut esc = AfroEsc::new(&mut pwm_pin);; // let mut esc = AfroEsc::new(&mut pwm_pin);;
// esc.set_timestamp(1000); // esc.set_timestamp(1000);