Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

状态读取

完整状态快照

一次性读取完整的机械臂状态,包含 TCP 位姿、所有关节的角度、速度、加速度、扭矩和温度。

from linkerbot import A7

with A7(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: 包含 posejoint_anglesjoint_control_anglesjoint_velocitiesjoint_control_velocitiesjoint_control_accelerationjoint_torquesjoint_temperatures

State 数据模型

属性说明
poseTCP 位姿(Pose)
joint_angles7 个关节的实际角度(list[AngleState])
joint_control_angles7 个关节的控制角度(list[AngleState])
joint_velocities7 个关节的实际速度(list[VelocityState])
joint_control_velocities7 个关节的控制速度(list[VelocityState])
joint_control_acceleration7 个关节的控制加速度(list[AccelerationState])
joint_torques7 个关节的实际扭矩(list[TorqueState])
joint_temperatures7 个关节的温度(list[TemperatureState])

各子状态模型均包含值字段和 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 A7

with A7(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 使用轮询模式采集传感器数据,get_*() 返回的是上一次轮询时的值。

数据类型单位默认轮询间隔最大延迟
角度rad10 ms≈ 10 ms
速度rad/s10 ms≈ 10 ms
扭矩Nm50 ms≈ 50 ms
温度°C1000 ms≈ 1000 ms

如需更低延迟,可通过 start_polling() 方法自定义不同传感器的轮询间隔:

from linkerbot import A7
from linkerbot.arm.a7 import SensorType

with A7(side="left", interface_name="can0") as arm:
    arm.start_polling(
        {
            SensorType.POSITION: 0.005,  # 5 ms = 200 Hz
            SensorType.VELOCITY: 0.005,
            SensorType.TORQUE: 0.1,
            SensorType.TEMPERATURE: 2.0,
        }
    )
    arm.enable()
    arm.home()