can2我c你的

This commit is contained in:
Feelyx 2026-01-12 21:44:09 +08:00
parent e250fedca2
commit 35cf664580
5 changed files with 138 additions and 13 deletions

View File

@ -0,0 +1,122 @@
#include "module/arm.hpp"
#include "bsp/time.h"
Arm::Arm(){
dm_motor_params[0] = MOTOR_DM_Param_t{
.can = BSP_CAN_1,
.master_id = 0x11,
.can_id = 1,
.module = MOTOR_DM_J4310,
.reverse = false
};
dm_motor_params[1] = MOTOR_DM_Param_t{
.can = BSP_CAN_1,
.master_id = 0x12,
.can_id = 1,
.module = MOTOR_DM_J4310,
.reverse = false
};
dm_motor_params[2] = MOTOR_DM_Param_t{
.can = BSP_CAN_1,
.master_id = 0x13,
.can_id = 1,
.module = MOTOR_DM_J4310,
.reverse = false
};
lz_motor_params[0] = MOTOR_LZ_Param_t{
.can = BSP_CAN_1,
.motor_id = 127,
.host_id = 0xff,
.module= MOTOR_LZ_RSO3,
.reverse = false,
.mode = MOTOR_LZ_MODE_MOTION
};
lz_motor_params[1] = MOTOR_LZ_Param_t{
.can = BSP_CAN_1,
.motor_id = 126,
.host_id = 0xff,
.module= MOTOR_LZ_RSO3,
.reverse = false,
.mode = MOTOR_LZ_MODE_MOTION
};
lz_motor_params[2] = MOTOR_LZ_Param_t{
.can = BSP_CAN_1,
.motor_id = 125,
.host_id = 0xff,
.module= MOTOR_LZ_RSO3,
.reverse = false,
.mode = MOTOR_LZ_MODE_MOTION
};
}
void Arm::init(){
MOTOR_LZ_Init();
MOTOR_LZ_Register(&lz_motor_params[0]);
MOTOR_LZ_Enable(&lz_motor_params[0]);
BSP_TIME_Delay(2);
MOTOR_LZ_Register(&lz_motor_params[1]);
MOTOR_LZ_Enable(&lz_motor_params[1]);
BSP_TIME_Delay(2);
MOTOR_LZ_Register(&lz_motor_params[2]);
MOTOR_LZ_Enable(&lz_motor_params[2]);
BSP_TIME_Delay(2);
MOTOR_DM_Register(&dm_motor_params[0]);
MOTOR_DM_Enable(&dm_motor_params[0]);
BSP_TIME_Delay(2);
MOTOR_DM_Register(&dm_motor_params[1]);
MOTOR_DM_Enable(&dm_motor_params[1]);
BSP_TIME_Delay(2);
MOTOR_DM_Register(&dm_motor_params[2]);
MOTOR_DM_Enable(&dm_motor_params[2]);
BSP_TIME_Delay(2);
}
void Arm::operator()(){
MOTOR_DM_Relax(&dm_motor_params[0]);
BSP_TIME_Delay(2);
MOTOR_DM_Relax(&dm_motor_params[1]);
BSP_TIME_Delay(2);
MOTOR_DM_Relax(&dm_motor_params[2]);
BSP_TIME_Delay(2);
MOTOR_DM_UpdateAll();
MOTOR_DM_t *motor_dm = NULL;
motor_dm = MOTOR_DM_GetMotor(&dm_motor_params[0]);
arm_dm_motor[0] = *motor_dm;
motor_dm = MOTOR_DM_GetMotor(&dm_motor_params[1]);
arm_dm_motor[1] = *motor_dm;
motor_dm = MOTOR_DM_GetMotor(&dm_motor_params[2]);
arm_dm_motor[2] = *motor_dm;
arm_output[0].angle = 1.0f;
arm_output[0].velocity = 1.0f;
arm_output[0].kp = 0.5f;
arm_output[0].kd = 1.0f;
// MOTOR_DM_MITCtrl(&dm_motor_params[0], &arm_output[0]);
arm_state = MOTOR_LZ_Relax(&lz_motor_params[0]);
BSP_TIME_Delay(2);
MOTOR_LZ_Relax(&lz_motor_params[1]);
BSP_TIME_Delay(2);
MOTOR_LZ_Relax(&lz_motor_params[2]);
BSP_TIME_Delay(2);
MOTOR_LZ_UpdateAll();
MOTOR_LZ_t *motor_lz = NULL;
motor_lz = MOTOR_LZ_GetMotor(&lz_motor_params[0]);
arm_lz_motor[0] = *motor_lz;
motor_lz = MOTOR_LZ_GetMotor(&lz_motor_params[1]);
arm_lz_motor[1] = *motor_lz;
motor_lz = MOTOR_LZ_GetMotor(&lz_motor_params[2]);
arm_lz_motor[2] = *motor_lz;
// arm_lz_motion[0].target_angle = 1.0f;
arm_lz_motion[0].target_velocity = 1.0f;
// arm_lz_motion[0].kp = 0.5f;
arm_lz_motion[0].kd = 0.5f;
// MOTOR_LZ_MotionControl(&lz_motor_params[0], &arm_lz_motion[0]);
}

View File

@ -6,6 +6,7 @@
#include "device/motor_lz.h" #include "device/motor_lz.h"
#include "device/motor_rm.h" #include "device/motor_rm.h"
#include "device/motor_dm.h" #include "device/motor_dm.h"
#include <stdint.h>
class Arm { class Arm {
public: public:
@ -13,6 +14,11 @@ public:
void init(); void init();
void operator()(); void operator()();
private: private:
MOTOR_DM_Param_t motors_param[4]; MOTOR_DM_Param_t dm_motor_params[3];
MOTOR_t arm_motors[4]; MOTOR_DM_t arm_dm_motor[3];
MOTOR_LZ_Param_t lz_motor_params[3];
MOTOR_LZ_t arm_lz_motor[3];
MOTOR_LZ_MotionParam_t arm_lz_motion[3];
MOTOR_MIT_Output_t arm_output[3];
int8_t arm_state = 1;
}; };

View File

@ -1,13 +1,11 @@
#include "module/chassis.hpp" #include "module/chassis.hpp"
#include "bsp/can.h"
#include "device/motor_rm.h"
Chassis::Chassis() { Chassis::Chassis() {
motors_param[0] = { motors_param[0] = {
.can = BSP_CAN_1, .can = BSP_CAN_1,
.id = 0x201, .id = 0x206,
.module = MOTOR_M3508, .module = MOTOR_GM6020,
.reverse = false, .reverse = false,
.gear = true .gear = true
}; };
@ -35,7 +33,6 @@ Chassis::Chassis() {
} }
void Chassis::init() { void Chassis::init() {
BSP_CAN_Init();
MOTOR_RM_Register(&motors_param[0]); MOTOR_RM_Register(&motors_param[0]);
MOTOR_RM_Register(&motors_param[1]); MOTOR_RM_Register(&motors_param[1]);
MOTOR_RM_Register(&motors_param[2]); MOTOR_RM_Register(&motors_param[2]);

View File

@ -6,7 +6,7 @@
/* Includes ----------------------------------------------------------------- */ /* Includes ----------------------------------------------------------------- */
#include "task/user_task.h" #include "task/user_task.h"
/* USER INCLUDE BEGIN */ /* USER INCLUDE BEGIN */
#include "module/arm.hpp"
/* USER INCLUDE END */ /* USER INCLUDE END */
/* Private typedef ---------------------------------------------------------- */ /* Private typedef ---------------------------------------------------------- */
@ -14,7 +14,7 @@
/* Private macro ------------------------------------------------------------ */ /* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */ /* Private variables -------------------------------------------------------- */
/* USER STRUCT BEGIN */ /* USER STRUCT BEGIN */
Arm arm;
/* USER STRUCT END */ /* USER STRUCT END */
/* Private function --------------------------------------------------------- */ /* Private function --------------------------------------------------------- */
@ -30,13 +30,13 @@ void Task_ctrl_arm(void *argument) {
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */ uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
/* USER CODE INIT BEGIN */ /* USER CODE INIT BEGIN */
arm.init();
/* USER CODE INIT END */ /* USER CODE INIT END */
while (1) { while (1) {
tick += delay_tick; /* 计算下一个唤醒时刻 */ tick += delay_tick; /* 计算下一个唤醒时刻 */
/* USER CODE BEGIN */ /* USER CODE BEGIN */
arm();
/* USER CODE END */ /* USER CODE END */
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */ osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
} }

View File

@ -7,7 +7,7 @@
#include "task/user_task.h" #include "task/user_task.h"
/* USER INCLUDE BEGIN */ /* USER INCLUDE BEGIN */
#include "bsp/can.h"
/* USER INCLUDE END */ /* USER INCLUDE END */
/* Private typedef ---------------------------------------------------------- */ /* Private typedef ---------------------------------------------------------- */
@ -25,7 +25,7 @@
void Task_Init(void *argument) { void Task_Init(void *argument) {
(void)argument; /* 未使用argument消除警告 */ (void)argument; /* 未使用argument消除警告 */
/* USER CODE INIT BEGIN */ /* USER CODE INIT BEGIN */
BSP_CAN_Init();
/* USER CODE INIT END */ /* USER CODE INIT END */
osKernelLock(); /* 锁定内核,防止任务切换 */ osKernelLock(); /* 锁定内核,防止任务切换 */