from PiMotor import Sensor import time go = "true" while go == "true": us = Sensor("ULTRASONIC", 15) us.trigger() if us.Triggered: print("Bremsen")
import PiMotor from PiMotor import Sensor import time m1 = PiMotor.Motor("MOTOR1", 1) m2 = PiMotor.Motor("MOTOR2", 1) m3 = PiMotor.Motor("MOTOR3", 1) m4 = PiMotor.Motor("MOTOR4", 1) #Names for Individual Arrows ab = PiMotor.Arrow(1) al = PiMotor.Arrow(2) af = PiMotor.Arrow(3) ar = PiMotor.Arrow(4) us = Sensor("ULTRASONIC", 120) irFront = Sensor("IR1", 1) irBack = Sensor("IR2", 1) irLeft = Sensor("IR3", 1) irRight = Sensor("IR4", 1) #To drive all motors together motorAll = PiMotor.LinkedMotors(m1, m2, m3, m4) rightMotors = PiMotor.LinkedMotors(m1, m2) leftMotors = PiMotor.LinkedMotors(m3, m4) def trigIR(): irFront.trigger() irBack.trigger() if irFront.Triggered:
import PiMotor from PiMotor import Sensor import time m1 = PiMotor.Motor("MOTOR1",1) m2 = PiMotor.Motor("MOTOR2",1) m3 = PiMotor.Motor("MOTOR3",1) m4 = PiMotor.Motor("MOTOR4",1) us=Sensor("ULTRASONIC",60) ir1=Sensor("IR2",10) ir2=Sensor("IR1",10) #To drive all motors together motorAll = PiMotor.LinkedMotors(m1,m2,m3,m4) x=0 def trigIR(): ir1.trigger() ir2.trigger() if ir1.Triggered: motorAll.reverse(100) time.sleep(0.7) motorAll.stop() print("Front Line Detected") if ir2.Triggered: motorAll.forward(100) time.sleep(0.7) motorAll.stop()
import PiMotor from PiMotor import Sensor import time m1 = PiMotor.Motor("MOTOR1", 1) m2 = PiMotor.Motor("MOTOR2", 1) m3 = PiMotor.Motor("MOTOR3", 1) m4 = PiMotor.Motor("MOTOR4", 1) us = Sensor("ULTRASONIC", 45) ir1 = Sensor("IR2", 10) ir2 = Sensor("IR1", 10) #To drive all motors together motorAll = PiMotor.LinkedMotors(m1, m2, m3, m4) leftMotors = PiMotor.LinkedMotors(m1, m2) rightMotors = PiMotors.LinkedMotors(m3, m4) try: leftMotors.forward(80) rightMotors.reverse(80) time.sleep(5) motorAll.stop() except KeyboardInterrupt: GPIO.cleanup()
import PiMotor from PiMotor import Sensor import time m1 = PiMotor.Motor("MOTOR1", 1) m2 = PiMotor.Motor("MOTOR2", 1) m3 = PiMotor.Motor("MOTOR3", 1) m4 = PiMotor.Motor("MOTOR4", 1) us = Sensor("ULTRASONIC", 45) ir1 = Sensor("IR2", 10) ir2 = Sensor("IR1", 10) ir3 = Sensor("IR3", 10) #To drive all motors together motorAll = PiMotor.LinkedMotors(m1, m2, m3, m4) def trigIR(): ir1.trigger() ir2.trigger() if ir1.Triggered: motorAll.reverse(100) time.sleep(0.7) motorAll.stop() print("Front Line Detected") if ir2.Triggered: motorAll.forward(100) time.sleep(0.7) motorAll.stop() print("Back Line Detected")
#!/usr/bin/python from PiMotor import Sensor us = Sensor("ULTRASONIC", 10) while True: us.sonicCheck() if us.Triggered: print("Sonic detected obtstruction")
from PiMotor import Sensor import time go = "true" while go == "true": us1 = Sensor("IR1", 1) us1.trigger() us2 = Sensor("IR2", 1) us2.trigger() if us1.Triggered and us2.Triggered: print("stop") elif us1.Triggered: print("rechts") elif us2.Triggered: print("links")
import time import sys sys.path.append("/home/pi/MotorShield") from PiMotor import Arrow from PiMotor import Sensor from PiMotor import Motor m1 = Motor("MOTOR1",1) m2 = Motor("MOTOR2",1) m3 = Motor("MOTOR3",1) m4 = Motor("MOTOR4",1) us = Sensor("ULTRASONIC", 10) ls1 = Sensor("IR1",0) ls2 = Sensor("IR2",0) while True: ls1.iRCheck() if ls1.Triggered: print("IR1 detected black line") ls2.iRCheck() if ls2.Triggered: print("IR2 detected black line")
import PiMotor from PiMotor import Sensor import time m1 = PiMotor.Motor("MOTOR1", 1) m2 = PiMotor.Motor("MOTOR2", 1) m3 = PiMotor.Motor("MOTOR3", 1) m4 = PiMotor.Motor("MOTOR4", 1) us = Sensor("ULTRASONIC", 30) ir1 = Sensor("IR1", 4) ir2 = Sensor("IR2", 4) #M1 = BL #M2 = BR #M3 = FR #M4 = FL # #To drive all motors together motorAll = PiMotor.LinkedMotors(m1, m2, m3, m4) try: #To turn around: # m1.forward(100) m2.reverse(100) m3.reverse(100) m4.forward(100) time.sleep(0.9) motorAll.stop() #To do a 90 degree turn right: m1.forward(100) m2.reverse(100) m3.reverse(100) m4.forward(100) time.sleep(0.46) motorAll.stop() #To do a 90 degree turn left:
import sys sys.path.append("/home/pi/MotorShield") from PiMotor import Arrow from PiMotor import Sensor from PiMotor import Motor m1 = Motor("MOTOR1", 1) m2 = Motor("MOTOR2", 1) m3 = Motor("MOTOR3", 1) m4 = Motor("MOTOR4", 1) us = Sensor("ULTRASONIC", 10) ir1 = Sensor("IR1", 0) ir2 = Sensor("IR2", 0) while True: ir1.trigger() if ir1.Triggered: print("No Line Detected - IR1") else: print("Black Line Detected - IR1") ir2.trigger() if ir2.Triggered: print("No Line Detected - IR2") else: print("Black Line Detected - IR2") # except KeyboardInterrupt: # GPIO.cleanup()
from PiMotor import Motor, Sensor import Compass import time, math, keyboard import numpy as np # definicja globalnych zmiennych mL = Motor("MOTOR1", 1) mR = Motor("MOTOR4", 1) sen = Sensor("ULTRASONIC", 10) start_Time = 0.0 end_Time = 0.0 speed = 50 direction = 0.0 realSpeed = 13.5 def DistanceToCheck(): realDistance = realSpeed * (end_Time - start_Time) print("estimated distance traveled: " + str(realDistance)) return realDistance # robot control methods def Forward(): mL.forward(speed) mR.forward(speed) def Revers(): mL.reverse(speed) mR.reverse(speed)