update motor

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-07-13 16:28:07 +07:00
parent bccfb156d7
commit dddf3fc594
9 changed files with 2142 additions and 48 deletions

View File

@@ -684,17 +684,28 @@ public class DifferentialDrive : IInverseKinematics, IOdometryEstimator, IHosted
}
var (leftVel, rightVel) = CalculateWheelVelocities(twist);
try
{
if (_leftWheelServo != null)
// Ưu tiên gửi cả hai bánh trong một khung (RPDO) để chúng nhận lệnh đồng thời.
// Nếu driver/firmware không hỗ trợ thì fallback về ghi SDO từng bánh.
bool sentTogether = false;
if (_leftWheelServo is IDualAxisVelocityCommand dualAxis)
{
await _leftWheelServo.SetTargetVelocityAsync(leftVel, ct);
sentTogether = await dualAxis.TrySetBothTargetVelocitiesAsync(leftVel, rightVel, ct);
}
if (_rightWheelServo != null)
if (!sentTogether)
{
await _rightWheelServo.SetTargetVelocityAsync(rightVel, ct);
if (_leftWheelServo != null)
{
await _leftWheelServo.SetTargetVelocityAsync(leftVel, ct);
}
if (_rightWheelServo != null)
{
await _rightWheelServo.SetTargetVelocityAsync(rightVel, ct);
}
}
}
catch (Exception ex)