Skip to content

Commit

Permalink
add param adjust for hero, set default baud 230400
Browse files Browse the repository at this point in the history
  • Loading branch information
tz61 committed Mar 13, 2024
1 parent e98b77b commit a9a7db1
Show file tree
Hide file tree
Showing 9 changed files with 641 additions and 7 deletions.
23 changes: 17 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -417,16 +417,27 @@ target_compile_definitions(ut_damiao_motor PRIVATE ut_damiao_motor)

# Gimbal: include CANInterface, GimbalInterface, GimbalController, GimbalFeedbackThread and adjustment modules.

set(pa_gimbal_dir dev/application/param_adjusts/pa_infantry/)
add_executable(pa_gimbal
set(pa_infantry_dir dev/application/param_adjusts/pa_infantry)
add_executable(pa_infantry
${COMMON_SRC}
${AHRS_SRC}
${CAN_SRC}
dev/interface/remote/remote_interpreter.cpp
${pa_gimbal_dir}can_motor_config.cpp
${pa_gimbal_dir}pa_infantry.cpp)
target_link_libraries(pa_gimbal ${AHRS_LIB})
target_include_directories(pa_gimbal PRIVATE ${pa_gimbal_dir})
${pa_infantry_dir}/can_motor_config.cpp
${pa_infantry_dir}/pa_infantry.cpp)
target_link_libraries(pa_infantry ${AHRS_LIB})
target_include_directories(pa_infantry PRIVATE ${pa_infantry_dir})

set(pa_hero_dir dev/application/param_adjusts/pa_hero)
add_executable(pa_hero
${COMMON_SRC}
${AHRS_SRC}
${CAN_SRC}
dev/interface/remote/remote_interpreter.cpp
${pa_hero_dir}/can_motor_config.cpp
${pa_hero_dir}/pa_hero.cpp)
target_link_libraries(pa_hero ${AHRS_LIB})
target_include_directories(pa_hero PRIVATE ${pa_hero_dir})

add_executable(ca_ahrs_infantry
dev/interface/ahrs/ahrs_math.hpp
Expand Down
7 changes: 7 additions & 0 deletions config/RM_Board_F3X.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source [find interface/stlink.cfg]


transport select hla_swd


source [find target/stm32f3x.cfg]
67 changes: 67 additions & 0 deletions dev/application/param_adjusts/pa_hero/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# PA INFANTRY步兵调参固件
此target是为步兵编写的调参固件。这个固件取消了电机之间的界限,将每个电机看作独立的轴,每个电机的PID参数都可单独调整。你甚至可以为步兵底盘电机调整角度PID,对底盘M3508电机进行角度闭环控制(虽然不知道有什么用,但这听上去很酷)。

## 程序结构
本程序基本沿用了infantry application内的文件, 包含 `hardware_conf.h`,`can_motor_config`,`thread_priorities.h`,以及`pa_infantry.cpp`

### pa_infantry.cpp
`pa_infantry.cpp`是调参的主程序文件,包含了调参的各类shell commands以及remote controller测试程序。

在遥控器左上拨钮拨到上方时,所有电机关闭并失去动力。

在遥控器左上拨钮拨到中间时,整机进入调试状态,用户可以通过发送shell command调试各个电机的角度或者速度PID。

在遥控器左上拨钮拨到下方时,整机进入测试状态,用户可以通过遥控器验证PID参数效果。

pa_infantry包含的shell command API会在文尾列出。

### hardware_conf.h
`hardware_conf.h`通过配置文件内TRUE/FALSE开启、关闭特定功能。
目前,用户可以改变 `#define ENABLE_USB_SHELL` 宏定义切换Shell显示方式。

`ENABLE_USB_SHELL``TRUE`,你可以通过USB虚拟串口接入Shell。但是,由于USB虚拟串口包含接收验证,在USB断开时,调用Shell发送数据的线程会被Shell printf命令卡住导致机器停止接收命令。

`ENABLE_USB_SHELL``FALSE`, 你可以通过UART6口,连接USB转TTL模块接入shell。此种方式不会导致某些调用Shell printf命令的线程卡死。

不过,由于大部分线程已经对Shell printf进行了分离,不管是使用USB虚拟串口还是UART6口,断开都只会影响命令接收而不会影响主功能(电机控制PID,遥控器)卡死。

### thread_priorities.h
`thread_priorities.h`包含了线程的优先级,由于作者较懒和考虑到未来开发可能在调参程序中加入的功能,这个文件是直接从infantry拷贝过来的,有较多冗余的priorities。

### can_motor_config
`can_motor_config` 类决定了电机的数量、以及对应电机的型号和`SID`。此外,`can_motor_config`中还包含了一组电机的初始PID参数。在每次重启后,即使你不设置pid电机仍然是可以动起来的,这不是灵异现象。
关于详细的`can_motor_config`介绍,请阅读`dev/interface/can_motor`下的`README`文档。

## pa_infantry Shell 命令一览
| 命令头 | 数据 | 详细描述 |
|:------------------|:-----:|:-----------------------:|
| set_enable_a | motor_id | 启动角度PID闭环控制(串级PID) |
| set_disable_a | motor_id | 关闭角度PID闭环控制(并将力矩输出调整为0) |
| set_enable_v | motor_id | 启动速度PID闭环控制 |
| set_disable_v | motor_id | 关闭速度PID闭环控制 |
| get_sid | motor_id | 得到某个电机的CAN SID |
| fb_enable | motor_id | 将某个电机的反馈数据显示在Shell上 |
| fb_disable | motor_id | 停止把某个电机的反馈数据显示在Shell上 |
| set_pid | motor_id pid_id(0: angle_to_v, 1: v_to_i) ki kp kd i_limit out_limit | 设置PID参数 |
| echo_pid | motor_id pid_id(0: angle_to_v, 1: v_to_i) | 读取正在使用的PID参数 |
| set_target_angle | motor_id target_angle | 设置电机目标角度 |
| set_target_vel | motor_id target_vel | 设置电机目标速度 |
| echo_actual_angle | motor_id | 反馈电机累计角度 |
| echo_raw_angle | motor_id | 反馈电机原始转子角度(-8192~8192) |

关于Shell反馈数据格式,在CANMotorController的DOXYGEN documentation中有解释:
```
!fb, %u, %u, %.2f, %.2f, %.2f, %.2f, %d, %d\r\n
| | | | | | | |
| | actual target actual target actual target
time id angle angle velocity velocity current current
```
其中,`!fb`是行头,标志这行是反馈数据。

`time`为反馈数据的时间戳,从STM32开机开始计时,单位为毫秒。

`id`为电机ID,和`can_motor_config`中的`motor_id_t` enumerator相对应,**并非SID!**

其余的就不一一阐述了。

希望有兴趣的同学可以通过此写出自己的GUI调参软件 :D
48 changes: 48 additions & 0 deletions dev/application/param_adjusts/pa_hero/can_motor_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// Created by 钱晨 on 11/14/21.
//

#include "can_motor_config.h"

CANMotorBase CANMotorCFG::CANMotorProfile[MOTOR_COUNT] = {
{CANMotorBase::can_channel_2, 0x202, CANMotorBase::M3508, 3572},//Front Left
{CANMotorBase::can_channel_2, 0x201, CANMotorBase::M3508, 3572},//Front Right
{CANMotorBase::can_channel_2, 0x204, CANMotorBase::M3508, 3572},//Back Right
{CANMotorBase::can_channel_2, 0x203, CANMotorBase::M3508, 3572},//Back Left
{CANMotorBase::can_channel_2, 0x208, CANMotorBase::GM6020, 1994},//Yaw
{CANMotorBase::can_channel_1, 0x205, CANMotorBase::GM6020, 3301},//PITCH 侧面的6020
{CANMotorBase::can_channel_1, 0x201, CANMotorBase::M3508_without_deceleration, 3344},
{CANMotorBase::can_channel_2, 0x206, CANMotorBase::M3508, 3572}, //Bullet Loader
{CANMotorBase::can_channel_1, 0x203, CANMotorBase::M3508_without_deceleration, 3572},//FW_UP(左边)
{CANMotorBase::can_channel_1, 0x204, CANMotorBase::M3508_without_deceleration, 3572}//FW_DOWN
};

PIDController::pid_params_t CANMotorCFG::a2vParams[MOTOR_COUNT] = {
{10, 0.0f, 0.2, 100, 500},
{10, 0.0f, 0.2, 100, 500},
{10, 0.0f, 0.2, 100, 500},
{10, 0.0f, 0.2, 100, 500},
{10, 0.0f, 0.1, 70, 90},
{8.5, 0.0f, 0.1, 70, 90},
{10, 0.0f, 0.2, 100, 500},
{50, 0.0f, 0.18, 100, 250},//Bullet Loader temprarily to 2.5x to surpass the friction
{10, 0.0f, 0.2, 100, 500},
{10, 0.0f, 0.2, 100, 500},
};

PIDController::pid_params_t CANMotorCFG::v2iParams[MOTOR_COUNT] = {
{26.0f,0.1f,0.02f,2000.0,6000.0},
{26.0f,0.1f,0.02f,2000.0,6000.0},
{26.0f,0.1f,0.02f,2000.0,6000.0},
{26.0f,0.1f,0.02f,2000.0,6000.0},
{50.0f, 0.0f, 0.0f, 5000.0f, 15000.0f},
{ 50.0f, 0.0f, 0.00f, 5000.0f, 15000.0f},
{26.0f, 0.1f, 0.02f, 2000.0f, 6000.0f},
{35.0f, 2.1f, 0.0f, 3000.0f, 16383.0f},//Bullet Loader
{26.0f, 0.1f, 0.02f, 2000.0f, 6000.0f},
{26.0f, 0.1f, 0.02f, 2000.0f, 6000.0f}
};

/// Will assigned by each scheduler.
bool CANMotorCFG::enable_a2v[MOTOR_COUNT] {false};
bool CANMotorCFG::enable_v2i[MOTOR_COUNT] {false};
35 changes: 35 additions & 0 deletions dev/application/param_adjusts/pa_hero/can_motor_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Created by 钱晨 on 11/14/21.
//

#ifndef META_INFANTRY_CANBUS_MOTOR_CFG_H
#define META_INFANTRY_CANBUS_MOTOR_CFG_H

#include "can_motor_feedback.h"
#include "pid_controller.hpp"

class CANMotorCFG {
public:
enum motor_id_t {
FL,
FR,
BR,
BL,
YAW,
PITCH,
SUB_PITCH,
BULLET_LOADER,
FW_UP,
FW_DOWN,
MOTOR_COUNT
};
static CANMotorBase CANMotorProfile[MOTOR_COUNT];

// Parameters for double loop PID control.
static PIDController::pid_params_t a2vParams [MOTOR_COUNT];
static PIDController::pid_params_t v2iParams [MOTOR_COUNT];
static bool enable_a2v[MOTOR_COUNT];
static bool enable_v2i[MOTOR_COUNT];
};

#endif //META_INFANTRY_CANBUS_MOTOR_CFG_H
33 changes: 33 additions & 0 deletions dev/application/param_adjusts/pa_hero/hardware_conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Created by 钱晨 on 3/16/22.
// This file contains some feature enabling masks.
//

#ifndef META_INFANTRY_HARDWARE_CONF_H
#define META_INFANTRY_HARDWARE_CONF_H

#if !defined(ENABLE_VISION) || defined(__DOXYGEN__)
#define ENABLE_VISION FALSE
#endif

#if !defined(ENABLE_REFEREE) || defined(__DOXYGEN__)
#define ENABLE_REFEREE FALSE
#endif

#if !defined(ENABLE_AHRS) || defined(__DOXYGEN__)
#define ENABLE_AHRS TRUE
#endif

#if !defined(ENABLE_SUBPITCH) || defined(__DOXYGEN__)
#define ENABLE_SUBPITCH FALSE
#endif

#if !defined(ENABLE_CAPACITOR) || defined(__DOXYGEN__)
#define ENABLE_CAPACITOR TRUE
#endif

#if !defined(ENABLE_USB_SHELL) || defined(__DOXYGEN__)
#define ENABLE_USB_SHELL FALSE
#endif

#endif //META_INFANTRY_HARDWARE_CONF_H
Loading

0 comments on commit a9a7db1

Please sign in to comment.