AsdaB3 1.0.1

dotnet add package AsdaB3 --version 1.0.1
                    
NuGet\Install-Package AsdaB3 -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AsdaB3" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AsdaB3" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="AsdaB3" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AsdaB3 --version 1.0.1
                    
#r "nuget: AsdaB3, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AsdaB3@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AsdaB3&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=AsdaB3&version=1.0.1
                    
Install as a Cake Tool

AsdaB3 伺服驱动器控制库

概述

AsdaB3 是一个用于控制台达(Delta)AsdaB3 系列伺服驱动器的 .NET 类库。该库基于 Modbus RTU 协议实现与伺服驱动器的通信,提供位置控制、速度控制、原点回归等核心功能。

项目结构

AsdaB3/
├── AsdaB3.csproj          # 项目文件
├── AsdaB3Servo.cs         # 核心伺服控制类
├── PositionControlConfig.cs # 位置控制配置类
├── PrPathType.cs          # PR路径类型枚举
└── ServoDirection.cs      # 伺服方向枚举

依赖项

依赖 版本 说明
Microsoft.Extensions.Logging.Abstractions 10.0.7 日志抽象
NModbus4.Core 1.0.2 Modbus RTU 协议实现
System.IO.Ports 10.0.7 串口通信

核心类与方法

AsdaB3Servo 类

连接与通信
// 连接伺服驱动器
bool Connect(byte slaveId, string portName, int baudRate, 
             Parity parity, int dataBits, StopBits stopBits)

// 断开连接
void Disconnect()
伺服使能控制
// 使能伺服
void ServoOn()

// 禁用伺服
void ServoOff()

// 检查伺服是否使能
bool IsServoOn()
PR 位置模式控制
// 设置为PR位置控制模式(需重启生效)
void SetPrMode()

// 配置PATH1参数
void ConfigurePath1(int position, byte speedIndex = 0, 
                    byte accIndex = 0, byte decIndex = 0)

// 触发PR运动
void TriggerPrMotion()
void TriggerPrMotion(byte prNumber)

// 停止PR运动
void StopPrMotion()

// 读取PR状态
ushort ReadPrStatus()

// 检查PR定位是否完成
bool IsPrPositionCompleted()
速度与方向控制
// 设置速度(寸动功能)
void SetSpeed(ushort speed)

// 设置伺服方向
void SetDirection(ServoDirection direction)
位置读取
// 读取当前位置(32位)
int ReadCurrentPosition()

// 读取当前位置(16位)
int ReadCurrentPosition16()
参数配置
// 设置加减速时间参数
void SetAccelerationTime(byte timeIndex, ushort value)

// 设置速度参数
void SetSpeedParameter(byte speedIndex, ushort value)
PR-T 位置扭矩复合模式
// 设置为PR-T模式(需重启生效)
void SetPrTorqueMode()

// 设置扭矩限制百分比
void SetTorqueLimitPercent(short percent)

// 获取扭矩限制百分比
short GetTorqueLimitPercent()

原点回归(Home)功能

// 配置原点回归参数
void ConfigureHomeReturn(HomeDirection direction, 
                         HomeTriggerMode triggerMode,
                         ushort searchSpeed = 500, 
                         ushort creepSpeed = 50)

// 执行原点回归
bool ExecuteHomeReturn()

// 检查原点回归是否完成
bool IsHomeReturnCompleted()

// 等待原点回归完成
bool WaitForHomeReturnComplete(int timeoutMs = 30000)

// 完整的原点回归流程
bool PerformHomeReturn(HomeDirection direction,
                       HomeTriggerMode triggerMode,
                       ushort searchSpeed = 500,
                       ushort creepSpeed = 50,
                       int timeoutMs = 30000)

枚举类型

ServoDirection(伺服方向)
说明
Backward 反向
Stop 停止
Forward 正向
PrPathType(PR路径类型)
说明
SpeedControl 速度控制模式
SinglePosition 单次定位控制(最常用)
AutoPosition 自动定位控制
Jump 跳转控制
Write 写入控制
Index 分度定位控制
HomeDirection(原点回归方向)
说明
Forward 正向回归
Backward 反向回归
HomeTriggerMode(原点回归触发方式)
说明
ZPhaseOnly 仅Z相
LimitSwitchPlusZPhase 限位开关+Z相
LimitSwitchOnly 仅限位开关
OriginSensorPlusZPhase 原点传感器+Z相

使用示例

示例1:基本连接与位置控制

using AsdaB3;
using Microsoft.Extensions.Logging;
using System.IO.Ports;

// 创建日志记录器
var logger = LoggerFactory.Create(builder => {
    builder.AddConsole();
}).CreateLogger<AsdaB3Servo>();

// 创建伺服对象
var servo = new AsdaB3Servo(logger);

// 连接伺服驱动器
bool connected = servo.Connect(
    slaveId: 1,
    portName: "COM3",
    baudRate: 115200,
    parity: Parity.None,
    dataBits: 8,
    stopBits: StopBits.One
);

if (connected)
{
    // 使能伺服
    servo.ServoOn();
    
    // 配置并执行位置定位
    servo.ConfigurePath1(position: 10000, speedIndex: 1, accIndex: 2, decIndex: 2);
    servo.TriggerPrMotion();
    
    // 等待定位完成
    while (!servo.IsPrPositionCompleted())
    {
        System.Threading.Thread.Sleep(100);
    }
    
    // 读取当前位置
    int position = servo.ReadCurrentPosition();
    Console.WriteLine($"当前位置: {position}");
    
    // 断开连接
    servo.Disconnect();
}

示例2:执行原点回归

// 执行原点回归(使用默认参数)
bool success = servo.PerformHomeReturn();

// 或自定义参数
bool success = servo.PerformHomeReturn(
    direction: HomeDirection.Forward,
    triggerMode: HomeTriggerMode.ZPhaseOnly,
    searchSpeed: 500,      // 搜索速度 500 rpm
    creepSpeed: 50,        // 爬行速度 50 rpm
    timeoutMs: 30000       // 超时时间 30秒
);

if (success)
{
    Console.WriteLine("原点回归完成,零点已标定");
}

示例3:PR-T 位置扭矩复合模式

// 设置为PR-T模式(需重启生效)
servo.SetPrTorqueMode();

// 设置扭矩限制
servo.SetTorqueLimitPercent(50); // 50%

// 执行定位(带扭矩限制)
servo.ConfigurePath1(position: 5000);
servo.TriggerPrMotion();

寄存器映射说明

常用寄存器

寄存器 说明 读写
P0.002 状态监控 只读
P1.001 控制模式选择 读写
P2.020 原点回归配置 读写
P2.021-P2.022 原点搜索速度(32位) 读写
P2.023-P2.024 原点爬行速度(32位) 读写
P2.030 伺服使能 读写
P4.005 寸动速度/方向 读写
P5.007 PR命令触发 读写
P5.016-P5.017 主编码器位置(32位) 只读
P5.020-P5.035 加减速时间参数 读写
P5.060-P5.075 速度参数 读写
P6.002-P6.003 PATH1参数 读写

寄存器地址计算

库内部使用以下公式计算 Modbus 寄存器地址:

地址 = (组号 * 0x100) + (寄存器号 * 2)

例如:P5.016
组号 = 5, 寄存器号 = 16
地址 = (5 * 256) + (16 * 2) = 1280 + 32 = 1312 (0x0520)

注意事项

1. 通信参数配置

确保串口参数与伺服驱动器 P3 组参数一致:

参数 对应寄存器
波特率 P3.001
数据位/校验/停止位 P3.002
站号 P3.003

2. 原点回归

  • 原点回归参数(P2.020-P2.024)需要在伺服未使能状态下配置
  • 搜索速度和爬行速度范围:0-6553.5 rpm(单位:0.1 rpm)
  • PR#1001 用于触发原点回归

3. 安全注意事项

  • 在执行任何运动前确保伺服已使能
  • 确保机械行程范围内有足够空间执行运动
  • 建议在测试阶段使用较低速度

4. 错误处理

所有方法内部均有异常处理和日志记录,建议在调用时检查返回值或捕获异常。

版本历史

版本 日期 更新内容
1.0.0 2026-05 初始版本,包含基本位置控制和原点回归功能

许可证

MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 89 5/11/2026
1.0.0 91 5/10/2026