资源简介

树莓派小车利用安装在底盘位置的三个红外线传感器来进行循迹行驶

资源截图

代码片段和文件信息

#!/usr/bin/python  
# coding=utf-8  
#本段代码实现树莓派智能小车的循迹效果
import RPi.GPIO as GPIO  
import time  
import sys 
 
T_SensorRight = 26
T_SensorLeft  = 13

PWMA   = 18
AIN1   = 22
AIN2   = 27

PWMB   = 23
BIN1   = 25
BIN2   = 24

BtnPin  = 19
Gpin    = 5
Rpin    = 6
 
def t_up(speedt_time):
        L_Motor.ChangeDutyCycle(speed)
        GPIO.output(AIN2False)#AIN2
        GPIO.output(AIN1True) #AIN1

        R_Motor.ChangeDutyCycle(speed)
        GPIO.output(BIN2False)#BIN2
        GPIO.output(BIN1True) #BIN1
        time.sleep(t_time)
        
def t_stop(t_time):
        L_Motor.ChangeDutyCycle(0)
        GPIO.output(AIN2False)#AIN2
        GPIO.output(AIN1False) #AIN1

        R_Motor.ChangeDutyCycle(0)
        GPIO.output(BIN2False)#BIN2
        GPIO.output(BIN1False) #BIN1
        time.sleep(t_time)
        
def t_down(speedt_time):
        L_Motor.ChangeDutyCycle(speed)
        GPIO.output(AIN2True)#AIN2
        GPIO.output(AIN1False) #AIN1

        R_Motor.ChangeDutyCycle(speed)
        GPIO.output(BIN2True)#BIN2
        GPIO.output(BIN1False) #BIN1
        time.sleep(t_time)

def t_left(speedt_time):
        L_Motor.ChangeDutyCycle(speed)
        GPIO.output(AIN2True)#AIN2
        GPIO.output(AIN1False) #AIN1

        R_Motor.ChangeDutyCycle(speed)
        GPIO.output(BIN2False)#BIN2
        GPIO.output(BIN1True) #BIN1
        time.sleep(t_time)

def t_right(speedt_time):
        L_Motor.ChangeDutyCycle(speed)
        GPIO.output(AIN2False)#AIN2
        GPIO.output(AIN1True) #AIN1

        R_Motor.ChangeDutyCycle(speed)
        GPIO.output(BIN2True)#BIN2
        GPIO.output(BIN1False) #BIN1
        time.sleep(t_time)
        
def keysacn():
    val = GPIO.input(BtnPin)
   

评论

共有 条评论