slight refactoring, also fuck that
This commit is contained in:
parent
94f28e0034
commit
2d8de20d57
1 changed files with 25 additions and 24 deletions
|
|
@ -12,18 +12,18 @@ use esp_hal::delay::Delay;
|
||||||
use esp_hal::uart::{Config, Uart};
|
use esp_hal::uart::{Config, Uart};
|
||||||
use esp_hal::{gpio, main};
|
use esp_hal::{gpio, main};
|
||||||
|
|
||||||
|
use core::fmt::Debug;
|
||||||
use esp_hal::gpio::{Event, OutputConfig};
|
use esp_hal::gpio::{Event, OutputConfig};
|
||||||
use esp_hal::gpio::{Input, InputConfig};
|
use esp_hal::gpio::{Input, InputConfig};
|
||||||
use esp_hal::handler;
|
use esp_hal::handler;
|
||||||
use esp_hal::rmt::{Rmt, TxChannelConfig, TxChannelCreator};
|
use esp_hal::rmt::{Rmt, TxChannelConfig, TxChannelCreator};
|
||||||
use esp_hal::time::{ Instant, Rate};
|
use esp_hal::time::{Instant, Rate};
|
||||||
use core::fmt::Debug;
|
|
||||||
//pid-controller
|
//pid-controller
|
||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
use discrete_pid::pid::PidContext;
|
use discrete_pid::pid::PidContext;
|
||||||
|
use discrete_pid::time::InstantLike;
|
||||||
use discrete_pid::time::Millis;
|
use discrete_pid::time::Millis;
|
||||||
use discrete_pid::{pid, time};
|
use discrete_pid::{pid, time};
|
||||||
use discrete_pid::time::InstantLike;
|
|
||||||
|
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
use core::mem::forget;
|
use core::mem::forget;
|
||||||
|
|
@ -44,15 +44,15 @@ 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::OneShotTimer;
|
||||||
use esp_hal::timer::Timer;
|
use esp_hal::timer::Timer;
|
||||||
|
use esp_hal::timer::timg::TimerGroup;
|
||||||
#[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;
|
||||||
|
|
@ -82,8 +82,6 @@ impl InstantLike for Time {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[main]
|
#[main]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
// generator version: 1.0.1
|
// generator version: 1.0.1
|
||||||
|
|
@ -131,7 +129,8 @@ fn main() -> ! {
|
||||||
let loop_time = Duration::from_micros(10);
|
let loop_time = Duration::from_micros(10);
|
||||||
let cfg = pid::PidConfigBuilder::default()
|
let cfg = pid::PidConfigBuilder::default()
|
||||||
.kp(3.0)
|
.kp(3.0)
|
||||||
.ki(1.0).output_limits(100.00, 2040.00)
|
.ki(1.0)
|
||||||
|
.output_limits(100.00, 2040.00)
|
||||||
.sample_time(loop_time)
|
.sample_time(loop_time)
|
||||||
.filter_tc(0.1)
|
.filter_tc(0.1)
|
||||||
.build()
|
.build()
|
||||||
|
|
@ -143,12 +142,12 @@ fn main() -> ! {
|
||||||
let mut rpm = 0;
|
let mut rpm = 0;
|
||||||
let mut control: f32 = 200.0;
|
let mut control: f32 = 200.0;
|
||||||
let mut timg0 = TimerGroup::new(peripherals.TIMG0);
|
let mut timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||||
let timer0 = timg0.timer0;
|
let coat_timer = timg0.timer0;
|
||||||
// let now =timer.now();
|
let _ = coat_timer
|
||||||
//we need the explicit type here!
|
.load_value(esp_hal::time::Duration::from_secs(10))
|
||||||
timer0.load_value(esp_hal::time::Duration::from_secs(10));
|
.expect("TODO: Could not set timer for coating! ");
|
||||||
timer0.start();
|
coat_timer.start();
|
||||||
while !timer0.is_interrupt_set() {
|
while !coat_timer.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 :)
|
||||||
|
|
@ -166,7 +165,9 @@ fn main() -> ! {
|
||||||
// rprintln!("RPM:{}",rpm);
|
// rprintln!("RPM:{}",rpm);
|
||||||
let last_time = esp_hal::time::Instant::now();
|
let last_time = esp_hal::time::Instant::now();
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue