byu-magicc / roscopter

*Under Development* - A fully-featured multirotor autopilot for ROS
http://scholarsarchive.byu.edu/cgi/viewcontent.cgi?article=2324&context=facpub
52 stars 38 forks source link

How to add additional sensors to the mekf? #37

Closed memphis242 closed 4 years ago

memphis242 commented 5 years ago

Hey, so our project is trying to build an autonomous quadcopter that navigates indoors without the aid of GPS, and because of size and weight limitations, we can't really use a LiDAR and perform SLAM with that. That leaves just a few possibilities. Now I've set up the roscopter package and I notice that for the mekf node, it uses IMU, GPS, magnetometer, barometer, and sonar data from what is published by rosflight_io to estimate the current state. Without the GPS input however, as far as I understand, just using the IMU data will not be enough because eventually the error builds even if the initial error is very small. No one in my project is really familiar with how EKFs work, and aside from reading and researching on our own, I wanted to ask you guys how you would go about adding sensors to the mekf.

So for instance, one of the sensors that could help us is an optical flow sensor, and specifically, we have the PX4flow board and have it setup to work with the px4flow_node package, and that would give us x, y, x-velocity, and y-velocity values.

superjax commented 5 years ago

Hey @memphis242, cool project! The main motivation for our stuff is actually GPS-denied, however we haven't posted a lot of our GPS-denied code.

So, in general, to add sensors to an EKF you have to derive a "measurement model" and the associated jacobian.

For example, if you can write the estimated measurement from the PX4Flow in terms of the state where x is the state and y is the measurement.

y = h(x)

Then the Jacobian you need to implement is dh/dx (and should be a short and fat matrix).

the baroCallback, sonarCallback, gpsCallback and magCallback all create an h vector (the measurement) and an H matrix, (the jacobian). Once you have those matrices, you can plug them into the Kalman Filter update step, which is also in each of these callback functions.

Honestly, Kalman filtering can be pretty complicated. I would recommend at the very least reading Dr. Beard's notes on the subject (https://scholarsarchive.byu.edu/cgi/viewcontent.cgi?article=2324&context=facpub) (chapter 6)

I haven't looked at the filter in this package in a long while... it's kinda old, and we are in the middle of adapting our VI-EKF package that @jerelbn and I have been working on to be a bit more generic. That filter will ultimately replace the mekf in roscopter. Adding measurement models is a little easier in that package, and it's being actively maintained.

superjax commented 5 years ago

Also, now that I am thinking about it, if you can carry a camera and have the computing power onboard, I would reommend VINS. It's a really superb visual-inertial estimation package that works with almost anything.

memphis242 commented 5 years ago

Ok, so I'll need some more help on this. After going through the code a bit more, as well as the paper (which I honestly was not really able to understand past the first chapter), here is what I'm getting. VI-EKF and VINS aside, say we want to add the optical flow data to the MEKF, this is what I have understood that I need to do (verify and correct me please):