Initial commit
This commit is contained in:
@@ -0,0 +1,223 @@
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Interface cho thiết bị IMU (Inertial Measurement Unit) trong robot AGV
|
||||
/// </summary>
|
||||
public interface IInertialMeasurementUnit
|
||||
{
|
||||
/// <summary>
|
||||
/// Trạng thái kết nối với thiết bị IMU
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Trạng thái đã được calibrate hay chưa
|
||||
/// </summary>
|
||||
bool IsCalibrated { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tần số lấy mẫu hiện tại (Hz)
|
||||
/// </summary>
|
||||
double SampleRate { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Dữ liệu gia tốc được cache (m/s²)
|
||||
/// </summary>
|
||||
AccelStamped CachedAcceleration { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
Vector3Stamped CachedAngularVelocity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Dữ liệu từ trường (magnetometer) được cache (µT hoặc Gauss)
|
||||
/// </summary>
|
||||
Vector3Stamped? CachedMagnetometer { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Dữ liệu hướng (Euler angles) được cache (rad)
|
||||
/// Roll, Pitch, Yaw được map sang X, Y, Z của Vector3
|
||||
/// </summary>
|
||||
Vector3Stamped CachedOrientation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Dữ liệu quaternion được cache
|
||||
/// </summary>
|
||||
QuaternionStamped? CachedQuaternion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Nhiệt độ cảm biến được cache (°C)
|
||||
/// </summary>
|
||||
double? CachedTemperature { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Timestamp của lần đọc dữ liệu gần nhất
|
||||
/// </summary>
|
||||
DateTime LastUpdateTime { get; }
|
||||
|
||||
// Events
|
||||
|
||||
/// <summary>
|
||||
/// Event được kích hoạt khi dữ liệu gia tốc thay đổi
|
||||
/// </summary>
|
||||
event EventHandler<AccelerationChangedEventArgs>? AccelerationChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Event được kích hoạt khi dữ liệu vận tốc góc thay đổi
|
||||
/// </summary>
|
||||
event EventHandler<AngularVelocityChangedEventArgs>? AngularVelocityChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Event được kích hoạt khi dữ liệu từ trường thay đổi
|
||||
/// </summary>
|
||||
event EventHandler<MagnetometerChangedEventArgs>? MagnetometerChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Event được kích hoạt khi hướng (orientation) thay đổi
|
||||
/// </summary>
|
||||
event EventHandler<OrientationChangedEventArgs>? OrientationChanged;
|
||||
|
||||
// Connection Methods
|
||||
|
||||
/// <summary>
|
||||
/// Kết nối với thiết bị IMU
|
||||
/// </summary>
|
||||
Task ConnectAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Ngắt kết nối với thiết bị IMU
|
||||
/// </summary>
|
||||
Task DisconnectAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
// Data Reading Methods
|
||||
|
||||
/// <summary>
|
||||
/// Đọc dữ liệu gia tốc (m/s²)
|
||||
/// </summary>
|
||||
Task<AccelStamped> ReadAccelerationAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc dữ liệu vận tốc góc (rad/s)
|
||||
/// Roll, Pitch, Yaw được map sang X, Y, Z của Vector3
|
||||
/// </summary>
|
||||
Task<Vector3Stamped> ReadAngularVelocityAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc dữ liệu từ trường (magnetometer) nếu có (µT hoặc Gauss)
|
||||
/// </summary>
|
||||
Task<Vector3Stamped?> ReadMagnetometerAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc dữ liệu hướng (Euler angles) (rad)
|
||||
/// Roll, Pitch, Yaw được map sang X, Y, Z của Vector3
|
||||
/// </summary>
|
||||
Task<Vector3Stamped> ReadOrientationAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc dữ liệu quaternion nếu có
|
||||
/// </summary>
|
||||
Task<QuaternionStamped?> ReadQuaternionAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc tất cả dữ liệu IMU cùng lúc
|
||||
/// </summary>
|
||||
Task<Imu> ReadAllDataAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc nhiệt độ cảm biến nếu có (°C)
|
||||
/// </summary>
|
||||
Task<double?> ReadTemperatureAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
// Calibration Methods
|
||||
|
||||
/// <summary>
|
||||
/// Calibrate IMU (gyroscope và accelerometer)
|
||||
/// </summary>
|
||||
Task CalibrateAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Calibrate magnetometer (nếu có)
|
||||
/// </summary>
|
||||
Task CalibrateMagnetometerAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Reset calibration về mặc định
|
||||
/// </summary>
|
||||
Task ResetCalibrationAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
// Configuration Methods
|
||||
|
||||
/// <summary>
|
||||
/// Thiết lập tần số lấy mẫu (Hz)
|
||||
/// </summary>
|
||||
Task SetSampleRateAsync(double sampleRate, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Thiết lập dải đo gia tốc (g)
|
||||
/// </summary>
|
||||
Task SetAccelerometerRangeAsync(double range, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Thiết lập dải đo vận tốc góc (rad/s)
|
||||
/// </summary>
|
||||
Task SetGyroscopeRangeAsync(double range, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
// Event Args
|
||||
|
||||
/// <summary>
|
||||
/// Event args khi dữ liệu gia tốc thay đổi
|
||||
/// </summary>
|
||||
public class AccelerationChangedEventArgs(AccelStamped data) : EventArgs
|
||||
{
|
||||
public AccelStamped Data { get; } = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event args khi dữ liệu vận tốc góc thay đổi
|
||||
/// </summary>
|
||||
public class AngularVelocityChangedEventArgs(Vector3Stamped data) : EventArgs
|
||||
{
|
||||
public Vector3Stamped Data { get; } = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event args khi dữ liệu từ trường thay đổi
|
||||
/// </summary>
|
||||
public class MagnetometerChangedEventArgs(Vector3Stamped data) : EventArgs
|
||||
{
|
||||
public Vector3Stamped Data { get; } = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event args khi hướng (orientation) thay đổi
|
||||
/// </summary>
|
||||
public class OrientationChangedEventArgs(Vector3Stamped data) : EventArgs
|
||||
{
|
||||
public Vector3Stamped Data { get; } = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event args chứa toàn bộ dữ liệu IMU trong 1 sample (dùng cho SensorPipeline)
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user