This repository has been archived on 2026-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
hero/Mecanum Wheel moving project 1/Core/Inc/M3508.h
2025-11-27 20:08:38 +08:00

42 lines
1.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __M3508_H
#define __M3508_H
#include "main.h"
#include "PID.h"
// 底盘参数(根据实际机械结构调整)
#define WHEEL_RADIUS 0.075f// 轮子半径 (米)
#define WHEELBASE_WIDTH 0.21f // 轮距宽度/2 (米)
#define WHEELBASE_LENGTH 0.17f // 轮距长度/2 (米)
typedef struct
{
uint16_t ecd;//编码器值 -16384--+16384
int16_t speed_rpm;//转速 转每分钟
int16_t given_current;//输出电流值
uint8_t temperate;//电机温度
int16_t last_ecd;//上次编码器值
} motor_measure_t;
// 电机控制结构体
typedef struct {
motor_measure_t measure; // 电机测量值速度单位RPM
PID_Controller_t speed_pid; // 速度环PID
float target_speed; // 目标速度 (rad/s)
} Motor_Controller_t;
extern motor_measure_t motor_chassis[4];
extern Motor_Controller_t motor_controller[4];
extern int16_t motor_commands[4];
extern void CAN_cmd_chassis(int16_t motor1, int16_t motor2, int16_t motor3, int16_t motor4);
extern float RPM_To_RadPerSec(int16_t rpm);
extern int16_t RadPerSec_To_RPM(float rad_per_sec);
extern void Set_Motor_Target_Speed(uint8_t motor_id, float target_speed_rad_s);
extern void Motor_Speed_Control_Task(float dt);
extern void Drive_Motor(float vx, float vy, float vz);
extern float Map_Remote_to_Speed(int16_t input, float max_speed);
extern void Process_Remote_Control(void);
#endif