-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optionally, generate estimates for imu orientation based on imu data
- Loading branch information
Showing
4 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright (c) 2024, Ouster, Inc. | ||
* All rights reserved. | ||
* | ||
* @file imu-model.h | ||
* @brief provide orientation esimtate based on imu data | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <Eigen/Core> | ||
|
||
// A class that can estimates the current orientation based on imu telemetry | ||
class ImuModel { | ||
public: | ||
/* | ||
* TODO: Add description | ||
* param: orientation represented as euler | ||
* TODO: add initial angular velocity | ||
*/ | ||
virtual void set_initial_state(const Eigen::Vector3d& orientation) = 0; | ||
|
||
/* | ||
* TODO: Update | ||
* params la: linear acceleration | ||
* params av: angular velocity | ||
*/ | ||
virtual Eigen::Quaterniond update(uint64_t ts, const Eigen::Vector3d& la, const Eigen::Vector3d& av) = 0; | ||
}; | ||
|
||
|
||
class SimpleImuModel : public ImuModel { | ||
public: | ||
void set_initial_state(const Eigen::Vector3d& orientation) override { | ||
this->orientation = orientation; | ||
} | ||
|
||
Eigen::Quaterniond update(uint64_t ts, const Eigen::Vector3d& la, const Eigen::Vector3d& av) override { | ||
// TODO: compute delta t | ||
double dt = 0.01; | ||
|
||
orientation.x() += av.x() * dt; | ||
orientation.y() += av.y() * dt; | ||
orientation.z() += av.z() * dt; | ||
orientation.x() += atan2(la.y(), la.z()); | ||
orientation.y() += atan2(-la.x(), sqrt(la.y() * la.y() + la.z() * la.z())); | ||
|
||
Eigen::Quaterniond q = | ||
Eigen::AngleAxisd(orientation.x(), Eigen::Vector3d::UnitX()) | ||
* Eigen::AngleAxisd(orientation.y(), Eigen::Vector3d::UnitY()) | ||
* Eigen::AngleAxisd(orientation.z(), Eigen::Vector3d::UnitZ()); | ||
return q; | ||
} | ||
|
||
private: | ||
// using euler angles for now | ||
Eigen::Vector3d orientation; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters