示例#1
0
    def __init__(self,
                 motor_left_pin1=17,
                 motor_left_pin2=27,
                 motor_right_pin1=23,
                 motor_right_pin2=24,
                 line_follow_pin_left=19,
                 line_follow_pin_right=6,
                 servo_pin=22,
                 us_trigger_pin=12,
                 us_echo_pin=13):
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)

        # init modules
        self.ultrasonic = US(servo_pin, us_trigger_pin, us_echo_pin)
        self.motor = L293D(motor_left_pin1, motor_left_pin2, motor_right_pin1,
                           motor_right_pin2)
        self.line_follow_pin_left = line_follow_pin_left
        self.line_follow_pin_right = line_follow_pin_right

        GPIO.setup(self.line_follow_pin_left, GPIO.IN)
        GPIO.setup(self.line_follow_pin_right, GPIO.IN)
示例#2
0
import RPi.GPIO as GPIO
import time
from l293d import L293D

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

print("robot will run...\n")

l = L293D(17, 27, 23, 24)
l.stop()

for i in range(20):
    l.forward()
    time.sleep(0.5)
    l.forwardRight()
    time.sleep(0.5)
l.stop()
示例#3
0
import RPi.GPIO as GPIO
from l293d import L293D
from time import sleep

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

print("Keskeytä Ctrl+C")
#Microbit kytketaan raspberryn GPIO4:seen eli fysikaalinen pinni 7
ohjain_eteenpain = Button(4, pull_up=False)
#Microbit kytketaan raspberryn GPIO5:seen eli fysikaalinen pinni 8
ohjain_oikealle = Button(5, pull_up=False)
#Microbit kytketaan raspberryn GPIO6:seen eli fysikaalinen pinni 9
ohjain_vasemmalle = Button(6, pull_up=False)

motor = L293D(17, 27, 23, 24)
motor.stop()

try:
    while True:
        if ohjain_eteenpain.is_pressed:
            motor.forward()
        if ohjain_oikealle.is_pressed:
            motor.forwardRight()
        if ohjain_vasemmalle.is_pressed:
            motor.forwardLeft()
        sleep(0.5)
except KeyboardInterrupt:
    print("Lopetetaan ohjelma")
finally:
    motor.stop()
示例#4
0
import RPi.GPIO as io
from l293d import L293D

pwm_fw = 50
brakeInterval = -5

motor = L293D()

io.output(motor.EN12, 0)
io.output(motor.EN34, 0)

pwm12 = io.PWM(motor.EN12, 1000)  # frequency =1000
pwm34 = io.PWM(motor.EN34, 1000)  # frequency =1000

pwm12.start(100)
pwm34.start(100)

motor.move_fw()

from time import sleep

sleep(1)


def brake():
    print("BRAKE!!!...")
    for dc in range(pwm_fw, 0, brakeInterval):
        pwm34.ChangeDutyCycle(dc)
        pwm12.ChangeDutyCycle(dc)
        sleep(.25)
示例#5
0
import RPi.GPIO as GPIO
import time
from l293d import L293D
 
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
 
l = L293D(23,24,17,27)

l.stop()
 
for i in range(1):
  l.forward()
  time.sleep(0.5)
  l.forwardRight()
  time.sleep(0.5)
l.stop()