標(biāo)題:
stm32控制機(jī)械臂的智能小車源程序
[打印本頁(yè)]
作者:
lihongquan123
時(shí)間:
2021-4-16 21:37
標(biāo)題:
stm32控制機(jī)械臂的智能小車源程序
stm32機(jī)械臂智能小車,已經(jīng)很成熟,歡迎下載
制作出來(lái)的實(shí)物圖如下:
IMG20210405201430.jpg
(4.85 MB, 下載次數(shù): 61)
下載附件
2021-4-16 21:36 上傳
單片機(jī)源程序如下:
#include "stm32f10x.h"
#include "usart1.h"
#include "car_config.h"
#include "pwm_output.h"
#include "bsp_SysTick.h"
#include "timers.h"
#include "bizhang.h"
#include "delay.h"
//#include "LED.h"
#include "ultrasonic.h"
//#include "sys.h"
#include "stm32f10x_gpio.h"
/*
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
#define GPIOB_ODR_Addr (GPIOB_BASE+12) //0x40010C0C
#define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //輸出
#define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //輸入
*/
extern u8 receByte;
//一次獲取超聲波測(cè)距數(shù)據(jù),兩次測(cè)距之間需要間隔一段時(shí)間,阻斷回響信號(hào)
//為了消除余震的影響,取五次數(shù)據(jù)的平均值進(jìn)行加權(quán)濾波
uint32_t Hcsr04GetLength(void )
{
int i = 0;
u32 sum = 0;
u32 lengthTemp = 0;
while(i != 5)
{
delay_us(20);
i = i+1;
lengthTemp = get_distance();
sum = lengthTemp + sum ;
}
lengthTemp = sum/5.0;
return lengthTemp;
}
//#define LED PBout(10)
#define LEDPORT GPIOB
#define LED1 GPIO_Pin_10 //定義LED1
void ESP8266_Init()
{
printf("AT\r\n");
delay_ms(300);
printf("AT+CWMODE=3\r\n");
delay_ms(300);
printf("AT+CIPMUX=1\r\n");
delay_ms(300);
printf("AT+CIPSERVER=1,8080\r\n");
delay_ms(300);
}
//初始化LED
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;//構(gòu)造結(jié)構(gòu)體
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);//使能其所在時(shí)鐘
GPIO_InitStructure.GPIO_Pin = LED1;//定義IO端口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//定義IO端口輸出模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//定義IO端口輸出速度
GPIO_Init(LEDPORT, &GPIO_InitStructure);//寫(xiě)入其中
}
int main(void)
{
u16 sudu = 0;
u8 aflag = 0;
u8 aflag_1 = 0;
u32 a=5; //延時(shí)參數(shù)
u32 distance;
sudu = 250;//
SysTick_Init(); /* 配置SysTick 為1us中斷一次 */
Car_GPIO_Config();
USARTx_Config(); //USART1 config 9600 8-N-1
NVIC_Configuration();
Timer2Init();
TIM3_PWM_Init();
Speed_config(sudu);
// ESP8266_Init();
ultrasonic_init(); //初始化超聲波測(cè)距模塊
delay_init(); //初始化系統(tǒng)延時(shí)
for(a=5;a>0;a--)
{
delay_ms(500);
}
LED_Init();
//distance = Hcsr04GetLength();
//printf("i love you");
ESP8266_Init();
GPIO_WriteBit(LEDPORT,LED1,(BitAction)(0));
delay_ms(200);
GPIO_WriteBit(LEDPORT,LED1,(BitAction)(1));
//GPIO_SetBits(LEDPORT,LED1);
while(1){
if(aflag==0){
distance = Hcsr04GetLength();
if(distance < 150)
{
hout();
// baojing_1();
//LED1=0;
GPIO_WriteBit(LEDPORT,LED1,(BitAction)(0));
delay_ms(200);
//LED1=1;
//distance = Hcsr04GetLength(); //測(cè)量當(dāng)前距離
//printf("DISTANCE_av: %d mm\r\n", distance); // 藍(lán)牙串口打印當(dāng)前距離
}else{
GPIO_WriteBit(LEDPORT,LED1,(BitAction)(1));
}
if(receByte==0x30){
tingz();
printf("i love you");
receByte = 0x40;
}else if(receByte==0x31){
qianj();
receByte = 0x40;
}else if(receByte==0x32){
hout();
receByte = 0x40;
}else if(receByte==0x33){
zuoz();
receByte = 0x40;
}else if(receByte==0x34){
youz();
receByte = 0x40;
}
else if(receByte==0x35){
sudu = sudu+100;
if(sudu>=800){
sudu = 0;
}
Speed_config(sudu);
receByte = 0x40;
}else if(receByte==0x36){
if(sudu>100){
sudu = sudu-100;
} else if(sudu<=100){
sudu = 0;
}
Speed_config(sudu);
receByte = 0x40;
}
}else{
distance = Hcsr04GetLength();
if(aflag_1==0){
if(distance > 200)
{
qianj();
//aflag_1=1;
//distance = Hcsr04GetLength(); //測(cè)量當(dāng)前距離
//printf("DISTANCE_av: %d mm\r\n", distance); // 藍(lán)牙串口打印當(dāng)前距離
}else {
aflag_1=1;
youz_1();
delay_ms(700);
//delay_ms(400);
//delay_ms(300);
tingz();
delay_ms(900);
youz_1();
delay_ms(1000);
//delay_ms(150);
delay_ms(100);
// delay_ms(300);
tingz();
delay_ms(900);
delay_ms(600);
qianj();
}
} else{
if(distance > 200)
{
qianj();
//aflag_1=1;
//distance = Hcsr04GetLength(); //測(cè)量當(dāng)前距離
//printf("DISTANCE_av: %d mm\r\n", distance); // 藍(lán)牙串口打印當(dāng)前距離
}else {
aflag_1=0;
zuoz_1();
delay_ms(1000);
// delay_ms(300);
delay_ms(200);
//delay_ms(1000);
tingz();
delay_ms(1000);
delay_ms(100);
zuoz_1();
//delay_ms(1000);
delay_ms(800);
delay_ms(200);
//delay_ms(300);
tingz();
delay_ms(500);
delay_ms(1000);
qianj();
}
}
/*
sudu = 280;
Speed_config(sudu);
if((BiZhang_State(GPIOB,GPIO_Pin_0) == 0)&&(BiZhang_State(GPIOB,GPIO_Pin_1) == 0)){
qianj();
}else if((BiZhang_State(GPIOB,GPIO_Pin_0) == 1)&&(BiZhang_State(GPIOB,GPIO_Pin_1) == 1)){
tingz();
}else if((BiZhang_State(GPIOB,GPIO_Pin_0) == 1)&&(BiZhang_State(GPIOB,GPIO_Pin_1) == 0)){
zuoz();
}else if((BiZhang_State(GPIOB,GPIO_Pin_0) == 0)&&(BiZhang_State(GPIOB,GPIO_Pin_1) == 1)){
youz();
}
*/
}
if(receByte==0x37){
aflag = 1;
}
if(receByte==0x38){
aflag = 0;
}
}
}
復(fù)制代碼
所有資料51hei提供下載:
STM32程序_test.7z
(185.38 KB, 下載次數(shù): 34)
2021-4-17 00:37 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
hua767
時(shí)間:
2021-4-17 08:25
機(jī)械臂在哪里呢?沒(méi)有看到
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1