Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMU class template #48

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions Common/Inc/CommonDataTypes.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
//
// Created by Gordon Fountain 2022-11-30.
//
/** CommonDataTypes.hpp
* Contains a bunch of common datatypes!
*
* Created by: Gordon Fountain 2022-11-30
* Updated by: Anthony Luo
* Last update: 2024-04-18
*/

#ifndef ZPSW3_COMMON_DATATYPES_HPP
#define ZPSW3_COMMON_DATATYPES_HPP

#include <stdint.h>

/************************************************
* Sensor/Error structs (can be either or. tbd ig)
************************************************/
typedef enum SensorErrorCode {
SENSOR_SUCCESS = 0,
SENSOR_FAIL = -1,
SENSOR_BUSY = 1,
} SensorErrorCode;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/************************************************
* Control limits & inter-manager datatypes
************************************************/
namespace AM {

struct AttitudeManagerInput {
float roll;
float pitch;
float yaw;
float throttle;
};

} // Namespace AM

typedef enum {
Expand Down
52 changes: 52 additions & 0 deletions Drivers/imu/inc/imu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* IMU class definition / stub
* Designed to be extended by IMU devices
* Created by: Anthony Luo on 2024-04-18
* Maintained by:
* Last updated:
*/

#ifndef IMU_HPP
#define IMU_HPP

#include "CommonDataTypes.hpp"

/************************************************
* Definitions
************************************************/

struct IMUData_t {
float gyrx, gyry, gyrz;
float accx, accy, accz;
float magx, magy, magz;

bool is_data_new;
SensorErrorCode sensor_status; // TODO: determine if we need this?
};

/************************************************
* Prototypes
************************************************/
class IMU{
public:
// Leaving the constructor to be elsewhere.... don't know how to handle passing SPI/I2C handles

/**
* Re-calibrates sensor. Useful if we need to hard re-set an IMU in-flight or something.
*/
virtual SensorErrorCode calibrate() = 0;
/**
* Begins IMU data sampling. TODO: determine how this is determined
* Data should be stored in a buffer and accessible at any time.
*
*/
virtual void beginMeasuring() = 0;

/**
* Retrieves newest data stored by IMU.
* TODO: determine if we want to return error codes or if we want to set the struct
*/
virtual SensorErrorCode getResult(IMUData_t &data) = 0;
private:
IMUData_t latest_data;
};
Loading