admin
聪明的教授 Lv153    
课程作者
程序2
已学习:1579   提交:0   发表于2022-01-05 17:14:22
下载编号:94612

##机器人转圈圈## 这个C语言小程序能够控制机器人转圈圈哦,代码很简单,就是几个个左转控制而已。

#define left1on GPIO_SetBits(GPIOD,GPIO_Pin_6)
#define left1off GPIO_ResetBits(GPIOD,GPIO_Pin_6)
#define left2on GPIO_SetBits(GPIOG,GPIO_Pin_9)
#define left2off GPIO_ResetBits(GPIOG,GPIO_Pin_9)
#define right1on GPIO_SetBits(GPIOC,GPIO_Pin_11)
#define right1off GPIO_ResetBits(GPIOC,GPIO_Pin_11)
#define right2on GPIO_SetBits(GPIOD,GPIO_Pin_0)
#define right2off GPIO_ResetBits(GPIOD,GPIO_Pin_0)
extern volatile u32 time;
u8 start=0;
u16 time1,time2;
volatile u8 motor0_angel=90,motor1_angel=90,motor2_angel=90,motor3_angel=90,motor4_angel=90,motor5_angel=90;
void TIM2_IRQHandler(void)
{
if ( TIM_GetITStatus(TIM2 , TIM_IT_Update) != RESET )
{
TIM_ClearITPendingBit(TIM2 , TIM_FLAG_Update);
time1++;
time2++;
if(time1==50)
{
time1=0;
time++;
if(time>9)
time=0;
if(ina1>time)
left1on;
else
left1off;
if(ina2>time)
left2on;
else
left2off;
if(inb1>time)
right1on;
else
right1off;
if(inb2>time)
right2on;
else
right2off;
}
if(time2>1818)
time2=0;
if(time2 motor0on;
else
motor0off;
if(time2 motor1on;
else
motor1off;
if(time2 motor2on;
else
motor2off;
if(time2 motor3on;
else
motor3off;
if(time2 motor4on;
else
motor4off;
if(time2 motor5on;
else
motor5off;
}
}

void USART3_IRQHandler(void)
{
unsigned char rec_data;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART3, USART_IT_RXNE);
/* Read one byte from the receive data register */
rec_data = USART_ReceiveData(USART3);
if(start!=0&&rec_data!=0xff) //??????????????????
{
buf[start-1]=rec_data; //????
start++;
}
else if(start!=0&&rec_data==0xff) //??????
{
mode[0]=buf[0]; //?????????
mode[1]=buf[1];
mode[2]=buf[2];
start=0;
mode1=1; //???????????
}
else if(rec_data==0xff&&start==0) //????????
start++;
}
}

void dianji(u8 i)
{
switch(i)
{
case 1: //??
speed_right=4;
speed_left=4;
break;

case 2: //??
speed_right=-4;
speed_left=-4;
break;
case 3: //??
speed_right=-2;
speed_left=4;
break;
case 4: //??
speed_right=4;
speed_left=-2;
break;
case 0: //??
speed_right=0;
speed_left=0;
break;
case 5: //??
speed_right=2;
speed_left=5;
break;
case 6: //??
speed_right=5;
speed_left=1;
break;
case 7: //??
speed_right=-2;
speed_left=-5;
break;
case 8: //??
speed_right=-5;
speed_left=-2;
break;
}
}

结语:上面这个小程序是不是很有趣嘞?还有更多的小程序供你探索哦!

优唯思教育机器人,你所有的问题在我这儿都能得到解决! 
学习列表
默认   热门   正序   倒序
暂无班级信息
等级:0级
优币:
好奇少年:
最新作业
左邻右舍
{"竞赛编程":"http://www.uwis.cn/uide/","课程编辑":"http://www.135editor.com/","成信大":"http://www.cuit.edu.cn","老版优唯思":"http://old.uwis.cn","图文发帖":"http://yz.uwis.cn/index.php?c=edit&type=read&pyteditorload=no"}

©2015 - 2024 优唯思编程   |   Copyright 2015 All Rights 成都优威骐骥教育科技有限公司  |  网站备案号:蜀ICP备16015136号

已有0次打赏
PID
MIC