odrive入门教程(securecrt使用教程串口)

ODrive官方入门指南中,采用的是USB连接控制模式(中文翻译版本链接)使用的是NativeProtocol。当我们需要尝试串口通信实现时,需要专程ASCII协议来进行串口通信实现相关的命令,结合着入门指南以及ODrive中的相关属性方法参数,将流程中用到的相关方法整理如下:importserialimporttimeted=serial.Serial(port=’/dev/tty.wchusbserial1470′,baudrate=115200)ted.writ

大家好,又见面了,我是你们的朋友全栈君。

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 = float(ted.readline().decode('ascii'))
print("axis0.controller.config.vel_limit:",axis0_controller_config_vel_limit,type(axis0_controller_config_vel_limit))

# Calibration current
ted.write("r axis0.motor.config.calibration_current\n".encode('ascii'))
axis0_motor_config_calibration_current = float(ted.readline().decode('ascii'))
print("axis0.motor.config.calibration_current:",axis0_motor_config_calibration_current,type(axis0_motor_config_calibration_current))

# brake_resistance
ted.write("r config.brake_resistance\n".encode('ascii'))
config_brake_resistance = float(ted.readline().decode('ascii'))
print("config.brake_resistance:",config_brake_resistance,type(config_brake_resistance))

# pole_pairs
ted.write("r axis0.motor.config.pole_pairs\n".encode('ascii'))
axis0_motor_config_pole_pairs = int(ted.readline().decode('ascii'))
print("axis0.motor.config.pole_pairs:",axis0_motor_config_pole_pairs,type(axis0_motor_config_pole_pairs))

# motor_type
ted.write("r axis0.motor.config.motor_type\n".encode('ascii'))
axis0_motor_config_motor_type = int(ted.readline().decode('ascii'))
print("axis0.motor.config.motor_type:",axis0_motor_config_motor_type,type(axis0_motor_config_motor_type))

print("~"*20)
# cpr
ted.write("r axis0.encoder.config.cpr\n".encode('ascii'))
axis0_encoder_config_cpr = int(ted.readline().decode('ascii'))
print("axis0.encoder.config.cpr:",axis0_encoder_config_cpr,type(axis0_encoder_config_cpr))

ted.write("w axis0.encoder.config.cpr 4096\n".encode('ascii'))

ted.write("r axis0.encoder.config.cpr\n".encode('ascii'))
axis0_encoder_config_cpr2 = int(ted.readline().decode('ascii'))
print("axis0.encoder.config.cpr modified:",axis0_encoder_config_cpr2,type(axis0_encoder_config_cpr2))

print("~"*20)

# Save configuration
ted.write("ss\n".encode('ascii'))

# Position control
""" AXIS_STATE_UNDEFINED = 0 AXIS_STATE_IDLE = 1 AXIS_STATE_STARTUP_SEQUENCE = 2 AXIS_STATE_FULL_CALIBRATION_SEQUENCE = 3 AXIS_STATE_MOTOR_CALIBRATION = 4 AXIS_STATE_SENSORLESS_CONTROL = 5 AXIS_STATE_ENCODER_INDEX_SEARCH = 6 AXIS_STATE_ENCODER_OFFSET_CALIBRATION = 7 AXIS_STATE_CLOSED_LOOP_CONTROL = 8 AXIS_STATE_LOCKIN_SPIN = 9 AXIS_STATE_ENCODER_DIR_FIND = 10 """
ted.write("r axis0.current_state\n".encode('ascii'))
axis0_current_state = int(ted.readline().decode('ascii'))
print("axis0.current_state:",axis0_current_state,type(axis0_current_state))

# AXIS_STATE_FULL_CALIBRATION_SEQUENCE
ted.write("w axis0.requested_state 3\n".encode('ascii'))
print("校准电机...")
time.sleep(15)
ted.write("r axis0.current_state\n".encode('ascii'))
axis0_current_state2 = int(ted.readline().decode('ascii'))
print("axis0.current_state modified:",axis0_current_state2,type(axis0_current_state2))

# AXIS_STATE_CLOSED_LOOP_CONTROL
ted.write("w axis0.requested_state 8\n".encode('ascii'))

ted.write("r axis0.current_state\n".encode('ascii'))
axis0_current_state3 = int(ted.readline().decode('ascii'))
print("axis0.current_state modified again:",axis0_current_state3,type(axis0_current_state3))

ted.write("w axis0.controller.pos_setpoint 10000\n".encode('ascii'))




版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/127520.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • sql2008“备份集中的数据库备份与现有的xx数据库不同”解决方法[通俗易懂]

    sql2008“备份集中的数据库备份与现有的xx数据库不同”解决方法[通俗易懂]原文链接:http://www.cnblogs.com/huangfr/archive/2012/08/09/2629687.html1.因为是在另一台电脑对同名数据库做的备份,用常规方法还原,提示不是相同数据库,不让还原,在网上找到下面的方法解决了:一、右击系统数据库master,新建查询执行以下SQL代码:RESTOREDATABASExxxFROMDI

    2022年6月6日
    37
  • 最全ASCii 码表和说明

    最全ASCii 码表和说明最全ASCii 码表和说明

    2022年4月24日
    121
  • makefile 指定文件的生成目录[通俗易懂]

    makefile 指定文件的生成目录[通俗易懂]1.上一篇博客虽然简单实现了自动处理依赖关系,但是生成的各种临时文件都混在一起,太乱了。假定我们的源文件放在src目录,头文件放在inc目录,.o文件放在obj目录,.d文件放在dmk目录,Makefile和上述4个目录为同一级别。则定义如下变量:D_SRC=srcD_INC=-I./incD_OBJ=objD_MK=dmk2.自动遍历src目录下的所有.c

    2022年5月21日
    47
  • 浅谈 js 字符串 search 方法

    浅谈 js 字符串 search 方法这是一个很久以前的事情了,好像是安心兄弟在学习js的时候做的练习。具体记不清了,今天就来简单分析下search究竟是什么用的。从字面意思理解,一个是搜索字符串吧。varstr="1

    2022年7月2日
    27
  • Java单例模式以及其实现

    Java单例模式以及其实现单例模式单例模式(SingletonPattern)是Java中最简单的设计模式之一。这种类型的设计模式属于创建型模式,它提供了一种创建对象的最佳方式。这种模式涉及到一个单一的类,该类负责创建自己的对象,同时确保只有单个对象被创建。这个类提供了一种访问其唯一的对象的方式,可以直接访问,不需要实例化该类的对象。简单来说就是类只能创建唯一一个对象实现要求:(1)构造器私有化:指用private修饰构造器,使得外部无法调用构造器,使得类外部方法无法创建该类对象(2)自行创建对象,静态

    2022年7月8日
    18
  • tkMapper的使用[通俗易懂]

    tkMapper的使用[通俗易懂]Maven引入<dependency><groupId>tk.mybatis</groupId><artifactId>mapper-spring-boot-starter</artifactId><version>2.1.5</version></dependency>…

    2022年10月7日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号