Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7b99762
创建分支
Ashington258 Oct 17, 2024
de25067
添加测试代码以验证ODrive连接和电压读取
Ashington258 Oct 17, 2024
13b58d2
添加项目依赖项到requirements.txt
Ashington258 Oct 17, 2024
c844f26
添加 USB CDC 接口的测试代码
Ashington258 Oct 17, 2024
d2a539b
添加键盘控制ODrive的代码实现
Ashington258 Oct 17, 2024
ed81db9
添加PyQt5库以支持图形界面开发
Ashington258 Oct 18, 2024
da18e2d
添加ASCII协议文档并提供Python类实现
Ashington258 Oct 18, 2024
7317414
```✅添加ODriveAsciiProtocol类实现对ODrive的控制和配置```
Ashington258 Oct 18, 2024
7d6c8d2
```新增电机控制用户界面```
Ashington258 Oct 18, 2024
e4bd260
```✅添加主程序入口和基本功能示例```
Ashington258 Oct 18, 2024
1902dc7
```
Ashington258 Oct 18, 2024
23bf643
删除键盘控制ODrive的代码
Ashington258 Oct 18, 2024
7f7b205
feat(odrive_protocol): 添加 ODrive 设备检测和信息检查功能
Ashington258 Oct 18, 2024
a475540
还原原本的配置代码
Ashington258 Oct 18, 2024
f6b0cc6
feat(ch100_protocol): 添加 hipnuc 串口数据解析功能
Ashington258 Oct 19, 2024
e337c64
```✅完成CH100的协议解析,并且使用zmq发布```
Ashington258 Oct 19, 2024
08975f1
test: ```❌数据绘图显示有延迟,不正常```添加 IMU 数据实时绘图脚本
Ashington258 Oct 19, 2024
ab76a43
test: 添加 TCP 端口检测脚本
Ashington258 Oct 19, 2024
26102a1
chore: 忽略 Python 缓存文件
Ashington258 Oct 19, 2024
6f9ce09
docs(config): 添加电机驱动配置文件
Ashington258 Oct 19, 2024
5cb20ab
docs(ch100): 添加 CH100 使用手册
Ashington258 Oct 19, 2024
5ad5c8e
feat(ch100_protocol): 为解析后的数据帧添加主题信息
Ashington258 Oct 19, 2024
3bc4df1
feat(odrive_protocol): 增加 ODrive 设备信息检查和自动查找功能
Ashington258 Oct 19, 2024
d68bf27
test: 更新测试脚本配置并添加新测试功能
Ashington258 Oct 19, 2024
6130413
build: 更新项目依赖
Ashington258 Oct 19, 2024
fc14f5f
feat(main): 实现 CH100 和 ODrive 数据采集和发布
Ashington258 Oct 19, 2024
e6cbbea
refactor(odrive_protocol): 重构 ODrive 协议库
Ashington258 Oct 19, 2024
bd5b4e6
feat(balance_control): 添加 ODrive 订阅者功能
Ashington258 Oct 19, 2024
3f738df
feat(self_check): 添加系统自检功能并优化主程序
Ashington258 Oct 19, 2024
a0ae65c
```✅完成了双进程发布ZMQ消息```
Ashington258 Oct 19, 2024
3166308
chore: 删除 odrive_protocol 模块的缓存文件
Ashington258 Oct 19, 2024
207d855
Update hipnuc_serial_parser_zmq.py
Ashington258 Oct 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ CMakePresets.json
cmake_install.cmake
compile_commands.json

# Ignore python cache
__pycache__/
cache.md

This file was deleted.

245 changes: 0 additions & 245 deletions Calculation_Unit/设计框图/计算单元.drawio

This file was deleted.

68 changes: 68 additions & 0 deletions config/配置参数(优化版本).txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
odrv0.erase_configuration()
odrv0.config.brake_resistance = 0.47
odrv0.config.dc_bus_overvoltage_trip_level = 56
odrv0.config.dc_max_positive_current = 120
odrv0.config.dc_max_negative_current = -30


odrv0.axis0.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT
odrv0.axis0.motor.config.pole_pairs = 14
odrv0.axis0.motor.config.calibration_current = 10
odrv0.axis0.motor.config.current_lim = 120
odrv0.axis0.motor.config.current_lim_margin = 8
odrv0.axis0.encoder.config.mode = ENCODER_MODE_INCREMENTAL
odrv0.axis0.encoder.config.cpr = 8192
odrv0.axis0.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis0.controller.config.vel_limit = 50
odrv0.axis0.controller.config.vel_limit_tolerance = 2
odrv0.axis0.controller.config.vel_gain = 0.45 //kp
odrv0.axis0.controller.config.vel_integrator_gain = 0.2 //ki
odrv0.axis0.controller.config.input_mode = INPUT_MODE_VEL_RAMP
odrv0.axis0.controller.config.vel_ramp_rate = 50


odrv0.axis1.motor.config.motor_type = MOTOR_TYPE_HIGH_CURRENT
odrv0.axis1.motor.config.pole_pairs = 14
odrv0.axis1.motor.config.calibration_current = 10
odrv0.axis1.motor.config.current_lim = 120
odrv0.axis1.motor.config.current_lim_margin = 8
odrv0.axis1.encoder.config.mode = ENCODER_MODE_INCREMENTAL
odrv0.axis1.encoder.config.cpr = 8192
odrv0.axis1.controller.config.control_mode = CONTROL_MODE_VELOCITY_CONTROL
odrv0.axis1.controller.config.vel_limit = 50
odrv0.axis1.controller.config.vel_limit_tolerance = 2
odrv0.axis1.controller.config.vel_gain = 0.45 //kp
odrv0.axis1.controller.config.vel_integrator_gain = 0.2 //ki
odrv0.axis1.controller.config.input_mode = INPUT_MODE_VEL_RAMP
odrv0.axis1.controller.config.vel_ramp_rate = 50



odrv0.axis0.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE //校准大概需要十秒钟
odrv0.axis0.error //检查是否有错误,报0说明编码器连接没问题,报256说明编码器连接有问题
odrv0.axis0.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv0.axis0.motor.config.pre_calibrated = True
odrv0.axis0.config.startup_encoder_offset_calibration = True
odrv0.axis0.config.startup_closed_loop_control = True


odrv0.axis1.requested_state = AXIS_STATE_FULL_CALIBRATION_SEQUENCE //校准大概需要十秒钟
odrv0.axis1.error //检查是否有错误
odrv0.axis1.requested_state = AXIS_STATE_CLOSED_LOOP_CONTROL
odrv0.axis1.motor.config.pre_calibrated = True
odrv0.axis1.config.startup_encoder_offset_calibration = True
odrv0.axis1.config.startup_closed_loop_control = True

odrv0.config.enable_uart = True
odrv0.config.uart_baudrate = 460800

odrv0.axis0.requested_state = AXIS_STATE_IDLE //释放电机,配置完参数之后释放电机才能保存
odrv0.axis1.requested_state = AXIS_STATE_IDLE
odrv0.save_configuration()
odrv0.reboot()


odrv0.axis0.controller.input_vel = 10 //设置转速
odrv0.axis1.controller.input_vel = 10


113 changes: 113 additions & 0 deletions doc/ASCII Protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
Here’s a summary of the protocol layers based on the given ASCII protocol, encapsulated in a Python class for ease of use.

### ASCII Protocol Summary
1. **Communication Interfaces**:
- USB or UART can be used to communicate with the ODrive. Different commands are sent based on the connection type.

2. **Command Format**:
- Commands are sent as text-based lines, potentially including an optional GCode-compatible checksum.
- The format is: `command *checksum ; comment [newline]`.
- Commands are interpreted when a newline character is encountered.

3. **Command Types**:
- **Motor Commands**:
- `t motor destination`: Motor trajectory command.
- `q motor position velocity_lim torque_lim`: Single setpoint for motor position.
- `p motor position velocity_ff torque_ff`: Streaming setpoints for motor position.
- `v motor velocity torque_ff`: Motor velocity command.
- `c motor torque`: Motor current (torque) command.
- **Feedback Requests**:
- `f motor`: Requests motor position and velocity feedback.
- **Watchdog Update**:
- `u motor`: Updates the motor watchdog timer.
- **Parameter Reading/Writing**:
- `r property`: Read parameter.
- `w property value`: Write parameter.
- **System Commands**:
- `ss`: Save configuration.
- `se`: Erase configuration.
- `sr`: Reboot.
- `sc`: Clear errors.

### Python Encapsulation

The following Python class encapsulates the described ASCII protocol:

```python
import serial

class ODriveAsciiProtocol:
def __init__(self, port: str, baudrate: int = 115200):
self.serial = serial.Serial(port, baudrate, timeout=1)

def send_command(self, command: str):
# Send command to the ODrive, with newline character
self.serial.write(f"{command}\n".encode())

def read_response(self):
# Read the response from ODrive
return self.serial.readline().decode().strip()

def motor_trajectory(self, motor: int, destination: float):
command = f"t {motor} {destination}"
self.send_command(command)

def motor_position(self, motor: int, position: float, velocity_lim: float = None, torque_lim: float = None):
command = f"q {motor} {position}"
if velocity_lim is not None:
command += f" {velocity_lim}"
if torque_lim is not None:
command += f" {torque_lim}"
self.send_command(command)

def motor_position_stream(self, motor: int, position: float, velocity_ff: float = 0.0, torque_ff: float = 0.0):
command = f"p {motor} {position} {velocity_ff} {torque_ff}"
self.send_command(command)

def motor_velocity(self, motor: int, velocity: float, torque_ff: float = 0.0):
command = f"v {motor} {velocity} {torque_ff}"
self.send_command(command)

def motor_current(self, motor: int, torque: float):
command = f"c {motor} {torque}"
self.send_command(command)

def request_feedback(self, motor: int):
command = f"f {motor}"
self.send_command(command)
return self.read_response()

def update_watchdog(self, motor: int):
command = f"u {motor}"
self.send_command(command)

def read_parameter(self, property_name: str):
command = f"r {property_name}"
self.send_command(command)
return self.read_response()

def write_parameter(self, property_name: str, value: float):
command = f"w {property_name} {value}"
self.send_command(command)

def system_command(self, command_type: str):
valid_commands = {"ss", "se", "sr", "sc"}
if command_type not in valid_commands:
raise ValueError(f"Invalid system command: {command_type}")
self.send_command(command_type)

def close(self):
self.serial.close()
```

### Usage Example
```python
# Example usage
odrive = ODriveAsciiProtocol(port='/dev/ttyACM0')
odrive.motor_position(0, -2, velocity_lim=1, torque_lim=0.1)
feedback = odrive.request_feedback(0)
print(f"Motor feedback: {feedback}")
odrive.close()
```

This class provides a Pythonic way to interact with the ODrive via the ASCII protocol, supporting motor control, parameter management, and system operations.
Loading