ODrive 官方入门指南中,采用的是 USB 连接控制模式(中文翻译版本链接)使用的是 Native Protocol。当我们需要尝试串口通信实现时,需要专程 ASCII 协议来进行串口通信实现相关的命令,结合着入门指南以及 ODrive 中的相关属性方法参数,将流程中用到的相关方法整理如下:
import serial
import time
ted = serial.Serial(port='/dev/tty.wchusbserial1470', baudrate=115200)
ted.write("r vbus_voltage;ted's words\n".encode('ascii'))
vbus_voltage = float(ted.readline().decode('ascii'))
print("vbus_voltage:",vbus_voltage,type(vbus_voltage))
# Current limit
ted.write("r axis0.motor.config.current_lim\n".encode('ascii'))
axis0_motor_config_current_lim = float(ted.readline().decode('ascii'))
print("axis0.motor.config.current_lim:",axis0_motor_config_current_lim,type(axis0_motor_config_current_lim))
# Velocity limit
ted.write("r axis0.controller.config.vel_limit\n".encode('ascii'))
axis0_controller_config_vel_limit = fl