we are now measuring the RPM based on the code from: https://symonb.github.io//docs/drone/ESC/ESC_prot_impl_2_2
This commit is contained in:
parent
47f224055b
commit
65761b3f7d
3 changed files with 75 additions and 19 deletions
|
|
@ -304,16 +304,28 @@ impl<'a> DShot<'a> {
|
|||
// Decode to a 16 bit value.
|
||||
if let Some(frame) = decode_bidi_telemetry(&buf[..len]) {
|
||||
// Check CRC.
|
||||
let data = frame >> 4;
|
||||
let mut data = frame >> 4;
|
||||
let crc = calculate_crc(data);
|
||||
if data != 0xfff && crc == (frame&0b1111) {
|
||||
// Fucking got it.
|
||||
let exp = data >> 9;
|
||||
let mantissa = data & 0b111111111;
|
||||
let mut rpm: u32 = (mantissa << exp).into();
|
||||
rpm = (rpm*1000);
|
||||
|
||||
// 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 rpm = (((erpm))/((XING_EPRO_22_COILS)));
|
||||
rprintln!("RPM: {}", rpm);
|
||||
rprintln!("ERPM: {}", erpm);
|
||||
rprintln!("period_ms: {}", period_ms);
|
||||
self.rpm.set(Some(rpm))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -330,7 +342,7 @@ impl<'a> DShot<'a> {
|
|||
let tx_chann = rc.take().unwrap().wait().unwrap();
|
||||
let mut pulses = self.pulses.borrow_mut();
|
||||
let throttle = self.requested_throttle.borrow();
|
||||
*pulses = self.create_pulses(*throttle, false);
|
||||
*pulses = self.create_pulses(*throttle, true);
|
||||
let pulses = pulses.as_ref();
|
||||
// SAFETY: eat shit, rust
|
||||
let pulses = unsafe {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue