陀螺仪的初级数据获取
This commit is contained in:
26
app/by_imu.c
Normal file
26
app/by_imu.c
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "by_imu.h"
|
||||||
|
#include "zf_common_headfile.h"
|
||||||
|
|
||||||
|
float imu_acc_x;
|
||||||
|
float imu_acc_y;
|
||||||
|
float imu_acc_z;
|
||||||
|
float imu_gyro_x;
|
||||||
|
float imu_gyro_y;
|
||||||
|
float imu_gyro_z;
|
||||||
|
|
||||||
|
void by_imu_data_get(void)
|
||||||
|
{
|
||||||
|
imu660ra_get_acc();
|
||||||
|
imu660ra_get_gyro();
|
||||||
|
imu660ra_get_temperature();
|
||||||
|
|
||||||
|
imu_acc_x = imu660ra_acc_transition(imu660ra_acc_x);
|
||||||
|
imu_acc_y = imu660ra_acc_transition(imu660ra_acc_y);
|
||||||
|
imu_acc_z = imu660ra_acc_transition(imu660ra_acc_z);
|
||||||
|
|
||||||
|
imu_gyro_x = imu660ra_gyro_transition(imu660ra_gyro_x);
|
||||||
|
imu_gyro_y = imu660ra_gyro_transition(imu660ra_gyro_y);
|
||||||
|
imu_gyro_z = imu660ra_gyro_transition(imu660ra_gyro_z);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
15
app/by_imu.h
Normal file
15
app/by_imu.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef _BY_IMU_H__
|
||||||
|
#define _BY_IMU_H__
|
||||||
|
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "ch32v30x.h"
|
||||||
|
|
||||||
|
extern float imu_acc_x;
|
||||||
|
extern float imu_acc_y;
|
||||||
|
extern float imu_acc_z;
|
||||||
|
extern float imu_gyro_x;
|
||||||
|
extern float imu_gyro_y;
|
||||||
|
extern float imu_gyro_z;
|
||||||
|
|
||||||
|
extern void by_imu_data_get(void);
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "by_pt_button.h"
|
#include "by_pt_button.h"
|
||||||
#include "zf_common_headfile.h"
|
#include "zf_common_headfile.h"
|
||||||
|
#include "by_imu.h"
|
||||||
uint8_t potate_button;
|
uint8_t potate_button;
|
||||||
|
|
||||||
void by_gpio_init(void)
|
void by_gpio_init(void)
|
||||||
{
|
{
|
||||||
gpio_init(E10, GPI, GPIO_HIGH, GPI_PULL_UP);
|
gpio_init(E10, GPI, GPIO_HIGH, GPI_PULL_UP);
|
||||||
@@ -21,7 +23,32 @@ uint8_t by_get_pb_statu(void)
|
|||||||
|
|
||||||
void by_ips_show(void)
|
void by_ips_show(void)
|
||||||
{
|
{
|
||||||
ips114_show_string(0, 0, "button statu:");
|
ips200_show_string(0, 0, "button statu:");
|
||||||
ips114_show_uint(104, 0, by_get_pb_statu(), 1);
|
// ips200_show_uint(104, 0, by_get_pb_statu(), 1);
|
||||||
|
switch (by_get_pb_statu()) {
|
||||||
}
|
case 1:
|
||||||
|
ips200_show_string(104, 0, "press");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
ips200_show_string(104, 0, "up ");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
ips200_show_string(104, 0, "down ");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ips200_show_string(104, 0, " ");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// 按钮
|
||||||
|
ips200_show_string(0, 16, "imu:");
|
||||||
|
ips200_show_float(46, 16, imu_acc_x, 2, 2);
|
||||||
|
ips200_show_float(106, 16, imu_acc_y, 2, 2);
|
||||||
|
ips200_show_float(166, 16, imu_acc_z, 2, 2);
|
||||||
|
ips200_show_float(46, 32, imu_gyro_x, 2, 2);
|
||||||
|
ips200_show_float(106, 32, imu_gyro_y, 2, 2);
|
||||||
|
ips200_show_float(166, 32, imu_gyro_z, 2, 2);
|
||||||
|
ips200_show_float(46, 48, imu660ra_temperature, 2, 2);
|
||||||
|
printf("%d,%d,%d\n",(int16_t)(imu_gyro_x*10),(int16_t)(imu_gyro_y*10),(int16_t)(imu_gyro_z*10));
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,8 +8,10 @@
|
|||||||
#define POTATE_BUTTOM_BACKWARD 3
|
#define POTATE_BUTTOM_BACKWARD 3
|
||||||
extern uint8_t potate_button;
|
extern uint8_t potate_button;
|
||||||
|
|
||||||
|
|
||||||
extern void by_exit_init(void);
|
extern void by_exit_init(void);
|
||||||
extern void by_gpio_init(void);
|
extern void by_gpio_init(void);
|
||||||
extern uint8_t by_get_pb_statu(void);
|
extern uint8_t by_get_statu(void);
|
||||||
extern void by_ips_show(void);
|
extern void by_ips_show(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -198,10 +198,11 @@ void EXTI9_5_IRQHandler(void)
|
|||||||
EXTI_ClearITPendingBit(EXTI_Line9);
|
EXTI_ClearITPendingBit(EXTI_Line9);
|
||||||
if (SET == gpio_get_level(E10)) {
|
if (SET == gpio_get_level(E10)) {
|
||||||
potate_button = POTATE_BUTTOM_BACKWARD;
|
potate_button = POTATE_BUTTOM_BACKWARD;
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
potate_button = POTATE_BUTTOM_FOREWARD;
|
potate_button = POTATE_BUTTOM_FOREWARD;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,6 +223,7 @@ void EXTI15_10_IRQHandler(void)
|
|||||||
system_delay_us(200);
|
system_delay_us(200);
|
||||||
if (SET == !gpio_get_level(E11)) {
|
if (SET == !gpio_get_level(E11)) {
|
||||||
potate_button = POTATE_BUTTOM_PRESS;
|
potate_button = POTATE_BUTTOM_PRESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (SET == EXTI_GetITStatus(EXTI_Line12)) {
|
if (SET == EXTI_GetITStatus(EXTI_Line12)) {
|
||||||
|
|||||||
50
app/main.c
50
app/main.c
@@ -37,9 +37,10 @@
|
|||||||
#include "cw_servo.h"
|
#include "cw_servo.h"
|
||||||
#include "by_pt_button.h"
|
#include "by_pt_button.h"
|
||||||
#include "by_fan_control.h"
|
#include "by_fan_control.h"
|
||||||
|
#include "by_imu.h"
|
||||||
|
|
||||||
uint8 (*Img_Gray)[MT9V03X_W]; // <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> MT9V03X_W <20>е<EFBFBD> uint8 <20><><EFBFBD>͵Ķ<CDB5>ά<EFBFBD><CEAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
uint8 (*Img_Gray)[MT9V03X_W]; // <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD> MT9V03X_W <20>е<EFBFBD> uint8 <20><><EFBFBD>͵Ķ<CDB5>ά<EFBFBD><CEAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
||||||
//uint8 *mt9v03x_image_copy[0]; // <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8> uint8 <20><><EFBFBD>͵<EFBFBD>һά<D2BB><CEAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
// uint8 *mt9v03x_image_copy[0]; // <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8> uint8 <20><><EFBFBD>͵<EFBFBD>һά<D2BB><CEAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
|
||||||
sint32 pts_left[PT_MAXLEN][2], pts_right[PT_MAXLEN][2];
|
sint32 pts_left[PT_MAXLEN][2], pts_right[PT_MAXLEN][2];
|
||||||
sint32 pts_left_count, pts_right_count;
|
sint32 pts_left_count, pts_right_count;
|
||||||
float32 pts_inv_l[PT_MAXLEN][2], pts_inv_r[PT_MAXLEN][2];
|
float32 pts_inv_l[PT_MAXLEN][2], pts_inv_r[PT_MAXLEN][2];
|
||||||
@@ -51,8 +52,7 @@ sint32 pts_resample_left_count, pts_resample_right_count;
|
|||||||
float32 mid_left[PT_MAXLEN][2], mid_right[PT_MAXLEN][2];
|
float32 mid_left[PT_MAXLEN][2], mid_right[PT_MAXLEN][2];
|
||||||
sint32 mid_left_count, mid_right_count;
|
sint32 mid_left_count, mid_right_count;
|
||||||
|
|
||||||
|
// <20><><EFBFBD>ұ<EFBFBD><D2B1>߾ֲ<DFBE><D6B2>Ƕȱ仯<C8B1><E4BBAF>+<2B>Ǽ<EFBFBD><C7BC><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>
|
||||||
//<2F><><EFBFBD>ұ<EFBFBD><D2B1>߾ֲ<DFBE><D6B2>Ƕȱ仯<C8B1><E4BBAF>+<2B>Ǽ<EFBFBD><C7BC><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>
|
|
||||||
float angle_new_left[PT_MAXLEN];
|
float angle_new_left[PT_MAXLEN];
|
||||||
float angle_new_right[PT_MAXLEN];
|
float angle_new_right[PT_MAXLEN];
|
||||||
int angle_new_left_num, angle_new_right_num;
|
int angle_new_left_num, angle_new_right_num;
|
||||||
@@ -66,7 +66,7 @@ int angle_left_num, angle_right_num;
|
|||||||
// L<>ǵ<EFBFBD>
|
// L<>ǵ<EFBFBD>
|
||||||
int Lpt0_rpts0s_id, Lpt1_rpts1s_id;
|
int Lpt0_rpts0s_id, Lpt1_rpts1s_id;
|
||||||
bool Lpt0_found, Lpt1_found;
|
bool Lpt0_found, Lpt1_found;
|
||||||
int Lpt1[2],Lpt0[2];
|
int Lpt1[2], Lpt0[2];
|
||||||
|
|
||||||
int Lpt_in0_rpts0s_id, Lpt_in1_rpts1s_id;
|
int Lpt_in0_rpts0s_id, Lpt_in1_rpts1s_id;
|
||||||
bool Lpt_in0_found, Lpt_in1_found;
|
bool Lpt_in0_found, Lpt_in1_found;
|
||||||
@@ -85,44 +85,43 @@ float aim_distance;
|
|||||||
|
|
||||||
enum track_type_e track_type = TRACK_RIGHT;
|
enum track_type_e track_type = TRACK_RIGHT;
|
||||||
|
|
||||||
|
|
||||||
int frame_count = 0;
|
int frame_count = 0;
|
||||||
|
|
||||||
void img_processing();
|
void img_processing();
|
||||||
void get_corners();
|
void get_corners();
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
clock_init(SYSTEM_CLOCK_120M); // <20><>ʼ<EFBFBD><CABC>оƬʱ<C6AC><CAB1> <20><><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>Ϊ 120MHz
|
clock_init(SYSTEM_CLOCK_120M); // <20><>ʼ<EFBFBD><CABC>оƬʱ<C6AC><CAB1> <20><><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>Ϊ 120MHz
|
||||||
debug_init(); // <20><><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC>MPU ʱ<><CAB1> <20><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>
|
debug_init(); // <20><><EFBFBD>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC>MPU ʱ<><CAB1> <20><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>
|
||||||
mt9v03x_init();
|
// mt9v03x_init();
|
||||||
ips114_init();
|
ips200_init(IPS200_TYPE_SPI);
|
||||||
by_gpio_init();
|
by_gpio_init();
|
||||||
by_exit_init();
|
by_exit_init();
|
||||||
by_pwm_init();
|
by_pwm_init();
|
||||||
cw_servo_init();
|
cw_servo_init();
|
||||||
|
while (imu660ra_init())
|
||||||
|
;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
//while (frame_count < 20) {
|
// while (frame_count < 20) {
|
||||||
// if (mt9v03x_finish_flag) {
|
// if (mt9v03x_finish_flag) {
|
||||||
// memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t)));
|
// memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t)));
|
||||||
// adaptiveThreshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, 188, 120, 7, 8);
|
// adaptiveThreshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, 188, 120, 7, 8);
|
||||||
// //threshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, MT9V03X_W, MT9V03X_H, 110);
|
// //threshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, MT9V03X_W, MT9V03X_H, 110);
|
||||||
// ips114_show_gray_image(0, 0, mt9v03x_image_copy[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0);
|
// ips114_show_gray_image(0, 0, mt9v03x_image_copy[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0);
|
||||||
// mt9v03x_finish_flag = 0;
|
// mt9v03x_finish_flag = 0;
|
||||||
// frame_count++;
|
// frame_count++;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
//}
|
//}
|
||||||
if (mt9v03x_finish_flag) {
|
if (mt9v03x_finish_flag) {
|
||||||
//ips114_show_gray_image(0, 0, mt9v03x_image[0], 188, 120, 188, 120,0);
|
// ips114_show_gray_image(0, 0, mt9v03x_image[0], 188, 120, 188, 120,0);
|
||||||
memcpy(mt9v03x_image_copy[0], mt9v03x_image[0],(sizeof(mt9v03x_image_copy)/sizeof(uint8_t)));
|
memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t)));
|
||||||
//Img_Gray = mt9v03x_image;
|
// Img_Gray = mt9v03x_image;
|
||||||
//mt9v03x_image_copy[0] = Img_Gray[0];
|
// mt9v03x_image_copy[0] = Img_Gray[0];
|
||||||
mt9v03x_finish_flag = 0;
|
mt9v03x_finish_flag = 0;
|
||||||
|
|
||||||
|
|
||||||
state_type = COMMON_STATE;
|
state_type = COMMON_STATE;
|
||||||
img_processing();
|
img_processing();
|
||||||
|
|
||||||
@@ -137,10 +136,9 @@ int main(void)
|
|||||||
ElementRun();
|
ElementRun();
|
||||||
|
|
||||||
MidLineTrack();
|
MidLineTrack();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
by_imu_data_get();
|
||||||
|
by_ips_show();
|
||||||
|
system_delay_ms(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,10 +85,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 如果使用的是单排排针的两寸屏幕 SPI 驱动控制引脚 可以修改
|
// 如果使用的是单排排针的两寸屏幕 SPI 驱动控制引脚 可以修改
|
||||||
#define IPS200_RST_PIN_SPI (B7 ) // 液晶复位引脚定义
|
#define IPS200_RST_PIN_SPI (D8 ) // 液晶复位引脚定义
|
||||||
#define IPS200_DC_PIN_SPI (D7 ) // 液晶命令位引脚定义
|
#define IPS200_DC_PIN_SPI (D9 ) // 液晶命令位引脚定义
|
||||||
#define IPS200_CS_PIN_SPI (D4 )
|
#define IPS200_CS_PIN_SPI (D10 )
|
||||||
#define IPS200_BLk_PIN_SPI (D0 )
|
#define IPS200_BLk_PIN_SPI (D11 )
|
||||||
|
|
||||||
|
|
||||||
// --------------------单排两寸屏幕SPI接口引脚定义--------------------//
|
// --------------------单排两寸屏幕SPI接口引脚定义--------------------//
|
||||||
|
|||||||
Reference in New Issue
Block a user