智能车制作

 找回密码
 注册

扫一扫,访问微社区

查看: 4997|回复: 17
打印 上一主题 下一主题

[控制类] 现金

[复制链接]

0

主题

47

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
389
威望
276
贡献
71
兑换币
34
注册时间
2009-2-11
在线时间
21 小时
跳转到指定楼层
#
发表于 2009-3-31 18:58:22 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
2贡献
请问谁能给我点单片机(9S12)控制的源程序?很感谢!

0

主题

9

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
259
威望
183
贡献
20
兑换币
0
注册时间
2009-3-15
在线时间
28 小时
17#
发表于 2010-1-22 14:20:01 | 只看该作者
沾光同看
回复

使用道具 举报

3

主题

35

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
428
威望
288
贡献
88
兑换币
0
注册时间
2010-1-7
在线时间
26 小时
16#
发表于 2010-1-22 13:41:51 | 只看该作者
弄明白11楼发的程序,也要花很久吧。自己写写小模块,最后再集合,小问题都能明白了,大程序自然写的出来了,同意楼上的说法~~
回复

使用道具 举报

39

主题

593

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1694
威望
989
贡献
401
兑换币
86
注册时间
2008-12-13
在线时间
152 小时
15#
发表于 2010-1-21 13:54:28 | 只看该作者
有空别人的程序,还不如自己想。   这么好的机会锻炼自己的思维,干吗要放弃?
回复

使用道具 举报

49

主题

489

帖子

0

精华

金牌会员

董事长

Rank: 6Rank: 6

积分
2370
威望
754
贡献
1130
兑换币
0
注册时间
2009-10-30
在线时间
243 小时
14#
发表于 2010-1-21 13:02:45 | 只看该作者
厉害!!
回复

使用道具 举报

0

主题

162

帖子

0

精华

高级会员

Rank: 4

积分
537
QQ
威望
351
贡献
160
兑换币
12
注册时间
2009-9-26
在线时间
13 小时
13#
发表于 2010-1-21 10:29:02 | 只看该作者
从那位留代码的哥们学到了一点儿小东西
回复

使用道具 举报

0

主题

162

帖子

0

精华

高级会员

Rank: 4

积分
537
QQ
威望
351
贡献
160
兑换币
12
注册时间
2009-9-26
在线时间
13 小时
12#
发表于 2010-1-21 10:28:31 | 只看该作者
晕,还带这样问的啊
回复

使用道具 举报

0

主题

44

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
255
威望
216
贡献
21
兑换币
0
注册时间
2009-4-7
在线时间
9 小时
11#
发表于 2009-4-16 17:35:52 | 只看该作者
谢谢了,先收藏了。
回复

使用道具 举报

0

主题

242

帖子

0

精华

高级会员

Rank: 4

积分
925
QQ
威望
451
贡献
382
兑换币
0
注册时间
2008-11-28
在线时间
46 小时
10#
发表于 2009-4-16 12:57:52 | 只看该作者
够详细吧,哈哈
回复

使用道具 举报

0

主题

242

帖子

0

精华

高级会员

Rank: 4

积分
925
QQ
威望
451
贡献
382
兑换币
0
注册时间
2008-11-28
在线时间
46 小时
9#
发表于 2009-4-16 12:57:27 | 只看该作者
{
g_DirectionControl = Set_Max_Point - 12;
g_MotorControl = g_DirectionControl;
}
34
//===========================================================
===============
if(Sending_S == 0)
{
/////////////////未处理图像/////////
SCI0SendByte( 0xFE ) ; //场数据传输开始标志
for(i = 0; i < 50; i ++)
{
SCI0SendByte(0xFD); //行数据传输开始标志
for(j = 0;j < 5;j ++)
{
SCI0SendByte(v_point_used_down[i][j]);//
//asm("nop");
SCI0SendByte(v_point_used_up[i][j]) ; //
//SCI0SendByte(v_point_down[i][j]);//
asm("nop");
//SCI0SendByte(v_point_up[i][j]) ; //
}
}
SCI0SendByte(0xFC) ; //数据传输结束标志
///////////////处理后图像/////////////////////////////
for(i = 0; i < 50; i ++)
{
SCI0SendByte(g_SolutedBlackPositionCenter[i]); //处理后中心点
//SCI0SendByte(g_BlackPositionCenter[i]); //中心点
}
SCI0SendByte(0xFF) ; //数据传输结束标志
}
for(i = 0; i < 250; i = i + 1)
{
for(j = 0;j < 5;j ++)
{
v_point_up[i][j] = 0 ; //
v_point_down[i][j] = 0 ;//
}
35
}
//if(v_ValidStartline < 2)
if(Present_OddEven_state == Even) //
{
while (Present_OddEven_state == Even);
EnableInterrupts;
}
else //
{
while (Present_OddEven_state == Odd);
asm("nop"); asm("nop"); asm("nop"); asm("nop");
while (Present_OddEven_state == Even);
EnableInterrupts;
}
Running_Enable = 0;
}
/*******************************************************************
**
Function Name:ServoPIDInit
Description: initialize servo angle PID variable
Inputs: None
Outputs: None
NOTES:
********************************************************************
*/
void ServoPIDInit(void)
{
sPID.loca_Ref = Set_Mid_Point;
sPID.loca_FeedBack = 0;
sPID.loca_PreError = 0;
//sPID.loca_PreIntegral = 0;
sPID.loca_Kp = LOCA_KPVALUE;
sPID.loca_Ki = LOCA_KIVALUE;
sPID.loca_Kd = LOCA_KDVALUE;
sPID.loca_PreU = 0;
}
/*******************************************************************
**
Function Name:SpeedPIDInit
Description: initialize speed PID variable
36
Inputs: None
Outputs: None
NOTES:
********************************************************************
*/
/*******************************************************************
**
Function Name:V_PIDCalc
Description: speed PID calculation function
Inputs: None
Outputs: None
NOTES:
********************************************************************
*/
/*******************************************************************
**
Function NamearameterSelect
Description:
Inputs: None
Outputs: None
NOTES:
********************************************************************
/
void ParameterSelect(void)
{
INT8U l_tmp = 0;
INT16U i = 0;
Led1_ON;
Led2_ON;
Led3_ON;
Led4_ON;
F_WholePulse_SS = 30;
F_WholePulse_S = F_WholePulse_SS;
while(Sending_S == 0)
{
// Led3_OFF;
Led4_OFF;
37
if(Button_1 == 0)
{ //Led3_ON;
ShortDelay();//Delay short time
if(Button_1 == 0)
{
ShortDelay();//Delay short time
if(Button_1 == 0)
{
F_WholePulse_S ++;
F_WholePulse_S ++;
Led1_OFF;
Led2_OFF;
Led3_OFF;
Led4_OFF;
//Clear Display
//LED_PORT &= ~(l_tmp << 2);//Display Number
switch((F_WholePulse_S - F_WholePulse_SS) >> 1)
{
case 0ed1_OFF;Led2_OFF;Led3_OFF;Led4_OFF;
break; // 111
case 1:Led1_ON;Led2_OFF;Led3_OFF;Led4_OFF;
break; // 001
case 2:Led1_OFF;Led2_ON;Led3_OFF;Led4_OFF;
break; // 001
case 3:Led1_ON;Led2_ON;Led3_OFF;Led4_OFF;
break; // 010
case 4:Led1_OFF;Led2_OFF;Led3_ON; Led4_OFF;
break; // 011
case 5:Led1_ON;Led2_OFF;Led3_ON;Led4_OFF;
break; // 100
case 6:Led1_OFF;Led2_ON;Led3_ON;Led4_OFF;
break; // 101
case 7:Led1_ON;Led2_ON;Led3_ON;Led4_OFF;
break; // 110
case
8:Led1_OFF;Led2_OFF;Led3_OFF;Led4_ON;break; // 111
case 9:Led1_ON;Led2_OFF;Led3_OFF;Led4_ON;break;
// 001
case 10:Led1_OFF;Led2_ON;Led3_OFF;Led4_ON;
break; // 001
38
case 11:Led1_ON;Led2_ON;Led3_OFF;Led4_ON;
break; // 010
case 12:Led1_OFF;Led2_OFF;Led3_ON; Led4_ON;
break; // 011
case 13:Led1_ON;Led2_OFF;Led3_ON;Led4_ON;
break; // 100
case 14:Led1_OFF;Led2_ON;Led3_ON;Led4_ON;
break; // 101
case 15:Led1_ON;Led2_ON;Led3_ON;Led4_ON;
break; // 110
default:break;
}
LongDelay();
}
}
}
}
/*Parameters Input*/
while(Button_0 == 1)
{ Led4_ON;
if(Button_1 == 0)
{ //Led3_ON;
ShortDelay();//Delay short time
if(Button_1 == 0)
{
ShortDelay();//Delay short time
if(Button_1 == 0)
{
l_tmp ++;
if(l_tmp > MAX_STRATEGY + 1 )
{
l_tmp = 1;
}
Led1_OFF;
Led2_OFF;
Led3_OFF;
39
Led4_OFF;
//Clear Display
//LED_PORT &= ~(l_tmp << 2);//Display Number
switch(l_tmp)
{
case 1:Led1_OFF;Led2_OFF;Led3_OFF;break; // 001
case 2:Led1_ON;Led2_OFF;Led3_OFF; break; // 001
case 3:Led1_OFF;Led2_ON;Led3_OFF; break; // 010
case 4:Led1_ON;Led2_ON;Led3_OFF; break; // 011
case 5:Led1_OFF;Led2_OFF;Led3_ON; break; // 100
case 6:Led1_ON;Led2_OFF;Led3_ON; break; //
101
case 7:Led1_OFF;Led2_ON;Led3_ON; break; //
110
case 8:Led1_ON;Led2_ON;Led3_ON;break; // 111
default:break;
}
SCI0SendByte(l_tmp);
LongDelay();
}
}
}
}
Led1_OFF;
Led2_OFF;
Led3_OFF;
Led4_OFF;
/*Parameters Select*/
/*******************************************************************
***
Function Name:ShortDelay
Description:
Inputs: None
Outputs: None
NOTES:
********************************************************************
*/
void LongDelay(void)
40
{
INT8U j = 0;
INT16U i = 0;
for(j = 0;j < 0x20;j++)
{
for(i = 0;i <0xffff;i++);//Delay long time
}
}
void ShortDelay(void)
{
INT16U i = 0;
for(i = 0;i <50000;i++);//Delay short time
}
/*SCHEDULE_C END*/
回复

使用道具 举报

0

主题

242

帖子

0

精华

高级会员

Rank: 4

积分
925
QQ
威望
451
贡献
382
兑换币
0
注册时间
2008-11-28
在线时间
46 小时
8#
发表于 2009-4-16 12:57:21 | 只看该作者
v_point_used_down[n][i + 1]; //记录黑线宽度
if(cnt == 0) //
{
g_BlackPositionCenter[n] = g_BlackPoint[0][cnt]; //该行
黑线中心点重新赋值
g_width[n] = g_BlackPoint[1][cnt];
}
else // (1<n<=4)
{
if(g_BlackPoint[0][cnt] >= v_LastLineCenter) //
{
g_BlackPositionCenter[n] = g_BlackPoint[0][cnt]; //
该行黑线中心点重新赋值
27
g_width[n] = g_BlackPoint[1][cnt];
}
else if(g_BlackPositionCenter[n] - v_LastLineCenter >
v_LastLineCenter - g_BlackPoint[0][cnt])
{ //
g_BlackPositionCenter[n] = g_BlackPoint[0][cnt];//该
行黑线中心点重新赋值
g_width[n] = g_BlackPoint[1][cnt];
}
}
cnt ++;
// i = 4;//
}
}
if(cnt > 0)
{
v_LastLineCenter = g_BlackPositionCenter[n];
}
if((k - n) > 20)
{
g_BlackPositionCenter[n] = 250;
g_width[n] = 0;
n = -1;
}
}
}
v_slope_valid_line = 0;
v_slope_sum = 0;
v_slope_average = 0;
v_straight_valid_line = 0;
F_SlopAverageOne = 0;
F_SlopAverageTwo = 0;
F_StraightTwo = 0;
F_SlopAverageOne = 0;
v_straight_valid = 0;
v_ValidLine = 0;
28
v_TotleValidLine = 0;
v_straight_line_lost = 0;
v_slopeTwoSum = 0;
v_LastslopeOneAverage = v_slopeOneAverage;
v_slopeOneAverage = 0;
for(i = 49; i >= 0; i --)
{
g_SolutedBlackPositionCenter[i] = g_BlackPositionCenter[i];
}
for(i = 45; i > 3; i --)
{
v_slope_2[i] = 0;
if((g_BlackPositionCenter[i] != 250) && (g_BlackPositionCenter[i - 4] !=
250) && (g_BlackPositionCenter[i + 4] != 250))
{
v_TotleValidLine ++;
v_ValidLine ++;
v_slope_last = g_BlackPositionCenter[i - 4] -
g_BlackPositionCenter[i];//
v_slope_now = g_BlackPositionCenter[i] - g_BlackPositionCenter[i +
4];
v_slope_2[i] = v_slope_now - v_slope_last; //二次斜率
v_slopeOneAverage += v_slope_last;
v_slopeTwoSum += v_slope_2[i];
if(F_StraightTwo == 0)
{
if((v_slope_now - v_slope_last < 4) && (v_slope_now -
v_slope_last > -4))//直道
{
v_straight_valid_line ++;
v_slope_sum += v_slope_last;
}
}
else if(F_StraightTwo == 1)
{
if((v_slope_now - v_slope_last < 2) && (v_slope_now -
v_slope_last > -2))//直道
29
{
v_straight_valid_line ++;
v_slope_sum += v_slope_last;
}
if((v_ValidLine > 5) && (v_straight_valid_line >= 3))
{
// Led3_ON;
F_SlopAverageTwo = v_slope_sum / v_straight_valid_line ;
F_StraightTwo = 2;
i = 0;
}
}
}
else
{
if(F_StraightTwo == 0)
{
//if(((v_straight_valid_line > 2) && ((v_ValidLine >= 4)) &&
(v_TotleValidLine < 12)) ||((v_straight_valid_line > 4) && ((v_ValidLine > 6))) )
if(((v_TotleValidLine < 10)) ||((v_straight_valid_line > 4) &&
(v_ValidLine > 7) && (v_TotleValidLine < 30)) )
{
//Led2_ON;
v_straight_line_lost = i;
v_straight_valid = 1;
F_StraightTwo = 1;
F_SlopAverageOne = v_slope_sum / v_straight_valid_line ;
}
}
// SCI0SendByte(0xBB);
//SCI0SendByte(v_straight_valid_line);
//SCI0SendByte(v_ValidLine);
v_ValidLine = 0;
v_straight_valid_line = 0;
v_slope_sum = 0;
v_ValidLine = 0;
30
}
}
if(v_slopeTwoSum < 0) v_slopeTwoSum = 0 - v_slopeTwoSum;
v_slopeOneAverage = v_slopeOneAverage / v_TotleValidLine;
//==================================================
========================================
//SCI0SendByte(0xaa);
//SCI0SendByte(0xaa);
///SCI0SendByte(v_slope_sum + 128);
//SCI0SendByte(F_SlopAverageTwo + 128);
//SCI0SendByte(v_straight_line_lost);
/*
if(((F_SlopAverageTwo > 4) && (F_SlopAverageOne < -1) &&
(F_SlopAverageTwo - F_SlopAverageOne > 10)) || ((F_SlopAverageTwo < -4)
&&( F_SlopAverageOne > 1)&& (F_SlopAverageTwo - F_SlopAverageOne <
-10)))
{
//Led4_ON;
for(i = 0;i < v_straight_line_lost;i++)
{
g_BlackPositionCenter[i] = 250;
}
}
*/
for(i = 0;i < 46;i++)
{
if(g_SolutedBlackPositionCenter[i] != 250)
{
if(v_slope_2[i] > 10)
{
v_slope_2[i] = 10 ;
}
else if(v_slope_2[i] < -10)
{
v_slope_2[i] = -10 ;
}
g_SolutedBlackPositionCenter[i] -= v_slope_2[i] * 2;
31
}
if(g_SolutedBlackPositionCenter[i] < 10)
{
g_SolutedBlackPositionCenter[i] = 10;
}
else if(g_SolutedBlackPositionCenter[i] > 206)
{
g_SolutedBlackPositionCenter[i] = 206;
}
}
//===========================================================
===================
m = g_FormerValidLine; //用变量m 将上一场的有效行数存起来
g_FormerValidLine = g_ValidLine;
g_ValidLine = 0;
g_MotorValidLine = 0;
k = g_DirectionControl;//用变量k 将上一场的加权中心值存起来
k2 = g_BottomMiddle;//用变量k2 将上一场的后20 行中心值存起来
g_BlackLineTotal = 0;
g_DirectionControlLine = 0;
g_MotorControlLine = 0;
//g_FrontValidLine = 0;
for(n = (MAX_VIDEO_USEDLINE - 1); n >= 0; n --)
{
if(g_BlackPositionCenter[n] != 250)
{
if(0 == g_ValidLine)
{
g_DirectionControl = 0;
}
g_ValidLine ++;
g_BlackLineTotal += g_BlackPositionCenter[n];
//============加权平均===================
g_center = g_SolutedBlackPositionCenter[n];
//g_center = g_BlackPositionCenter[n];
32
g_DirectionControlLine += g_coeff[n];
g_DirectionControl += g_coeff[n] * g_center;
}
//======= ========
if(n == 30)
{
if(g_ValidLine >= 10)
{
g_BottomMiddle = g_BlackLineTotal / g_ValidLine;
}
}
}
////////////////////////////////////////////////////////////////
// Led2_OFF;
//Led3_OFF;
// Led4_OFF;
for(n = 1; n < 50; n ++)
{
if(g_BlackPositionCenter[n] != 250)
{
if(0 == g_MotorValidLine)
{
g_MotorControl = 0;
}
g_MotorValidLine ++;
if(g_MotorValidLine < 20)
{
g_MotorControlLine += g_coeff[n];
g_MotorControl += g_coeff[n] * g_BlackPositionCenter[n] ;
}
}
}
if(g_ValidLine == 0)
{
if(k < Set_Mid_Point - 40) //判断上一有效场黑线中心靠左还是靠右
{
33
g_DirectionControl = Set_Min_Point ;
g_BottomMiddle = Set_Min_Point + 30;
g_MotorControl = g_DirectionControl;
}
else if(k >= Set_Mid_Point + 40)
{
g_DirectionControl = Set_Max_Point;
g_BottomMiddle = Set_Max_Point - 30;
g_MotorControl = g_DirectionControl;
}
else
{
g_DirectionControl = k;
g_BottomMiddle = k2;
g_MotorControl = g_DirectionControl;
}
}
else if(((m > 40) || (g_FormerValidLine > 40)) && (g_ValidLine < 5))
{
g_DirectionControl = k;
g_BottomMiddle = k2;
g_MotorControl = g_DirectionControl;
}
else
{
g_DirectionControl /= g_DirectionControlLine;
g_MotorControl /= g_MotorControlLine;
}
if(g_DirectionControl < Set_Min_Point + 12)
{
g_DirectionControl = Set_Min_Point + 12;
g_MotorControl = g_DirectionControl;
}
else if(g_DirectionControl > Set_Max_Point - 12)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关于我们|联系我们|小黑屋|智能车制作 ( 黑ICP备2022002344号

GMT+8, 2024-9-20 09:08 , Processed in 0.049721 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表