Adjust PID, RPM math (still not correct)

This commit is contained in:
Serge Bazanski 2026-02-28 21:01:30 +01:00
parent e897d25b09
commit 9bce7f0416
4 changed files with 18 additions and 16 deletions

View file

@ -15,7 +15,7 @@ fn calculate_crc(frame: u16) -> u16 {
/*https://de.aliexpress.com/item/1005009484033753.html?spm=a2g0o.productlist.main.2.6389651cV8lVw8&algo_pvid=9cfe024b-8aff-49ea-981b-824f392de976&algo_exp_id=9cfe024b-8aff-49ea-981b-824f392de976-1&pdp_ext_f=%7B%22order%22%3A%2232%22%2C%22eval%22%3A%221%22%2C%22fromPage%22%3A%22search%22%7D&pdp_npi=6%40dis%21EUR%2111.99%2111.99%21%21%2113.55%2113.55%21%40211b813b17620408595223963e91a7%2112000049243823801%21sea%21DE%212739924950%21X%211%210%21n_tag%3A-29919%3Bd%3Abce7cd6%3Bm03_new_user%3A-29895&curPageLogUid=GNUFzsTU8oDr&utparam-url=scene%3Asearch%7Cquery_from%3A%7Cx_object_id%3A1005009484033753%7C_p_origin_prod%3A
IFlight XING-E Pro 2207 2750KV
*/
const XING_EPRO_22_COILS: u32 = 12;
const XING_EPRO_22_POLES: u32 = 4;
#[allow(dead_code)]
#[allow(non_camel_case_types)]
@ -300,7 +300,7 @@ impl<'a> DShot<'a> {
let mut buf = [PulseCode::default(); 32];
{
let mut rxt = rx.receive(&mut buf).unwrap();
while start.elapsed().as_micros() < 100 {
while start.elapsed().as_micros() < 150 {
// Got something within this time.
if rxt.poll() {
// Receive it fully.
@ -316,22 +316,13 @@ impl<'a> DShot<'a> {
if data != 0xfff && crc == (frame&0b1111) {
// Fucking got it.
// ESC_telemetry[4] = (SerialBuf[7] << 8) | SerialBuf[8]; // eRpM *100
// rprintln!("SETTING RPM");
// rprintln!("DATA:{}",data.to_le());
let exp = data >> 9;
let mantissa = data & 0b111111111;
let period_ms: u32 = (mantissa << exp).into();
let erpm = 60*100_000/period_ms*2;
// value sent by ESC is a period between each pole changes [us].
// to achive eRPM we need to find out how many of these changes are in one minute.
// eRPM = (60*1000 000)/T_us next RPM can be achived -> RPM = eRPM/(poles/2):
let erpm = (60 * 1_000_000) / period_ms;
let rpm = (((erpm))/((XING_EPRO_22_COILS)));
// rprintln!("RPM: {}", rpm);
// rprintln!("ERPM: {}", erpm);
// rprintln!("period_ms: {}", period_ms);
let rpm = (((erpm))/((XING_EPRO_22_POLES)));
self.rpm.set(Some(rpm))
}
}

View file

@ -56,7 +56,7 @@ use alloc::format;
static EMERGENCY_BUTTON: Mutex<RefCell<Option<Input>>> = Mutex::new(RefCell::new(None));
extern crate alloc;
//target RPM
const DEFAULT_TARGET_RPM: u32 = 500;
const DEFAULT_TARGET_RPM: u32 = 4000;
//in seconds
const DEFAULT_SPIN_TIME: u32 = 10;
// This creates a default app-descriptor required by the esp-idf bootloader.
@ -126,8 +126,8 @@ fn main() -> ! {
//PID-Controller
let loop_time = Duration::from_micros(10);
let cfg = pid::PidConfigBuilder::default()
.kp(2.0)
.ki(1.5).output_limits(100.00, 2040.00)
.kp(3.0)
.ki(1.0).output_limits(100.00, 2040.00)
.sample_time(loop_time)
.filter_tc(0.1)
.build()