@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user