using RobotNet10.Shared.Geometry;
using RobotNet10.Shared.Sensor;
namespace RobotNet10.RobotApp.Devices;
// Type alias để giữ tương thích với code hiện tại
using AccelerationData = AccelStamped;
///
/// Interface cho thiết bị IMU (Inertial Measurement Unit) trong robot AGV
///
public interface IInertialMeasurementUnit
{
///
/// Trạng thái kết nối với thiết bị IMU
///
bool IsConnected { get; }
///
/// Trạng thái đã được calibrate hay chưa
///
bool IsCalibrated { get; }
///
/// Tần số lấy mẫu hiện tại (Hz)
///
double SampleRate { get; }
///
/// Dữ liệu gia tốc được cache (m/s²)
///
AccelStamped CachedAcceleration { get; }
///
/// Dữ liệu vận tốc góc được cache (rad/s)
/// Roll, Pitch, Yaw được map sang X, Y, Z của Vector3
///
Vector3Stamped CachedAngularVelocity { get; }
///
/// Dữ liệu từ trường (magnetometer) được cache (µT hoặc Gauss)
///
Vector3Stamped? CachedMagnetometer { get; }
///
/// Dữ liệu hướng (Euler angles) được cache (rad)
/// Roll, Pitch, Yaw được map sang X, Y, Z của Vector3
///
Vector3Stamped CachedOrientation { get; }
///
/// Dữ liệu quaternion được cache
///
QuaternionStamped? CachedQuaternion { get; }
///
/// Nhiệt độ cảm biến được cache (°C)
///
double? CachedTemperature { get; }
///
/// Timestamp của lần đọc dữ liệu gần nhất
///
DateTime LastUpdateTime { get; }
// Events
///
/// Event được kích hoạt khi dữ liệu gia tốc thay đổi
///
event EventHandler? AccelerationChanged;
///
/// Event được kích hoạt khi dữ liệu vận tốc góc thay đổi
///
event EventHandler? AngularVelocityChanged;
///
/// Event được kích hoạt khi dữ liệu từ trường thay đổi
///
event EventHandler? MagnetometerChanged;
///
/// Event được kích hoạt khi hướng (orientation) thay đổi
///
event EventHandler? OrientationChanged;
// Connection Methods
///
/// Kết nối với thiết bị IMU
///
Task ConnectAsync(CancellationToken cancellationToken = default);
///
/// Ngắt kết nối với thiết bị IMU
///
Task DisconnectAsync(CancellationToken cancellationToken = default);
// Data Reading Methods
///
/// Đọc dữ liệu gia tốc (m/s²)
///
Task ReadAccelerationAsync(CancellationToken cancellationToken = default);
///
/// Đọc dữ liệu vận tốc góc (rad/s)
/// Roll, Pitch, Yaw được map sang X, Y, Z của Vector3
///
Task ReadAngularVelocityAsync(CancellationToken cancellationToken = default);
///
/// Đọc dữ liệu từ trường (magnetometer) nếu có (µT hoặc Gauss)
///
Task ReadMagnetometerAsync(CancellationToken cancellationToken = default);
///
/// Đọc dữ liệu hướng (Euler angles) (rad)
/// Roll, Pitch, Yaw được map sang X, Y, Z của Vector3
///
Task ReadOrientationAsync(CancellationToken cancellationToken = default);
///
/// Đọc dữ liệu quaternion nếu có
///
Task ReadQuaternionAsync(CancellationToken cancellationToken = default);
///
/// Đọc tất cả dữ liệu IMU cùng lúc
///
Task ReadAllDataAsync(CancellationToken cancellationToken = default);
///
/// Đọc nhiệt độ cảm biến nếu có (°C)
///
Task ReadTemperatureAsync(CancellationToken cancellationToken = default);
// Calibration Methods
///
/// Calibrate IMU (gyroscope và accelerometer)
///
Task CalibrateAsync(CancellationToken cancellationToken = default);
///
/// Calibrate magnetometer (nếu có)
///
Task CalibrateMagnetometerAsync(CancellationToken cancellationToken = default);
///
/// Reset calibration về mặc định
///
Task ResetCalibrationAsync(CancellationToken cancellationToken = default);
// Configuration Methods
///
/// Thiết lập tần số lấy mẫu (Hz)
///
Task SetSampleRateAsync(double sampleRate, CancellationToken cancellationToken = default);
///
/// Thiết lập dải đo gia tốc (g)
///
Task SetAccelerometerRangeAsync(double range, CancellationToken cancellationToken = default);
///
/// Thiết lập dải đo vận tốc góc (rad/s)
///
Task SetGyroscopeRangeAsync(double range, CancellationToken cancellationToken = default);
}
// Event Args
///
/// Event args khi dữ liệu gia tốc thay đổi
///
public class AccelerationChangedEventArgs(AccelStamped data) : EventArgs
{
public AccelStamped Data { get; } = data;
}
///
/// Event args khi dữ liệu vận tốc góc thay đổi
///
public class AngularVelocityChangedEventArgs(Vector3Stamped data) : EventArgs
{
public Vector3Stamped Data { get; } = data;
}
///
/// Event args khi dữ liệu từ trường thay đổi
///
public class MagnetometerChangedEventArgs(Vector3Stamped data) : EventArgs
{
public Vector3Stamped Data { get; } = data;
}
///
/// Event args khi hướng (orientation) thay đổi
///
public class OrientationChangedEventArgs(Vector3Stamped data) : EventArgs
{
public Vector3Stamped Data { get; } = data;
}
///
/// Event args chứa toàn bộ dữ liệu IMU trong 1 sample (dùng cho SensorPipeline)
///
public class ImuDataChangedEventArgs(
AccelStamped acceleration,
Vector3Stamped angularVelocity,
Vector3Stamped magnetometer,
Vector3Stamped orientation,
DateTime timestamp) : EventArgs
{
public AccelStamped Acceleration { get; } = acceleration;
public Vector3Stamped AngularVelocity { get; } = angularVelocity;
public Vector3Stamped Magnetometer { get; } = magnetometer;
public Vector3Stamped Orientation { get; } = orientation;
public DateTime Timestamp { get; } = timestamp;
}