using RobotNet10.CANOpen.CiA402.Enums;
using RobotNet10.Shared.Geometry;
using System.Threading;
using System.Threading.Tasks;
namespace RobotNet10.RobotApp.Motion;
///
/// Interface cho Inverse Kinematics - chuyển đổi vận tốc robot (Twist) thành vận tốc các bánh xe và điều khiển robot
/// Hỗ trợ state machine và operation modes tương tự CiA402
///
public interface IInverseKinematics
{
///
/// Gets the current state of the drive system (tương tự CiA402 state machine)
///
bool IsOperationEnabled { get; }
///
/// Tính toán vận tốc các bánh xe từ vận tốc robot
///
/// Vận tốc robot (linear X, angular Z)
/// Tuple (leftWheelVelocity, rightWheelVelocity) - vận tốc bánh trái và bánh phải (encoder counts/s)
(int leftWheelVelocity, int rightWheelVelocity) CalculateWheelVelocities(Twist twist);
///
/// Đặt vận tốc robot (Twist) - sẽ tự động tính toán và điều khiển các bánh xe
///
/// Vận tốc robot (linear X, angular Z)
/// Cancellation token
Task SetVelocityAsync(Twist twist, CancellationToken ct = default);
///
/// Enable drive system - convenience method để tự động transition qua các states
/// đến OperationEnabled. Gọi method này sẽ tự động thực hiện tất cả các bước cần thiết.
///
void Enable();
///
/// Enable 2 động cơ giống enable bằng tay trên device: gửi lệnh trực tiếp xuống từng servo,
/// await từng bước (SetOperationMode, SetProfileVelocity 0, SwitchOn, EnableOperation) rồi mới xong.
///
Task EnableAsync(CancellationToken cancellationToken = default);
///
/// Disable drive system - convenience method để tắt drive về trạng thái an toàn
///
void Disable();
///
/// Enable operation - chuyển từ SwitchedOn sang OperationEnabled (single step)
///
void EnableOperation();
///
/// Disable operation - chuyển từ OperationEnabled về SwitchedOn (single step)
///
void DisableOperation();
///
/// Quick stop - dừng khẩn cấp drive system
///
void QuickStop();
///
/// Fault reset - reset lỗi và đưa drive về trạng thái ban đầu
///
void FaultReset();
///
/// Set operation mode cho drive system (ProfileVelocity, ProfilePosition, etc.)
///
/// Operation mode to set
/// Cancellation token
Task SetOperationModeAsync(OperationMode mode, CancellationToken ct = default);
///
/// Get current operation mode của drive system
///
/// Cancellation token
Task GetOperationModeAsync(CancellationToken ct = default);
///
/// Set profile acceleration cho drive system
///
/// Gia tốc tăng tốc (m/s²)
/// Cancellation token
Task SetAccelerationAsync(double acceleration, CancellationToken ct = default);
///
/// Set profile deceleration cho drive system
///
/// Gia tốc giảm tốc (m/s²)
/// Cancellation token
Task SetDecelerationAsync(double deceleration, CancellationToken ct = default);
}