Commit cf4aa560 authored by Wenxi Xu's avatar Wenxi Xu
Browse files

Documents added at Documents/, EKF is not done yet.

parent 8fdbeacd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
        {
            "label": "Build",
            "type": "shell",
            "command": "west build -p always -b robomaster_board_c motor",
            "command": "west build -p always -b robomaster_board_c IMU",
            "args": [],
            "options": {
                "env": {
+3 −2
Original line number Diff line number Diff line
/*	
 * Copyright (c) 2021-2022 Henrik Brix Andersen <henrik@brixandersen.dk>
 * Copyright (c) 2024 ttwards <12411711@mail.sustech.edu.cn>
 *
 * SPDX-License-Identifier: Apache-2.0
 */
@@ -100,7 +100,8 @@ void console_feedback(void *arg1, void *arg2, void *arg3) {
        float gyro_z   = (float)gyro_data[2].val1 + (float)gyro_data[2].val2 / 1000000.0f;
        float gryo_c   = sqrtf(powf(gyro_x, 2) + powf(gyro_y, 2) + powf(gyro_z, 2));
        float temp_raw = ((float)temp_data.val1 + (float)temp_data.val2 / 1000000.0f);
        LOG_INF("accel: x %.3f y %.3f z %.3f\n", (double)accel_x, (double)accel_y, (double)accel_z);
        LOG_INF("accel: x %.3f y %.3f z %.3f\n", (double)accel_x, (double)accel_y,
                (double)accel_z);
        LOG_INF("gyro: x %.3f y %.3f z %.3f\n", (double)gyro_x, (double)gyro_y, (double)gyro_z);
        LOG_INF("IMU Temp: %.3f\n", (double)temp_raw);
        // LOG_INF("TEMP MSB: %d LSB: %d\n", temp_data.val1, temp_data.val2);

Documents/motor/README.md

deleted100644 → 0
+0 −1
Original line number Diff line number Diff line
## 电机驱动API

Documents/motor/api.md

0 → 100644
+39 −0
Original line number Diff line number Diff line
# 电机驱动API
```c
motor_driver_api {
    float motor_get_speed(const struct device *dev);
    float motor_get_torque(const struct device *dev);
    float motor_get_angle(const struct device *dev);
    int motor_set_speed(const struct device *dev, float speed_rpm);
    int motor_set_torque(const struct device *dev, float torque);
    int motor_set_angle(const struct device *dev, float angle);
    int motor_set_mode(const struct device *dev, enum motor_mode mode);
    void motor_control(const struct device *dev, enum motor_cmd cmd);
};
```
```c
/**
 * @brief 电机工作模式
 * 
 * MIT: MIT模式
 * PV: 位置-速度控制
 * VO: 速度控制  
 * MULTILOOP: 多环串联控制
 */
enum motor_mode { MIT, PV, VO, MULTILOOP };
```
```c
/**
 * @brief 电机控制命令
 */
enum motor_cmd { ENABLE_MOTOR, DISABLE_MOTOR, SET_ZERO_OFFSET, CLEAR_PID, CLEAR_ERROR };
```
## 电机状态获取
`motor_get_speed(const struct device *dev)`: 获取电机当前速度,返回值为电机当前速度,单位为rpm。
`motor_get_torque(const struct device *dev)`: 获取电机当前扭矩,返回值为电机当前扭矩,单位为N*m。
`motor_get_angle(const struct device *dev)`: 获取电机当前角度,返回值为电机当前角度,单位为°。
`motor_set_speed(const struct device *dev, float speed_rpm)`: 设置电机目标速度,参数为目标速度,单位为rpm。
`motor_set_torque(const struct device *dev, float torque)`: 设置电机目标扭矩,参数为目标扭矩,单位为N*m。
`motor_set_angle(const struct device *dev, float angle)`: 设置电机目标角度,参数为目标角度,单位为°。
`motor_set_mode(const struct device *dev, enum motor_mode mode)`: 设置电机工作模式,参数为工作模式。
`motor_control(const struct device *dev, enum motor_cmd cmd)`: 控制电机,参数为控制命令。
 No newline at end of file
+93 −0
Original line number Diff line number Diff line
# 电机驱动 Device Tree 配置
### DJI Motor Device Tree Properties
- `compatible`: 必须是"dji,motor"
  - `is_m3508`: 电机型号,可选
  - `is_m2006`: 电机型号,可选
  - `is_gm6020`: 电机型号,可选
- `id`: 电机编号
- `rx_id`: 电机接收ID
- `tx_id`: 电机发送ID
- `gear_ratio`: 减速比(需要乘100)
- `status` = "okay": 启用电机
- `can_channel`: CAN总线节点
- `controllers`: PID控制器节点,是从前到后的串联环,暂时不支持MIT模式
- `capabilities`: 指定PID环对应的控制对象,可选
  - "angle": 角度控制
  - "speed": 速度控制
```dts
\ {
	motor1 {
		compatible = "dji,motor";
        is_m3508;
		id = <1>;
    	rx_id = <0x201>;
        tx_id = <0x200>;
		gear_ratio = <1920>;
		status = "okay";
		can_channel = <&canbus1>;
		controllers = <&angle_pid_1 &speed_pid_1>;
		capabilities = "angle", "speed";
	};
};
```
#### 请注意,必须存在对应capabilities属性,否则电机驱动只能使用力矩控制
### 达妙电机 Device Tree Properties
- `compatible`: 必须是"dm,motor"
- `id`: 电机编号
- `tx_id`: 电机发送ID
- `rx_id`: 电机接收ID
- `can_channel`: CAN总线节点
- `gear_ratio`: 减速比(需要乘100)
- `controllers`: PID控制器节点,按顺序指定各控制环
- `capabilities`: 指定控制模式,可选:
  - "mit": MIT力矩控制
  - "pv": 位置-速度双环控制
  - "vo": 速度-电流双环控制
- `v_max`: 最大速度限制(需要乘10)
- `p_max`: 最大角度限制(需要乘10)
- `t_max`: 最大扭矩限制(需要乘10)
```dts
/ {
	motor1: motor1{
		compatible = "dm,motor";
		id = <24>;
		rx_id = <24>;
		tx_id = <86>;
		gear_ratio = <100>;
		status = "okay";
		can_channel = <&canbus1>;
		controllers = <&mit_pid_0>;
		capabilities = "mit";
		p_max = <125>;
		v_max = <450>;
		t_max = <100>;
	};
};
```

### PID Device Tree Properties
- `#controller-cells`: 必须是<0>
- `compatible`: 必须是"pid,single"
- `k_p`: 比例系数(乘100)
- `k_i`: 积分系数(乘10)
- `k_d`: 微分系数(乘10)
```dts
\ {
	pid {
		angle_pid_1: angle_pid_1 {
			#controller-cells = <0>;
			compatible = "pid,single";
			k_p = <700>;
			k_i = <3>;
			k_d = <800>;
		};
		speed_pid_1: speed_pid_1 {
			#controller-cells = <0>;
			compatible = "pid,single";
			k_p = <880>;
			k_i = <20>;
			k_d = <20>;
		};
	};
};
```
 No newline at end of file
Loading