📄 func.c
字号:
/*****************************************************************************/
//func.c
// 定义有关各迷宫小车图像处理函数
// 处理针对YUV图象的UV进行
// 注意所有的都是先列后行!
// X对应列,对应宽度,Y对应行,对应高度
/*****************************************************************************/
#include "math.h"
#include "stdlib.h"
#include "mydefines.h"
#include "func.h"
#include "list.c"
#include "stdio.h"
#include "CPLD.h"
#include "node.h"
//=========================================================================================================
//系统状态标记
extern volatile unsigned int SystemState; //系统状态标记
//=========================================================================================================
//=======================================================================================================
//图像处理缓存
extern volatile unsigned char ImaProBuffer[LCDLine][LCDWidth];
extern volatile unsigned char BImageBuffer[LCDLine][LCDMemoryWidth];
extern volatile unsigned char YUVClass[3][256];//颜色查找表;用内存换取速度
extern volatile unsigned char YUVClassY;
extern volatile unsigned char YUVClassU;
extern volatile unsigned char YUVClassV;//定义点的UV值
//=======================================================================================================
extern volatile unsigned char maze[MazeHeight40][MazeWidth40];//迷宫地图(路=0,墙=1,小车=2,3,4,目标=8,其他保留)
//目标位置定义
extern volatile int Goal_X;
extern volatile int Goal_Y;
extern int BReachGoal;
extern volatile int CarPosition[2];//小车当前位置
extern volatile int Road[300][3];//决策系统决策得到的路径
extern volatile int PixelIsObject;//是否是目标的标记
extern volatile int LoseCar;
extern volatile int LoseGoal;//丢掉目标点定义
extern volatile int MainTag[2];//主色标坐标
extern volatile int MainTagR;//主色标半径,以点数计
extern volatile int SubTag[2];//副色标坐标
extern volatile int SubTagR;//主色标半径,以点数计
extern volatile int FoundWayFlag; //是否找到路径标记
extern volatile int HaveFoundFlag; //是否找过路径标记
extern volatile int ArtificialWalkFlag;
extern volatile int dg_n;//定义重新计算子节点的费用值的变化量
extern volatile struct node * open_list;//定义open表
extern volatile struct node * closed_list;//定义closed表
//extern volatile struct node * best_node;//定义closed表
extern volatile int Astep;
/*****************************************************************************/
//函数名称:(unsigned char *pImage,int nWidthX, int nHeightY);//
//功能:得到像素点YUV空间值
//参数:
// unsigned char *pImage 图像数据指针
// int nWidthX, int nHeightY 图象宽度、高度
//返回值:无
/*****************************************************************************/
inline uint16_t GetPixelColoYUV(volatile unsigned char Image[][LCDWidth],int nWidthX, int nHeightY,int nowPointX,int nowPointY )
{
/* YUVClassY=Image[nowPointY][nowPointX];
YUVClassU=Image[nowPointY][nowPointX+1];
YUVClassV=Image[nowPointY][nowPointX+2];
*/
return TRUE;
}
//////////////////////////////////////////////////////////////////////
// list.c
// 各链表相关函数包括,创建,删除,插入,查找以及重新计算费用值等基本操作
// 关联list.h
//////////////////////////////////////////////////////////////////////
//=======================================================================
// 函数名称: create_node()
// 功能 : 构造函数,创建双向链表的一个结点,并赋值当前结点为空;
// 参数 :
// int row_1,int collum_1,节点所处的行数列数;
// int f_n_1, 节点的初始费用值,一般设为1;
// 返回值 :
// 说明 : int类型的数据,由于表头结点中的数据不会被使用;
// 因此该数据可以为任何不在后继结点中使用的数据即可;
//========================================================================
volatile struct node * create_node(int row_1,int collum_1,int f_n_1)
{
volatile struct node * pnode = NULL;
if ((pnode =(volatile struct node * )malloc(sizeof(volatile struct node)))==NULL)
{//不能分配空间
//可以在此扩展不能分配空间的处理函数
return NULL;
} ;
pnode->row = row_1;
pnode->collum = collum_1;
pnode->f_n = f_n_1;
pnode->g_n = 0;
pnode->h_n = 0;
pnode->father=NULL;
pnode->son1=NULL;
pnode->son2=NULL;
pnode->son3=NULL;
pnode->son4=NULL;
pnode->prior = pnode->next = pnode; //创建新结点时,让其前向和后向指针都指向自身
//return pnode;
return pnode;
}
//=======================================================================
// 函数名称: create_list(int head1,int head2,int head3)
// 功能 : 创建一个双向链表,其实就是创建创建链表的头指针;
// 参数 :
// int head1,int head2,int head3:表头的数据,任意付为用不到的数据;
// 返回值 : 成功,返回1,失败返回0;
// 说明 : int类型的数据,由于表头结点中的数据不会被使用;
// 因此该数据可以为任何不在后继结点中使用的数据即可;
//========================================================================
int create_list(int head1,int head2,int head3)//参数给出表头结点数据 (表头结点不作为存放有意义数据的结点)
{
/* volatile struct node * pnode1;
if ((pnode1 =(volatile struct node * )malloc(sizeof(struct node)))==NULL)
{//不能分配空间
//可以在此扩展不能分配空间的处理函数
} ;
//成功分配空间后,为表头付值
pnode1->row = head1;
pnode1->collum = head2;
pnode1->f_n = head3;
pnode1->g_n = 0;
pnode1->h_n = 0;
pnode1->father=NULL;
pnode1->son1=NULL;
pnode1->son2=NULL;
pnode1->son3=NULL;
pnode1->son4=NULL;
pnode1->prior = pnode1->next = pnode1;
*/
return (TRUE);//成功返回1
}
//=======================================================================
// 函数名称: insert_node(volatile struct node node_temp, int data1,int data2,int data3)
// 功能 : 插入新结点;
// 参数 :
// volatile struct node node_temp:链表的表头结点;
// int data1,int data2,int data3:要插入的结点(结点数据为data);
// 返回值 : 表头结点地址 ;
// 说明 : 总是在表尾插入;
//========================================================================
volatile struct node * insert_node(volatile struct node * node_temp, int data1,int data2,int data3) // 参数1是链表的表头结点,参数2是要插入的结点(结点数据为data)
{
volatile struct node * pnode;
if ((pnode =(volatile struct node * )malloc(sizeof(volatile struct node)))==NULL)
{//不能分配空间
//可以在此扩展不能分配空间的处理函数
} ;
pnode->row = data1;
pnode->collum = data2;
pnode->f_n = data3;
pnode->g_n = 0;
pnode->h_n = 0;
pnode->father=NULL;
pnode->son1=NULL;
pnode->son2=NULL;
pnode->son3=NULL;
pnode->son4=NULL;
pnode->prior = pnode->next = pnode; //创建新结点时,让其前向和后向指针都指向自身
volatile struct node * temp = node_temp->prior;
// 从左到右恢复链接
node_temp->prior->next = pnode;
pnode->next = node_temp;
// 从右到左恢复链接
node_temp->prior = pnode;
pnode->prior = temp;
return node_temp;
}
//=======================================================================
// 函数名称: insert_node2(volatile struct node node_temp, int data1,int data2,int data3)
// 功能 : 插入新结点;
// 参数 :
// volatile struct node node_temp:链表的表头结点;
// int data1,int data2,int data3:要插入的结点(结点数据为data);
// 返回值 : 表头结点地址 ;
// 说明 : 总是在表尾插入;
//========================================================================
volatile struct node * insert_node2(volatile struct node * list_head2,volatile struct node * node_temp) // 参数1是链表的表头结点,参数2是要插入的结点(结点数据为data)
{
volatile struct node * temp = list_head2->prior;
if(node_temp==NULL||list_head2==NULL)
{//
//错误的插入空节点或表为空
}
// 从左到右恢复链接
list_head2->prior->next = node_temp;
node_temp->next =list_head2;
// 从右到左恢复链接
list_head2->prior = node_temp;
node_temp->prior = temp;
return list_head2;
}
//=======================================================================
// 函数名称: find_closed(volatile struct node node_temp, int target1,int target2)
// 功能 : 查找结点;
// 参数 :
// volatile struct node node_temp:链表的表头结点;
// int target1,int target2:要查找的结点(结点数据为int target1,int target2);
// 返回值 : 成功则返回满足条件的结点指针,否则返回NULL;
// 说明 : 无
//========================================================================
volatile struct node *find_closed(volatile struct node * node_temp, int target1,int target2) // 参数1是链表的表头结点,参数2是要查找的结点(其中结点数据为target)
{
volatile struct node * pnode = node_temp->next;
while (pnode->next != node_temp && (!(pnode->row== target1&& pnode->collum==target2)))
{
pnode = pnode->next;
}
if (pnode->next == node_temp&& (!(pnode->row== target1&& pnode->collum==target2)))
{
return NULL;
}
return pnode;
}
//===============================================================================
// 函数名称 : del_node2(volatile struct node list_head1,volatile struct node node_current)
// 功能 : 删除当前结点;
// 参数 : volatile struct node list_head1,第一个是表头地址;
// volatile struct node node_current,第二个是要删的节点的地址;
// 返回值 : 成功,返回1,失败返回0;
// 说明 : 无
//================================================================================
int del_node2(volatile struct node * list_head1,volatile struct node * node_current)
{
volatile struct node * ptmp;
if (NULL == node_current)
{
//"删除节点出现错误。:-( \n");
return 0;
}
if (NULL == list_head1)
{
//删除节点出现错误。:您企图从空表中删除元素 :-( \n");
return 0;
}
if (node_current == list_head1) // 若删除的是第一个节点,
{ // 则删后表会空或者表空时还要删,这是不符合逻辑的
//你弄错了.\n");
//你正在企图删除表头,请重新确定您的意图。:-(\n");
return 0;
}
ptmp = node_current->prior;
ptmp->next = node_current->next;
ptmp->next->prior = ptmp;
//free((void *)node_current);
return 1;
}
//===============================================================================
// 函数名称 : IsMyListEmpty(volatile struct node link_temp)
// 功能 : 该函数判断双向链表是否为空;
// 参数 : volatile struct node link_temp,链表首地址 ;
// 返回值 : 若链表为空则返回1,否则返回0;
// 说明 : 无
//================================================================================
int IsMyListEmpty(volatile struct node * link_temp)
{
if(link_temp->next==link_temp)
{
return 1;
}
return 0;
}
//============================================================================
// 函数名称 : find_fn(volatile struct node node_temp)
// 功能 : 从链表开始位置寻找结点数据等于fn的结点;
// 参数 : volatile struct node node_temp,链表的表头结点;
// 返回值 : 链表的表头结点;
// 说明 : 无
//============================================================================
volatile struct node * find_fn(volatile struct node * node_temp) // 参数1是链表的表头结点
{
int findout=0;
volatile struct node * pnode = node_temp->next;
volatile struct node * min_fn = node_temp->next;
while (pnode->next != node_temp )
{
if(pnode->f_n<=min_fn->f_n) /* 谁小谁标记为min_fn */
{
min_fn=pnode;
}
pnode = pnode->next;
findout++;
if(findout>10000)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -