Why cannot I... just... take a break?

2024-05-04

beginnings

blogging

*Aaaaaaa*

Rust, deadlines and Kalman filters

Oh my - deadlines been finally met, worst of the exam survived and hopefully going to pass the course.

Having rewritten my deadlines in Rust, to learn more Rust! Crying out loud, I really need to learn how to take a break or two!

Although, I am kinda internally screaming of how much Rust makes it easier to do complex things - even if the borrow checker is a pain in the butt. As I have been implementing Kalman filters in Rust to later be running of embedded Rust on a RP2040 based system… over MicroPython, which I had a honeymoon phase, which got stumped due to fact that I spent 152 hours trying to implement matrix functions and wrestle with ulab when giving up.

Thanks to incredible help from to_matih with their graphics and vector experience, I was able to learn and avoid .copy() spaghetti and use .view of the nalgebra crate.

    fn predict(&mut self, debug_flag:Option<bool>){
        let x_v = self.state.view((0,0),(self.state.nrows(),self.state.ncols()));
        let f_v = self.state_transition.view((0,0),(self.state_transition.nrows(),self.state_transition.ncols()));
        let p_v = self.process_noise.view((0,0),(self.process_noise.nrows(),self.process_noise.ncols()));
        let q_v = self.process_noise.view((0,0),(self.process_noise.nrows(),self.process_noise.ncols()));

        if debug_flag == Some(true) {
            println!("Pre-Predict state: {}",self.state);
            println!("Pre-Predict covariance: {}", self.covariance);
        }

        self.state = f_v * x_v;

        let fpft_q = f_v * p_v * f_v.transpose() + q_v;

        self.covariance = fpft_q;

        if debug_flag == Some(true) {
            println!("Post-Predict state: {}",self.state);
            println!("Post-Predict covariance: {}", self.covariance);
        }
    }

Why am I doing this - maybe I am bit of a masochist, but I am one stubborn bastard. But damn, I am trying to hit myself for not embracing the meme of ‘just rewrite it in Rust’ - as somehow it makes things run so much easier and memory safer. Don’t have to deal with system crashing on itself if the designed filter desides to desintegrate itself, because either the state matrix went to the absurd levels or adaptive covarience matrix reached to zero and caused everything else to self-destruct. But hey, it is way easier and less crash prone in Rust and I can debug at the very least!

But hey - despite the incredible burnout - I am having fun in programming again! Who knew that deadlines sucks away the learning experience and makes one focus on delivering the thing, causing conservative estimation and no risk taking - where risk could have been even less risky than sunk-cost-fallacy.