Compare commits

..

No commits in common. "8048d48f18a7b0338ad3626470b7da8c9584821d" and "c6db09ac2c27e49f67e48a442f1d79ba2d597332" have entirely different histories.

3 changed files with 20 additions and 45 deletions

View file

@ -62,8 +62,7 @@ extern crate alloc;
//target RPM //target RPM
const DEFAULT_TARGET_RPM: u32 = 4000; const DEFAULT_TARGET_RPM: u32 = 4000;
//in seconds //in seconds
const DEFAULT_SPIN_TIME: u64 = 10; const DEFAULT_SPIN_TIME: u32 = 10;
const DEFAULT_DRY_SPIN_TIME: u64 = 10;
// This creates a default app-descriptor required by the esp-idf bootloader. // This creates a default app-descriptor required by the esp-idf bootloader.
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description> // For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!(); esp_bootloader_esp_idf::esp_app_desc!();
@ -130,7 +129,7 @@ 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(2.0) .kp(2.0)
.ki(0.4) .ki(0.0)
.output_limits(100.00, 400.00) .output_limits(100.00, 400.00)
.sample_time(loop_time) .sample_time(loop_time)
.filter_tc(0.1) .filter_tc(0.1)
@ -138,6 +137,8 @@ fn main() -> ! {
.expect("Failed to build a PID configuration"); .expect("Failed to build a PID configuration");
let controller = pid::FuncPidController::new(cfg); let controller = pid::FuncPidController::new(cfg);
let mut ctx = PidContext::new(Millis(0), 0.0, 0.0); let mut ctx = PidContext::new(Millis(0), 0.0, 0.0);
let set_point = DEFAULT_TARGET_RPM;
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 coat_timer = timg0.timer0; let coat_timer = timg0.timer0;
@ -176,10 +177,8 @@ fn main() -> ! {
let mut display = Nextion::new(&mut uart0); let mut display = Nextion::new(&mut uart0);
//we just set it to page0 to be sure //we just set it to page0 to be sure
display.send_command(b"page page0"); display.send_command(b"page page0");
let mut target_rpm = DEFAULT_TARGET_RPM; let mut _rpm = DEFAULT_TARGET_RPM;
let mut timer: u64 = DEFAULT_SPIN_TIME; let mut _timer = DEFAULT_SPIN_TIME;
let mut target_dry_rpm = DEFAULT_DRY_SPIN_TIME;
let mut dry_timer: u64 = DEFAULT_SPIN_TIME;
let mut started = false; let mut started = false;
loop { loop {
if display.read_ready() { if display.read_ready() {
@ -199,19 +198,11 @@ fn main() -> ! {
} }
Ok(Command::SetRpm(x)) => { Ok(Command::SetRpm(x)) => {
rprintln!("SET_RPM with {}", x); rprintln!("SET_RPM with {}", x);
target_rpm = x; _rpm = x;
} }
Ok(Command::SetTimer(x)) => { Ok(Command::SetTimer(x)) => {
rprintln!("SETTING TIMER {}", x); rprintln!("SETTING TIMER {}", x);
timer = x as _; _timer = x;
}
Ok(Command::SetRpm2(x)) => {
rprintln!("SET_RPM with {}", x);
target_dry_rpm = x.try_into().expect("Couldn't cast RPM2 to u64");
}
Ok(Command::SetTimer2(x)) => {
rprintln!("SETTING TIMER {}", x);
dry_timer = x as _;
} }
Ok(Command::SendConfig) => { Ok(Command::SendConfig) => {
rprintln!("SEND CONFIG"); rprintln!("SEND CONFIG");
@ -233,20 +224,18 @@ fn main() -> ! {
if started { if started {
rprintln!("STARTING!"); rprintln!("STARTING!");
let _ = coat_timer let _ = coat_timer
.load_value(esp_hal::time::Duration::from_secs(timer)) .load_value(esp_hal::time::Duration::from_secs(10))
.expect("TODO: Could not set timer for coating! "); .expect("TODO: Could not set timer for coating! ");
dshot_esc.arm(); dshot_esc.arm();
let mut rpm_fail_ctr = 0; let mut rpm_fail_ctr = 0;
let set_point = target_rpm;
coat_timer.start(); coat_timer.start();
let mut current_rpm = 0;
while !coat_timer.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 :)
control = 200.00; control = 200.00;
dshot_esc.set_throttle(control as _); dshot_esc.set_throttle(control as _);
current_rpm = match dshot_esc.get_rpm() { rpm = match dshot_esc.get_rpm() {
Some(x) => { Some(x) => {
// rprintln!("GOT RPM {}", x); // rprintln!("GOT RPM {}", x);
x x
@ -254,7 +243,7 @@ fn main() -> ! {
None => { None => {
rpm_fail_ctr+=1; rpm_fail_ctr+=1;
// rprintln!("NO RPM!"); // rprintln!("NO RPM!");
current_rpm rpm
} }
}; };
// rprintln!("RPM:{}",rpm); // rprintln!("RPM:{}",rpm);
@ -263,23 +252,19 @@ fn main() -> ! {
let timestamp = esp_hal::time::Instant::now() let timestamp = esp_hal::time::Instant::now()
.duration_since_epoch() .duration_since_epoch()
.as_millis(); .as_millis();
(control, ctx) = controller.compute( (control, ctx) =
ctx, controller.compute(ctx, rpm as _, set_point as _, Millis(timestamp), None);
current_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, current_rpm); rprintln!("control:{},rpm:{}", control,rpm);
//first we send the RPM! //first we send the RPM!
if display.write_ready(){ if display.write_ready(){
let running_rpm = format!("rpm.val={}", current_rpm); let running_rpm = format!("rpm.val={}", rpm);
display.send_command(running_rpm.to_string().as_bytes()); display.send_command(running_rpm.to_string().as_bytes());
} }
if display.write_ready(){ if display.write_ready(){
let counter = format!("counter.val={}", 1234); let counter = format!("counter.val={}", 1234);
display.send_command(counter.to_string().as_bytes()); display.send_command(counter.to_string().as_bytes());
} }
} }

View file

@ -7,8 +7,6 @@ pub enum Command {
Stop, Stop,
SendConfig, SendConfig,
CommandSuccess, CommandSuccess,
SetRpm2(u32),
SetTimer2(u32),
} }
#[derive(Debug)] #[derive(Debug)]
pub enum ErrCommand { pub enum ErrCommand {

View file

@ -116,14 +116,6 @@ impl<'a> Nextion<'a> {
Ok(Command::SetTimer(time)) Ok(Command::SetTimer(time))
} }
05 => Ok(Command::SendConfig), 05 => Ok(Command::SendConfig),
06 => {
let rpm = u32::from_le_bytes(buf[1..5].try_into().expect("failed to parse rpm!"));
Ok(Command::SetRpm2(rpm))
}
07 => {
let time = u32::from_le_bytes(buf[1..5].try_into().expect("failed to parse rpm!"));
Ok(Command::SetTimer2(time))
}
00 => Ok(Command::CommandSuccess), 00 => Ok(Command::CommandSuccess),
_ => Err(ErrCommand::NoValidCmd), _ => Err(ErrCommand::NoValidCmd),
} }