基于Linux设计的倒车雷达系统

一、项目背景介绍随着社会的不断发展,人们对于汽车的安全性要求越来越高,而倒车雷达系统就是为了增强汽车驾驶者的安全性而被广泛使用。在这种情况下,我们开发了一个基于linux设计的倒车雷达系统,该系统可以采用迅为4412主控板,运行linux3.5内核,使用usb摄像头、tft真彩显示屏、超声波测距模块和蜂鸣器等硬件。
二、创新点本项目的创新点包括:
采用开源linux系统:采用linux系统,具有很好的可扩展性和灵活性,可以实现更为丰富和复杂的功能。多个模块的协同工作:本项目涉及到了摄像头模块、超声波测距模块、处理模块、告警模块和显示模块等多个模块,这些模块需要协同工作才能实现完整的功能。实现了告警功能:本项目采用了蜂鸣器来实现告警功能,根据距离调整pwm输出给出不同级别的告警声音,能够提醒驾驶者注意障碍物。三、使用技术介绍迅为4412主控板:本项目采用了迅为4412主控板,该主控板具有较高的性能和稳定性,能够满足系统的运行要求。linux操作系统:本项目采用了开源的linux操作系统,具有很好的可扩展性和灵活性,适合进行自定义开发。v4l2协议:v4l2协议是linux下的一个视频设备驱动程序接口,可以方便地实现usb摄像头的图像采集。超声波测距模块:通过gpio口与主控板相连,使用定时器产生超声波并计算与接收到回波之间的时间差,从而计算出与障碍物之间的距离。pwm输出控制:根据距离调整pwm输出给出不同级别的告警声音。tft真彩显示屏:本项目采用了tft真彩显示屏,能够实现高清晰度的图像显示。系统管理模块:负责管理整个系统的启动、配置和错误处理等操作。例如,可以将系统的启动脚本写在/etc/rc.local中,通过调用shell脚本来实现系统的初始化和启动。四、系统架构整个系统由以下几个模块组成:
摄像头模块:负责采集车尾环境图像,并传输给处理模块。超声波测距模块:负责与障碍物之间的距离测量,并将结果传输给处理模块。处理模块:负责视频显示、距离信息的处理、告警功能的实现。告警模块:负责根据距离调整pwm输出给出不同级别的告警声音,并使用蜂鸣器输出告警信息。显示模块:负责将处理模块生成的图像显示在tft真彩显示屏上。系统管理模块:负责管理整个系统的启动、配置和错误处理等操作。五、功能设计摄像头模块 由于linux系统具有很好的驱动支持,因此可以直接使用v4l2协议来获取usb摄像头的图像。获取图像后,需要通过dma方式将数据传输给处理模块进行处理。超声波测距模块 超声波测距模块可以通过gpio口与主控板相连,使用定时器产生超声波并计算与接收到回波之间的时间差,从而计算出与障碍物之间的距离。处理模块 处理模块负责将摄像头采集到的图像和超声波测距模块测得的距离信息整合处理,并根据距离信息来控制告警模块。告警模块 告警模块根据处理模块传递过来的距离信息来控制pwm输出,并使用蜂鸣器输出告警信息。显示模块 显示模块负责将处理模块生成的图像显示在tft真彩显示屏上,并实现显示屏的刷新和管理操作。系统管理模块 系统管理模块负责管理整个系统的启动、配置和错误处理等操作。例如,可以将系统的启动脚本写在/etc/rc.local中,通过调用shell脚本来实现系统的初始化和启动。六、摄像头图像显示应用代码#include #include /* see notes */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include ​ /* 图片的象素数据 */ typedef struct pixeldatas { int iwidth; /* 宽度: 一行有多少个象素 */ int iheight; /* 高度: 一列有多少个象素 */ int ibpp; /* 一个象素用多少位来表示 */ int ilinebytes; /* 一行数据有多少字节 */ int itotalbytes; /* 所有字节数 */ unsigned char *videobuf; //存放一帧摄像头的数据 //指向了存放摄像头数据的空间地址 }t_pixeldatas; ​ t_pixeldatas pixedata; //存放实际的图像数据 ​ /* usb摄像头相关参数定义 */ struct v4l2_buffer tv4l2buf; int ifd; int listnum; unsigned char* pucvidebuf[4]; // 视频buff空间地址 void camera_pthread(void); ​ //lcd屏相关的参数 unsigned char *lcd_mem=null; /*lcd的内存地址*/ struct fb_fix_screeninfo finfo; /*固定形参*/ struct fb_var_screeninfo vinfo; /*可变形参*/ void lcd_init(void); void show_pixel(int x,int y,int color); ​ ​ int main(int argc ,char *argv[]) { if(argc!=2) { printf(./app /dev/videox); return -1; } lcd_init(); //lcd屏初始化 camera_init(argv[1]); //摄像头设备初始化 //开始采集摄像头数据,并实时显示在lcd屏幕上 camera_pthread(); return 0; } ​ ​ ​ //lcd屏初始化 void lcd_init(void) { /*1.打开设备文件*/ int fd=open(/dev/fb0,o_rdwr); if(fd<0) { printf(/dev/fb0设备文件打开失败!); return; } /*2. 读取lcd屏的参数*/ ioctl(fd,fbioget_fscreeninfo,&finfo);//固定参数 printf(映射的长度:%d,finfo.smem_len); ioctl(fd,fbioget_vscreeninfo,&vinfo);//可变参数,32位 printf(分辨率:%d*%d,%d,vinfo.xres,vinfo.yres,vinfo.bits_per_pixel); ​ /*3. 映射lcd的地址到进程空间*/ lcd_mem=mmap(null,finfo.smem_len,prot_write|prot_read,map_shared,fd,0); if(lcd_mem==null) { printf(lcd_mem映射失败!); return; } memset(lcd_mem,0xffffffff,finfo.smem_len); } ​ /*画点*/ void show_pixel(int x,int y,int color) { unsigned long *show32 = null; /* 定位到 lcd 屏上的位置*/ show32 =(unsigned long *)(lcd_mem + y*vinfo.xres*vinfo.bits_per_pixel/8 + x*vinfo.bits_per_pixel/8); *show32 =color; /*向指向的 lcd 地址赋数据*/ } ​ ​ //显示摄像头的数据 void show_videodata(int w,int h,unsigned char *rgb) { int i,j; int x0,x=0,y=0; int color; //颜色 值 unsigned char r,g,b; x0=x; for(i=0;i七、超声波测距驱动代码#include #include #include #include #include #include #include #include #include #include ​ #include #include #include ​ #include ​ static int chaoshengbo_irq=0; ​ #define gpb_con 0x11400040 #define gpb_dat 0x11400044 ​ static u32 *gpb_con=null; static u32 *gpb_dat=null; ​ /* 硬件连接: 输出脚: gpx1_0 ---echo 输入脚: gpb_7 */ static void tiny4412_work_func(struct work_struct *work) { printk(gpb=%d,*gpb_dat&1<<7); ​ ktime_t my_time1,my_time2; unsigned int i,j; unsigned int time_cnt=0; ​ my_time1=ktime_get(); //获取当前时间 i=ktime_to_us(my_time1); //转 us ​ while(gpio_get_value(exynos4_gpx1(0))){} //高电平卡住 ​ my_time2=ktime_get(); //获取当前时间 j=ktime_to_us(my_time2); //转 us ​ printk(us:%d,j-i); } ​ static declare_work(caoshengbotiny4412_work,tiny4412_work_func); ​ /* 中断处理函数 */ irqreturn_t irq_handler_chaoshengbo(int irq, void *dev) { schedule_work(&caoshengbotiny4412_work); /*正常情况下: 是在中断服务函数里面*/ return irq_handled; /*表示中断已经处理过了*/ } ​ static void timer_function(unsigned long data); static define_timer(timer_caoshengbo, timer_function,0,0); ​ static void timer_function(unsigned long data) { static u8 state; state=!state; if(state)*gpb_dat|=1<<7; else *gpb_dat&=~(1<<7); ​ mod_timer(&timer_caoshengbo,jiffies+msecs_to_jiffies(500)); } ​ static int __init tiny4412_chaoshengbo_init(void) { int i,err; /*获取中断号*/ chaoshengbo_irq=gpio_to_irq(exynos4_gpx1(0)); printk(中断号:%d,chaoshengbo_irq); /*外部中断注册*/ err=request_irq(chaoshengbo_irq,irq_handler_chaoshengbo,irq_type_edge_rising,tiny4412_chaoshengbo,null); if(err!=0)printk(中断注册失败!); ​ /*映射内存*/ gpb_con=ioremap(gpb_con,4); gpb_dat=ioremap(gpb_dat,4); ​ /*配置模式*/ *gpb_con&=~(0xf<<4*7); //输出模式 *gpb_con|=0x1<<4*7; mod_timer(&timer_caoshengbo,jiffies+msecs_to_jiffies(100)); return 0; } ​ static void __exit tiny4412_chaoshengbo_exit(void) { free_irq(chaoshengbo_irq,null); iounmap(gpb_con); iounmap(gpb_dat); del_timer(&timer_caoshengbo); } ​ module_init(tiny4412_chaoshengbo_init); /*指定驱动的入口函数*/ module_exit(tiny4412_chaoshengbo_exit); /*指定驱动的出口函数*/ module_license(gpl); /*指定驱动许可证*/ ​ ​

专利之争 LED封装龙头亿光接连获胜
昂科技术软件更新支持烧录Belling16位串行可擦除可编程只读存储器BL24C16A-PA
对于电动汽车电池的耐用性看看特斯拉是怎么做的
【麒麟系统】国产系统与***的强强联合
来看看你的工作被机器人取代的几率高不高?
基于Linux设计的倒车雷达系统
vivo X20 Plus与三星Note9的首款屏下指纹解锁手机争夺战
清华大学RUSH脑成像项目已升级到第二代
推动在智能制造中实现更高水平的灵活性、生产力和可持续性
关于Buck电路纹波控制的方式
固体钽电容和非固体钽电容区别
欧洲航天局正在选择空中客车建造SMILE卫星
电池电量计:以精度制胜
Xilinx Zynq-7000系列:基于ARM Cortex-A9内核处理器和FPGA结构
2023年EDA巨头的收购案件盘点
低功耗液晶电视LED背光源设计
继电器触点符号_继电器触点容量
出差旅行必备的倍思氮化镓充电器,它如何保障说走就走
一文详解限流算法的实现方式
排污水管水质在线监测系统和硬件供应数传平台