状态读取
完整状态快照
一次性读取完整的机械臂状态,包含 TCP 位姿、所有关节的角度、速度、加速度、扭矩和温度。
from linkerbot import A7lite
with A7lite(side="left", interface_name="can0") as arm:
arm.enable()
state = arm.get_state()
print(state.pose)
print(f"第一个关节实际角度:{state.joint_angles[0].angle:.4f} rad")
返回值
State: 包含pose、joint_angles、joint_control_angles、joint_velocities、joint_control_velocities、joint_control_acceleration、joint_torques、joint_temperatures
State 数据模型
| 属性 | 说明 |
|---|---|
pose | TCP 位姿(Pose) |
joint_angles | 7 个关节的实际角度(list[AngleState]) |
joint_control_angles | 7 个关节的控制角度(list[AngleState]) |
joint_velocities | 7 个关节的实际速度(list[VelocityState]) |
joint_control_velocities | 7 个关节的控制速度(list[VelocityState]) |
joint_control_acceleration | 7 个关节的控制加速度(list[AccelerationState]) |
joint_torques | 7 个关节的实际扭矩(list[TorqueState]) |
joint_temperatures | 7 个关节的温度(list[TemperatureState]) |
各子状态模型(AngleState、VelocityState 等)均包含值字段和 timestamp(UNIX 时间戳,秒)。
子状态模型字段
| 模型 | 值字段 | 时间戳字段 |
|---|---|---|
AngleState | .angle | .timestamp |
VelocityState | .velocity | .timestamp |
AccelerationState | .acceleration | .timestamp |
TorqueState | .torque | .timestamp |
TemperatureState | .temperature | .timestamp |
单项状态读取
除 get_state() 外,以下方法分别返回单一类型的状态数据,均返回 7 个关节的列表(get_pose() 除外)。
from linkerbot import A7lite
with A7lite(side="left", interface_name="can0") as arm:
arm.enable()
angles = arm.get_angles()
velocities = arm.get_velocities()
temps = arm.get_temperatures()
pose = arm.get_pose()
print(f"第二个关节实际角度:{angles[1]:.4f} rad")
print(f"第三个关节实际速度:{velocities[2]:.4f} rad/s")
print(f"第四个关节实际温度:{temps[3]:.1f} °C")
print(f"TCP: ({pose.x:.3f}m, {pose.y:.3f}m, {pose.z:.3f}m)")
返回值
| 方法 | 返回值 | 单位 |
|---|---|---|
get_angles() | 7 个关节的实际角度 | rad |
get_control_angles() | 7 个关节的控制角度 | rad |
get_velocities() | 7 个关节的实际速度 | rad/s |
get_control_velocities() | 7 个关节的控制速度 | rad/s |
get_control_acceleration() | 7 个关节的控制加速度 | rad/s² |
get_torques() | 7 个关节的实际扭矩 | Nm |
get_temperatures() | 7 个关节的温度 | °C |
get_pose() | TCP 位姿 | m, rad |
传感器数据
A7 Lite 使用电机主动上报模式,构造时自动启动。
| 数据类型 | 单位 | 上报频率 |
|---|---|---|
| 角度 | rad | 由电机上报周期决定 |
| 速度 | rad/s | 同上 |
| 扭矩 | Nm | 同上 |
| 温度 | °C | 同上 |