#include "inverse_solution.h"
wheel_speed W_S;
car_speed C_S;
void speed_inverse_solution()
{
W_S.Vw0 = C_S.Vx - C_S.Vy - C_S.W *(a+b);
W_S.Vw1 = C_S.Vx + C_S.Vy + C_S.W *(a+b);
W_S.Vw2 = C_S.Vx - C_S.Vy + C_S.W *(a+b);
W_S.Vw3 = C_S.Vx + C_S.Vy - C_S.W *(a+b);
}
#include "delay.h"
#include "sys.h"
#include "timer.h"
#include "motor_gpio.h"
#include "led.h"
#include "encoder.h"
#include "motor_operate.h"
#include "inverse_solution.h"
#include "pid.h"
#define a 0.0824
#define b 0.0665
#define TIM3_ARR 0XFFFF
#define TIM3_PSC 71
#define TIM4_ARR 100
#define TIM4_PSC 7199
#define MAX_RPM 70
#define waiting_forever 0
#define error -1
typedef struct motor
{
GPIO_TypeDef* motor_gpio_type[3];
GPIO_InitTypeDef motor_gpio[3];
}motor;
extern int scan;
extern motor Motors[];
extern u8 TIM3CH1_CAPTURE_STA;
extern u16 TIM3CH1_CAPTURE_VAL;
extern u8 TIM3CH2_CAPTURE_STA;
extern u16 TIM3CH2_CAPTURE_VAL;
extern u8 TIM3CH3_CAPTURE_STA;
extern u16 TIM3CH3_CAPTURE_VAL;
extern u8 TIM3CH4_CAPTURE_STA;
extern u16 TIM3CH4_CAPTURE_VAL;
extern u32 temp0;
extern u32 temp1;
extern u32 temp2;
extern u32 temp3;
extern u32 rpm0;
extern u32 rpm1;
extern u32 rpm2;
extern u32 rpm3;
typedef struct wheel_speed
{
float Vw0;
float Vw1;
float Vw2;
float Vw3;
}wheel_speed;
extern wheel_speed W_S;
typedef struct car_speed
{
float Vx;
float Vy;
float W;
}car_speed;
extern car_speed C_S;
#endif
#include "sys_conf.h"
u32 temp0 = 0;
u32 temp1 = 0;
u32 temp2 = 0;
u32 temp3 = 0;
u32 rpm0 = 0;
u32 rpm1 = 0;
u32 rpm2 = 0;
u32 rpm3 = 0;
int main(void)
{
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
LED_Init();
uart2_init(115200);
motor_init();
LED0 = 1;
C_S.Vx = 50;
C_S.Vy = 500;
C_S.W = 5;
speed_inverse_solution();
motor_run();
TIM_SetCompare1(TIM4,100);
TIM_SetCompare2(TIM4,100);
TIM_SetCompare3(TIM4,100);
TIM_SetCompare4(TIM4,100);
while(1)
{
int num = 1;
printf("rpm%d:%d \r\n",num,read_speed(num,waiting_forever,2));
}
}