-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
/****************************************************************************************************************** 2018年全国大学生恩智浦杯智能车竞赛 成都信息工程大学 成信WD队 作者QQ:97354734 全国预赛第五 比赛的速度只有2.6 实验室最高速度2.8 直立环 速度环(40ms)->角度环(8ms)->角速度环(4ms) 转向环 偏差环(8ms) ->角速度环(4ms) 两个环相加 内环应该越快越好 但同时也要考虑到芯片的运算能力 对陀螺仪芯片应该最好采用SPI读取的 例如ICM20602 但时间仓促 没来得及测试 只用了MPU6050 全部控制在loop.c在主循环中调用完成 定时器仅用来计系统时间 不会出现任务中断的情况 采用PID+ADRC控制 受限于KEA128的运算能力 只使用了TD环节对速度环的输出和速度的输出做了平滑处理 对坡道和颠簸时轮速产生的突变有消除作用 环岛处理在EM.c中 采用阈值检测和有限状态机实现 作为代码的搬运工 移植了多种飞控的姿态及控制 分享才会有进步 *******************************************************************************************************************/
- Loading branch information
1 parent
662b698
commit a5355d4
Showing
311 changed files
with
63,182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/********************************************************************************************************************* | ||
* COPYRIGHT NOTICE | ||
* Copyright (c) 2017,逐飞科技 | ||
* All rights reserved. | ||
* 技术讨论QQ群:179029047 | ||
* | ||
* 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, | ||
* 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 | ||
* | ||
* @file KEA128_adc | ||
* @company 成都逐飞科技有限公司 | ||
* @author 逐飞科技(QQ3184284598) | ||
* @version v2.0 | ||
* @Software IAR 7.7 or MDK 5.23 | ||
* @Target core S9KEA128AMLK | ||
* @Taobao https://seekfree.taobao.com/ | ||
* @date 2017-11-6 | ||
********************************************************************************************************************/ | ||
|
||
|
||
#ifndef _KEA128_adc_h | ||
#define _KEA128_adc_h | ||
|
||
#include "misc.h" | ||
#include "common.h" | ||
#include "SKEAZ1284.h" | ||
#include "KEA128_port_cfg.h" | ||
|
||
typedef enum | ||
{ | ||
ADC0_SE0=0, //A0 | ||
ADC0_SE1, //A1 | ||
ADC0_SE2, //A6 | ||
ADC0_SE3, //A7 | ||
ADC0_SE4, //B0 | ||
ADC0_SE5, //B1 | ||
ADC0_SE6, //B2 | ||
ADC0_SE7, //B3 | ||
ADC0_SE8, //C0 | ||
ADC0_SE9, //C1 | ||
ADC0_SE10, //C2 | ||
ADC0_SE11, //C3 | ||
ADC0_SE12, //F4 | ||
ADC0_SE13, //F5 | ||
ADC0_SE14, //F6 | ||
ADC0_SE15 //F7 | ||
} ADCn_Ch; | ||
|
||
|
||
|
||
//精度位数 | ||
typedef enum ADC_nbit | ||
{ | ||
ADC_8bit = 0x00, | ||
ADC_10bit = 0x01, | ||
ADC_12bit = 0x02 | ||
} ADC_nbit; | ||
|
||
|
||
void adc_init(ADCn_Ch adcn_ch); | ||
uint16 adc_once(ADCn_Ch adcn_ch, ADC_nbit bit); | ||
void adc_stop(void); | ||
uint16 ad_ave(ADCn_Ch adcn_ch,ADC_nbit bit,uint8 N); | ||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/********************************************************************************************************************* | ||
* COPYRIGHT NOTICE | ||
* Copyright (c) 2017,逐飞科技 | ||
* All rights reserved. | ||
* 技术讨论QQ群:179029047 | ||
* | ||
* 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, | ||
* 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 | ||
* | ||
* @file KEA128_flash | ||
* @company 成都逐飞科技有限公司 | ||
* @author 逐飞科技(QQ3184284598) | ||
* @version v2.0 | ||
* @Software IAR 7.7 or MDK 5.23 | ||
* @Target core S9KEA128AMLK | ||
* @Taobao https://seekfree.taobao.com/ | ||
* @date 2017-11-6 | ||
********************************************************************************************************************/ | ||
|
||
|
||
|
||
#ifndef _KEA128_flash_h | ||
#define _KEA128_flash_h | ||
|
||
#include "misc.h" | ||
#include "common.h" | ||
#include "SKEAZ1284.h" | ||
#include "KEA128_port_cfg.h" | ||
|
||
#define FTF FTMRE | ||
|
||
#define SECTOR_SIZE (512) | ||
#define FLASH_SECTOR_NUM (256) //扇区数 | ||
#define FLASH_ALIGN_ADDR 4 //地址对齐整数倍 | ||
typedef uint32 FLASH_WRITE_TYPE; //flash_write 函数写入 的数据类型 | ||
|
||
|
||
|
||
|
||
//------------------------------------------------------------------------------------------------------------------- | ||
// @brief 使用宏定义对flash进行数据读取 | ||
// @param SectorNum 需要写入的扇区编号 | ||
// @param offset 地址偏移 | ||
// @param type 读取的数据类型 | ||
// @return 返回给定地址的数据 | ||
// @since v1.0 | ||
// Sample usage: flash_read(20,0,uint32);//读取20号扇区偏移0数据类型为uint32 | ||
//------------------------------------------------------------------------------------------------------------------- | ||
#define flash_read(SectorNum,offset,type) (*(type *)((uint32)(((SectorNum)*SECTOR_SIZE) + (offset)))) | ||
|
||
|
||
void FLASH_Init(void); | ||
uint32 FLASH_GetSectorSize(void); | ||
uint8 FLASH_EraseSector(uint32 SectorNum); | ||
uint8 FLASH_WriteSector(uint32 SectorNum, const uint8 *buf, uint32 len, uint32 offset); | ||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/********************************************************************************************************************* | ||
* COPYRIGHT NOTICE | ||
* Copyright (c) 2017,逐飞科技 | ||
* All rights reserved. | ||
* 技术讨论QQ群:179029047 | ||
* | ||
* 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, | ||
* 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 | ||
* | ||
* @file KEA128_ftm | ||
* @company 成都逐飞科技有限公司 | ||
* @author 逐飞科技(QQ3184284598) | ||
* @version v2.0 | ||
* @Software IAR 7.7 or MDK 5.23 | ||
* @Target core S9KEA128AMLK | ||
* @Taobao https://seekfree.taobao.com/ | ||
* @date 2017-11-6 | ||
********************************************************************************************************************/ | ||
|
||
#ifndef _KEA128_ftm_h | ||
#define _KEA128_ftm_h | ||
|
||
#include "common.h" | ||
#include "SKEAZ1284.h" | ||
#include "KEA128_port_cfg.h" | ||
|
||
typedef enum | ||
{ | ||
ftm0, | ||
ftm1, | ||
ftm2, | ||
} FTMn; | ||
|
||
|
||
typedef enum | ||
{ | ||
ftm_ch0, | ||
ftm_ch1, | ||
ftm_ch2, | ||
ftm_ch3, | ||
ftm_ch4, | ||
ftm_ch5, | ||
ftm_ch6, | ||
ftm_ch7, | ||
} FTM_CHn; | ||
|
||
|
||
//------------------------ PWM ------------------------ | ||
|
||
#define FTM0_PRECISON 1000u //定义占空比精度,意思即使把一个周期分成多少分,分多越多这样精度越高,设置占空比的时候duty的范围就是0-FTM0_PRECISON | ||
#define FTM1_PRECISON 1000u //定义占空比精度,意思即使把一个周期分成多少分,分多越多这样精度越高,设置占空比的时候duty的范围就是0-FTM0_PRECISON | ||
#define FTM2_PRECISON 1000u //定义占空比精度,意思即使把一个周期分成多少分,分多越多这样精度越高,设置占空比的时候duty的范围就是0-FTM0_PRECISON | ||
|
||
|
||
void ftm_pwm_init(FTMn ftmn, FTM_CHn ch, uint32 freq, uint32 duty); | ||
void ftm_pwm_duty(FTMn ftmn, FTM_CHn ch, uint32 duty); | ||
void ftm_pwm_freq(FTMn ftmn, uint32 freq) ; | ||
void ftm_count_init(FTMn ftmn); | ||
uint16 ftm_count_get(FTMn ftmn); | ||
void ftm_count_clean(FTMn ftmn); | ||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/********************************************************************************************************************* | ||
* COPYRIGHT NOTICE | ||
* Copyright (c) 2017,逐飞科技 | ||
* All rights reserved. | ||
* 技术讨论QQ群:179029047 | ||
* | ||
* 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, | ||
* 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 | ||
* | ||
* @file KEA128_gpio | ||
* @company 成都逐飞科技有限公司 | ||
* @author 逐飞科技(QQ3184284598) | ||
* @version v2.0 | ||
* @Software IAR 7.7 or MDK 5.23 | ||
* @Target core S9KEA128AMLK | ||
* @Taobao https://seekfree.taobao.com/ | ||
* @date 2017-11-6 | ||
********************************************************************************************************************/ | ||
|
||
|
||
#ifndef _KEA128_gpio_h | ||
#define _KEA128_gpio_h | ||
|
||
|
||
|
||
#include "misc.h" | ||
#include "common.h" | ||
#include "SKEAZ1284.h" | ||
#include "KEA128_port_cfg.h" | ||
|
||
|
||
//------------------------------------------------------------------------------------------------------------------- | ||
// @brief GPIO 8位端口地址定义 | ||
// @param x x取值范围 0:对应系统板上的A0-A7八个引脚 1:对应系统板上的B0-B7八个引脚 | ||
// 2:对应系统板上的C0-C7八个引脚 3:对应系统板上的D0-D7八个引脚 | ||
// @since v2.0 | ||
// Sample usage: A_PDOR8(2) = 0XFF; //C0-C7八个引脚输出高电平 | ||
//------------------------------------------------------------------------------------------------------------------- | ||
#define A_PDOR8(x) *(uint8 *)(FGPIOA_BASE+0x00+x) //定义A端口的8位输出地址 | ||
#define A_PSOR8(x) *(uint8 *)(FGPIOA_BASE+0x04+x) //定义A端口的8位置位地址 | ||
#define A_PCOR8(x) *(uint8 *)(FGPIOA_BASE+0x08+x) //定义A端口的8位清零地址 | ||
#define A_PTOR8(x) *(uint8 *)(FGPIOA_BASE+0x0C+x) //定义A端口的8位取反地址 | ||
#define A_PDIR8(x) *(uint8 *)(FGPIOA_BASE+0x10+x) //定义A端口的8位输入地址 | ||
#define A_PDDR8(x) *(uint8 *)(FGPIOA_BASE+0x14+x) //定义A端口的8位方向地址 | ||
#define A_PIDR8(x) *(uint8 *)(FGPIOA_BASE+0x18+x) //定义A端口的8位禁用地址 | ||
//------------------------------------------------------------------------------------------------------------------- | ||
// @brief GPIO 8位端口地址定义 | ||
// @param x x取值范围 0:对应系统板上的E0-E7八个引脚 1:对应系统板上的F0-F7八个引脚 | ||
// 2:对应系统板上的G0-G7八个引脚 3:对应系统板上的H0-H7八个引脚 | ||
// @since v2.0 | ||
// Sample usage: B_PDOR8(3) = 0XFF; //H0-H7八个引脚输出高电平 | ||
//------------------------------------------------------------------------------------------------------------------- | ||
#define B_PDOR8(x) *(uint8 *)(FGPIOB_BASE+0x00+x) //定义B端口的8位输出地址 | ||
#define B_PSOR8(x) *(uint8 *)(FGPIOB_BASE+0x04+x) //定义B端口的8位置位地址 | ||
#define B_PCOR8(x) *(uint8 *)(FGPIOB_BASE+0x08+x) //定义B端口的8位清零地址 | ||
#define B_PTOR8(x) *(uint8 *)(FGPIOB_BASE+0x0C+x) //定义B端口的8位取反地址 | ||
#define B_PDIR8(x) *(uint8 *)(FGPIOB_BASE+0x10+x) //定义B端口的8位输入地址 | ||
#define B_PDDR8(x) *(uint8 *)(FGPIOB_BASE+0x14+x) //定义B端口的8位方向地址 | ||
#define B_PIDR8(x) *(uint8 *)(FGPIOB_BASE+0x18+x) //定义B端口的8位禁用地址 | ||
//------------------------------------------------------------------------------------------------------------------- | ||
// @brief GPIO 8位端口地址定义 | ||
// @param x x取值范围 0:对应系统板上的I0-I7八个引脚 | ||
// @since v2.0 | ||
// Sample usage: B_PDOR8(0) = 0XFF; //I0-I7八个引脚输出高电平 | ||
//------------------------------------------------------------------------------------------------------------------- | ||
#define C_PDOR8(x) *(uint8 *)(FGPIOC_BASE+0x00+x) //定义C端口的8位输出地址 | ||
#define C_PSOR8(x) *(uint8 *)(FGPIOC_BASE+0x04+x) //定义C端口的8位置位地址 | ||
#define C_PCOR8(x) *(uint8 *)(FGPIOC_BASE+0x08+x) //定义C端口的8位清零地址 | ||
#define C_PTOR8(x) *(uint8 *)(FGPIOC_BASE+0x0C+x) //定义C端口的8位取反地址 | ||
#define C_PDIR8(x) *(uint8 *)(FGPIOC_BASE+0x10+x) //定义C端口的8位输入地址 | ||
#define C_PDDR8(x) *(uint8 *)(FGPIOC_BASE+0x14+x) //定义C端口的8位方向地址 | ||
#define C_PIDR8(x) *(uint8 *)(FGPIOC_BASE+0x18+x) //定义C端口的8位禁用地址 | ||
|
||
|
||
|
||
void gpio_init(PTX_n ptx_n, GPIO_MOD ddr, uint8 dat);//初始化gpio | ||
void gpio_ddr(PTX_n ptx_n, GPIO_MOD ddr); //设置引脚方向 | ||
uint8 gpio_get(PTX_n ptx_n); //获取引脚状态 | ||
void gpio_set(PTX_n ptx_n, uint8 dat); //设置引脚状态 | ||
void gpio_turn(PTX_n ptx_n); //翻转引脚状态 | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/********************************************************************************************************************* | ||
* COPYRIGHT NOTICE | ||
* Copyright (c) 2017,逐飞科技 | ||
* All rights reserved. | ||
* 技术讨论QQ群:179029047 | ||
* | ||
* 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, | ||
* 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 | ||
* | ||
* @file KEA128_i2c | ||
* @company 成都逐飞科技有限公司 | ||
* @author 逐飞科技(QQ3184284598) | ||
* @version v2.0 | ||
* @Software IAR 7.7 or MDK 5.23 | ||
* @Target core S9KEA128AMLK | ||
* @Taobao https://seekfree.taobao.com/ | ||
* @date 2017-11-6 | ||
********************************************************************************************************************/ | ||
|
||
|
||
#ifndef _KEA128_i2c_h | ||
#define _KEA128_i2c_h | ||
|
||
|
||
#include "misc.h" | ||
#include "common.h" | ||
#include "SKEAZ1284.h" | ||
#include "KEA128_port_cfg.h" | ||
#include "stdlib.h" | ||
|
||
typedef enum | ||
{ | ||
i2c0 = 0, | ||
i2c1 = 1 | ||
} I2Cn_e; | ||
|
||
typedef enum MSmode | ||
{ | ||
MWSR = 0x00, // 主机写模式 | ||
MRSW = 0x01 // 主机读模式 | ||
} MSmode; | ||
|
||
//仅支持 I2C主机模式 | ||
extern uint32 i2c_init(I2Cn_e i2cn, uint32 baud); //初始化I2C | ||
extern void i2c_write_reg(I2Cn_e, uint8 SlaveID, uint8 reg, uint8 Data); //写入数据到寄存器 | ||
extern uint8 i2c_read_reg (I2Cn_e, uint8 SlaveID, uint8 reg); //读取寄存器的数据 | ||
extern uint8 i2c_read_reg_bytes(I2Cn_e i2cn, uint8 SlaveID, uint8 reg, uint8 num, uint8 * addr); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/********************************************************************************************************************* | ||
* COPYRIGHT NOTICE | ||
* Copyright (c) 2017,逐飞科技 | ||
* All rights reserved. | ||
* 技术讨论QQ群:179029047 | ||
* | ||
* 以下所有内容版权均属逐飞科技所有,未经允许不得用于商业用途, | ||
* 欢迎各位使用并传播本程序,修改内容时必须保留逐飞科技的版权声明。 | ||
* | ||
* @file KEA128_irq | ||
* @company 成都逐飞科技有限公司 | ||
* @author 逐飞科技(QQ3184284598) | ||
* @version v2.0 | ||
* @Software IAR 7.7 or MDK 5.23 | ||
* @Target core S9KEA128AMLK | ||
* @Taobao https://seekfree.taobao.com/ | ||
* @date 2017-11-6 | ||
********************************************************************************************************************/ | ||
|
||
|
||
#ifndef _KEA128_irq_h | ||
#define _KEA128_irq_h | ||
|
||
#include "misc.h" | ||
#include "common.h" | ||
#include "SKEAZ1284.h" | ||
#include "KEA128_port_cfg.h" | ||
|
||
|
||
//中断标志位清除 | ||
#define CLEAR_IRQ_FLAG (IRQ->SC |= IRQ_SC_IRQACK_MASK) | ||
|
||
|
||
|
||
void irq_init(void); | ||
|
||
|
||
#endif |
Oops, something went wrong.