├── Chapter01 ├── 1_1.py ├── 1_2.py ├── 1_3.py └── 1_4.py ├── Chapter02 ├── 2.1.py ├── 2.2.py ├── 2.3.py └── 2.4.py ├── Chapter03 ├── 3_1.py ├── 3_2.py ├── 3_3.py └── 3_4.py ├── Chapter04 ├── 4.1.py └── 4.2.py ├── Chapter05 ├── 5.1.py ├── 5.2.py └── 5.3.py ├── Chapter06 ├── 6_1.py └── 6_2.py ├── Chapter07 ├── 7.1.py ├── 7.2.py └── 7.3.py ├── Chapter08 ├── 8.1.py ├── 8.2.py └── 8.3.py ├── Chapter09 └── 9.1.py ├── Chapter10 ├── 10.1.py ├── 10.2.py ├── 10.3.py ├── 10.4.py └── 10.5.py ├── Chapter11 ├── 11.1.py ├── 11.2.py └── 11.3.py ├── Chapter12 ├── 12.1.py ├── 12.2.py ├── 12.3.py ├── 12.4.py ├── 12.5.py ├── 12.6.py ├── 12.7.py └── 12.8.py ├── Chapter13 ├── 13_1.py └── 13_2.py ├── Chapter14 ├── 14_1.py ├── 14_2.py ├── 14_3.py ├── 14_4.py ├── 14_5.py └── 14_6.py ├── Chapter15 ├── 15_1.py └── 15_2.py ├── Chapter16 └── 16.1.py ├── Chapter17 ├── 17_1.py ├── 17_2.py └── 17_3.py ├── Chapter18 ├── 18.1.py └── 18.2.py ├── LICENSE └── README.md /Chapter01/1_1.py: -------------------------------------------------------------------------------- 1 | import time 2 | import RPi.GPIO as GPIO 3 | GPIO.setmode(GPIO.BCM) 4 | GPIO.setup(23, GPIO.OUT) 5 | GPIO.setup(24, GPIO.IN) 6 | GPIO.setup(22, GPIO.OUT) 7 | while True: 8 | button_state = GPIO.input(24) 9 | if(button_state == True): 10 | GPIO.output(23,GPIO.HIGH) 11 | else: 12 | GPIO.output(23,GPIO.LOW) 13 | time.sleep(0.5) -------------------------------------------------------------------------------- /Chapter01/1_2.py: -------------------------------------------------------------------------------- 1 | import time 2 | import RPi.GPIO as GPIO 3 | GPIO.setmode(GPIO.BCM) 4 | GPIO.setup(23,GPIO.IN) 5 | GPIO.setup(24,GPIO.OUT) 6 | while True: 7 | if GPIO.input(23) == 1: 8 | GPIO.output(24,GPIO.HIGH) 9 | else: 10 | GPIO.output(24,GPIO.LOW) 11 | time.sleep(1) 12 | GPIO.cleanup() 13 | -------------------------------------------------------------------------------- /Chapter01/1_3.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | GPIO.setmode(GPIO.BCM) 4 | GPIO.setup(23,GPIO.OUT) 5 | GPIO.setup(24,GPIO.IN) 6 | while True: 7 | pulse_start = 0 8 | pulse_stop = 0 9 | duration = 0 10 | distance = 0 11 | GPIO.output(23,GPIO.LOW) 12 | time.sleep(0.1) 13 | GPIO.output(23,GPIO.HIGH) 14 | time.sleep(0.000010) 15 | GPIO.output(23,GPIO.LOW) 16 | while GPIO.input(24)==0: 17 | pulse_start = time.time() 18 | while GPIO.input(24)==1: 19 | pulse_stop = time.time() 20 | duration = pulse_stop - pulse_start 21 | distance = duration*17150.0 22 | distance = round(distance,2) 23 | print 'Distance = ',distance 24 | time.sleep(0.2) -------------------------------------------------------------------------------- /Chapter01/1_4.py: -------------------------------------------------------------------------------- 1 | import time 2 | import Adafruit_ADS1x15 3 | import RPi.GPIO as GPIO 4 | LED =14 5 | GPIO.setmode(GPIO.BCM) 6 | GPIO.setup(LED,GPIO.OUT) 7 | adc = Adafruit_ADS1x15.ADS1115() 8 | GAIN = 1 9 | channel=0 10 | adc.start_adc(channel, gain=GAIN) 11 | while True: 12 | value = adc.get_last_result() 13 | print(str(value)) 14 | time.sleep(0.1) 15 | if value >= 100: 16 | GPIO.output(LED,1) 17 | else: 18 | GPIO.output(LED,0) 19 | adc.stop_adc() -------------------------------------------------------------------------------- /Chapter02/2.1.py: -------------------------------------------------------------------------------- 1 | import time import RPi.GPIO as GPIO 2 | GPIO.setmode(GPIO.BCM) 3 | GPIO.setup(23,GPIO.IN) 4 | GPIO.setup(24,GPIO.OUT) 5 | while True: 6 | button_state = GPIO.input(24) 7 | if button_state == True: 8 | GPIO.output(23,GPIO.HIGH) 9 | else: 10 | GPIO.output(23,GPIO.LOW) 11 | time.sleep(0.5) 12 | GPIO.cleanup() -------------------------------------------------------------------------------- /Chapter02/2.2.py: -------------------------------------------------------------------------------- 1 | import time import RPi.GPIO as GPIO 2 | GPIO.setmode(GPIO.BCM) 3 | GPIO.setup(23,GPIO.IN) 4 | GPIO.setup(24,GPIO.OUT) 5 | while True: 6 | if GPIO.input(23) == 1: 7 | GPIO.output(24,GPIO.HIGH) 8 | else: 9 | GPIO.output(24,GPIO.LOW) 10 | 11 | time.sleep(1) 12 | GPIO.cleanup() -------------------------------------------------------------------------------- /Chapter02/2.3.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | 4 | GPIO.setmode(GPIO.BCM) 5 | GPIO.setup(23,GPIO.OUT) 6 | GPIO.setup(24,GPIO.IN) 7 | 8 | while True: 9 | pulse_start = 0 10 | pulse_stop = 0 11 | duration = 0 12 | distance = 0 13 | 14 | GPIO.output(23,GPIO.LOW) 15 | time.sleep(0.1) 16 | GPIO.output(23,GPIO.HIGH) 17 | time.sleep(0.000010) 18 | GPIO.output(23,GPIO.LOW) 19 | 20 | while GPIO.input(24)==0: 21 | pulse_start = time.time() 22 | 23 | while GPIO.input(24)==1: 24 | pulse_stop = time.time() 25 | 26 | duration = pulse_stop - pulse_start 27 | 28 | distance = duration*17150.0 29 | distance = round(distance,2) 30 | print ("distance" + str(distance)) 31 | 32 | time.sleep(0.2) 33 | } -------------------------------------------------------------------------------- /Chapter02/2.4.py: -------------------------------------------------------------------------------- 1 | import time 2 | import Adafruit_ADS1x15 3 | import RPi.GPIO as GPIO 4 | LED =14 5 | 6 | GPIO.setmode(GPIO.BCM) 7 | GPIO.setup(LED,GPIO.OUT) 8 | 9 | adc = Adafruit_ADS1x15.ADS1115() 10 | GAIN = 1 11 | channel=0 12 | adc.start_adc(channel, gain=GAIN) 13 | 14 | while True: 15 | value = adc.get_last_result() 16 | print(str(value)) 17 | time.sleep(0.1) 18 | if value >= 100: 19 | GPIO.output(LED,1) 20 | else : 21 | GPIO.output(LED,0) 22 | 23 | adc.stop_adc() -------------------------------------------------------------------------------- /Chapter03/3_1.py: -------------------------------------------------------------------------------- 1 | import time 2 | import RPi.GPIO as GPIO 3 | import Adafruit_ADS1x15 4 | water_valve_pin = 23 5 | moisture_percentage = 20 6 | GPIO.setmode(GPIO.BCM) 7 | GPIO.setwarnings(False) 8 | GPIO.setup(water_valve_pin, GPIO.OUT) 9 | adc = Adafruit_ADS1x15.ADS1115() 10 | channel = 0 11 | GAIN = 1 12 | while True: 13 | adc.start_adc(channel, gain=GAIN) 14 | moisture_value = adc.get_last_result() 15 | moisture_value = int(moisture_value/327) 16 | print moisture_value 17 | if moisture_value < moisture_percentage: 18 | GPIO.output(water_valve_pin, GPIO.HIGH) 19 | time.sleep(5) 20 | else: 21 | GPIO.output(water_valve_pin, GPIO.LOW) -------------------------------------------------------------------------------- /Chapter03/3_2.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Robotics-Projects/17221304cb3e15e486af855b442927f64fdcc738/Chapter03/3_2.py -------------------------------------------------------------------------------- /Chapter03/3_3.py: -------------------------------------------------------------------------------- 1 | from time import sleep 2 | from datetime import datetime 3 | import RPi.GPIO as GPIO 4 | import Adafruit_DHT 5 | sensor = 11 6 | pin = 4 7 | GPIO.setmode(GPIO.BCM) 8 | GPIO.setwarnings(False) 9 | while True: 10 | humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) 11 | print("Temperature: " +temperature+ "C") 12 | print("Humidity: " +humidity+ "%") 13 | time.sleep(2) 14 | -------------------------------------------------------------------------------- /Chapter03/3_4.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Robotics-Projects/17221304cb3e15e486af855b442927f64fdcc738/Chapter03/3_4.py -------------------------------------------------------------------------------- /Chapter04/4.1.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | from time import sleep 3 | GPIO.setmode(GPIO.BCM) 4 | 5 | Motor1R = 20 6 | Motor1L = 21 7 | 8 | GPIO.setup(Motor1R,GPIO.OUT) 9 | GPIO.setup(Motor1L,GPIO.OUT) 10 | 11 | 12 | GPIO.output(Motor1R,GPIO.HIGH) 13 | GPIO.output(Motor1L,GPIO.LOW) 14 | 15 | sleep(5) 16 | 17 | GPIO.output(Motor1R,GPIO.LOW) 18 | GPIO.output(Motor1L,GPIO.HIGH) 19 | 20 | sleep(5) 21 | 22 | GPIO.cleanup() -------------------------------------------------------------------------------- /Chapter04/4.2.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | from time 3 | import sleep 4 | GPIO.setmode(GPIO.BCM) 5 | 6 | Motor1R = 20 7 | Motor1L = 21 8 | 9 | GPIO.setup(Motor1R, GPIO.OUT) 10 | GPIO.setup(Motor1L, GPIO.OUT) 11 | 12 | pwm = GPIO.PWM(Motor1R, 100) 13 | pwm.start(0) 14 | 15 | try: 16 | while True: 17 | GPIO.output(Motor1L, GPIO.LOW) 18 | for i in range(0, 101): 19 | pwm.ChangeDutyCycle(i) 20 | sleep(0.1) 21 | 22 | except KeyboardInterrupt: 23 | 24 | pwm.stop() 25 | GPIO.cleanup() -------------------------------------------------------------------------------- /Chapter05/5.1.py: -------------------------------------------------------------------------------- 1 | import Adafruit_ADS1x15 2 | import RPi.GPIO as GPIO 3 | 4 | adc = Adafruit_ADS1x15.ADS1015() 5 | 6 | GAIN = 1 7 | channel = 0 8 | 9 | adc.start_adc(channel, gain=GAIN) 10 | 11 | while True: 12 | 13 | print(adc.get_last_result()) -------------------------------------------------------------------------------- /Chapter05/5.2.py: -------------------------------------------------------------------------------- 1 | import Adafruit_ADS1x15 2 | import RPi.GPIO as GPIO 3 | import time 4 | Motor1a = 21 5 | Motor1b = 20 6 | Buzzer = 14 7 | FSR = 16 8 | THRESHOLD = 1000 9 | GPIO.setmode(GPIO.BCM) 10 | GPIO.setup(Motor1a,GPIO.OUT) 11 | GPIO.setup(Motor1b,GPIO.OUT) 12 | GPIO.setup(Buzzer,GPIO.OUT) 13 | GPIO.setup(FSR,GPIO.IN) 14 | adc = Adafruit_ADS1x15.ADS1015() 15 | GAIN = 1 16 | channel = 0 17 | adc.start_adc(channel, gain=GAIN) 18 | while True: 19 | M = datetime.datetime.now().strftime('%M') 20 | if (H == 12 or H==16 or H==20) && M == 00 : 21 | value = adc.get_last_result() 22 | while value < THRESHOLD: 23 | GPIO.output(BUZZER,1) 24 | GPIO.output(MOTOR1a,1) 25 | GPIO.output(MOTOR1b,0) 26 | GPIO.output(MOTOR1a,0) 27 | GPIO.output(MOTOR1b,1) 28 | GPIO.output(Buzzer,0) 29 | time.sleep(5) 30 | GPIO.output(MOTOR1b,0) 31 | adc.stop_adc() -------------------------------------------------------------------------------- /Chapter05/5.3.py: -------------------------------------------------------------------------------- 1 | import time 2 | import Adafruit_ADS1x15 3 | import RPi.GPIO as GPIO 4 | 5 | Motor1a = 21 6 | Motor1b = 20 7 | Buzzer = 14 8 | FSR = 16 9 | 10 | GPIO.setmode(GPIO.BCM) 11 | GPIO.setup(Motor1a,GPIO.OUT) 12 | GPIO.setup(Motor1b,GPIO.OUT) 13 | GPIO.setup(Buzzer,GPIO.OUT) 14 | GPIO.setup(FSR,GPIO.IN) 15 | 16 | adc = Adafruit_ADS1x15.ADS1015() 17 | 18 | GAIN = 1 19 | channel = 0 20 | 21 | adc.start_adc(channel, gain=GAIN) 22 | 23 | 24 | def Distance(): 25 | GPIO.output(23,GPIO.LOW) 26 | 27 | time.sleep(0.2) 28 | 29 | GPIO.output(23,GPIO.HIGH) 30 | 31 | time.sleep(0.000010) 32 | 33 | GPIO.output(23,GPIO.LOW) 34 | 35 | while GPIO.input(24)==0: 36 | pulse_start = time.time() 37 | 38 | while GPIO.input(24)==1: 39 | pulse_stop = time.time() 40 | 41 | duration = pulse_stop - pulse_start 42 | distance = duration*17150.0 43 | distance = round(distance,2) 44 | 45 | return distance 46 | 47 | while True: 48 | 49 | 50 | H = datetime.datetime.now().strftime('%H') 51 | 52 | if H == 12 or H==16 or H==20: 53 | value = adc.get_last_result() 54 | 55 | while value < 100: 56 | GPIO.output(BUZZER,1) 57 | GPIO.output(MOTOR1a,1) 58 | GPIO.output(MOTOR1b,0) 59 | 60 | time.sleep(5) 61 | 62 | GPIO.output(MOTOR1a,0) 63 | GPIO.output(MOTOR1b,0) 64 | 65 | if Distance() <=2 : 66 | 67 | GPIO.output(Buzzer, 0) 68 | time.sleep(5) 69 | 70 | adc.stop_adc() -------------------------------------------------------------------------------- /Chapter06/6_1.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | GPIO.setmode(GPIO.BCM) 4 | Motor1a = 20 5 | Motor1b = 21 6 | Motor2a = 2 7 | Motor2b = 3 8 | GPIO.setup(Motor1a,GPIO.OUT) 9 | GPIO.setup(Motor1b,GPIO.OUT) 10 | GPIO.setup(Motor2a,GPIO.OUT) 11 | GPIO.setup(Motor2b,GPIO.OUT) 12 | GPIO.output(Motor1a,1) 13 | GPIO.output(Motor1b,0) 14 | GPIO.output(Motor2a,1) 15 | GPIO.output(Motor2b,0) 16 | time.sleep(10) 17 | GPIO.cleanup() -------------------------------------------------------------------------------- /Chapter06/6_2.py: -------------------------------------------------------------------------------- 1 | import bluetooth 2 | import time 3 | import RPi.GPIO as GPIO 4 | Motor1a = 20 5 | Motor1b = 21 6 | Motor2a = 2 7 | Motor2b = 3 8 | GPIO.setmode(GPIO.BCM) 9 | GPIO.setwarnings(False) 10 | GPIO.setup(Motor1a,GPIO.OUT) 11 | GPIO.setup(Motor1b,GPIO.OUT) 12 | GPIO.setup(Motor2a,GPIO.OUT) 13 | GPIO.setup(Motor2b,GPIO.OUT) 14 | server_socket=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) 15 | port = 1 16 | server_socket.bind(("",port)) 17 | server_socket.listen(1) 18 | client_socket,address = server_socket.accept() 19 | print ("Accepted connection from "+str(address)) 20 | def stop_car(): 21 | GPIO.output(Motor1a,0) 22 | GPIO.output(Motor1b,0) 23 | GPIO.output(Motor2a,0) 24 | GPIO.output(Motor2b,0) 25 | 26 | while True: 27 | data = client_socket.recv(1024) 28 | if (data == "B" or data== "b"): 29 | GPIO.output(Motor1a,1) 30 | GPIO.output(Motor1b,0) 31 | GPIO.output(Motor2a,1) 32 | GPIO.output(Motor2b,0) 33 | time.sleep(1) 34 | stop_car() 35 | 36 | if (data == "F" or data == "f"): 37 | GPIO.output(Motor1a,0) 38 | GPIO.output(Motor1b,1) 39 | GPIO.output(Motor2a,0) 40 | GPIO.output(Motor2b,1) 41 | time.sleep(1) 42 | stop_car() 43 | 44 | if (data == "R" or data == "r"): 45 | GPIO.output(Motor1a,0) 46 | GPIO.output(Motor1b,1) 47 | GPIO.output(Motor2a,1) 48 | GPIO.output(Motor2b,0) 49 | time.sleep(1) 50 | stop_car() 51 | 52 | if (data == "L" or data == "l"): 53 | GPIO.output(Motor1a,1) 54 | GPIO.output(Motor1b,0) 55 | GPIO.output(Motor2a,0) 56 | GPIO.output(Motor2b,1) 57 | time.sleep(1) 58 | stop_car() 59 | 60 | if (data == "Q" or data =="q"): 61 | stop_car() 62 | 63 | if (data =='Z' or data == "z"): 64 | client_socket.close() 65 | server_socket.close() 66 | -------------------------------------------------------------------------------- /Chapter07/7.1.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | GPIO.setmode(GPIO.BCM) 4 | import Adafruit_ADS1x15 5 | adc0 = Adafruit_ADS1x15.ADS1115() 6 | GAIN = 1 7 | adc0.start_adc(0, gain=GAIN) 8 | Motor1a = 20 9 | Motor1b = 21 10 | Motor2a = 23 11 | Motor2b = 24 12 | GPIO.setup(Motor1a,GPIO.OUT) 13 | GPIO.setup(Motor1b,GPIO.OUT) 14 | GPIO.setup(Motor2a,GPIO.OUT) 15 | GPIO.setup(Motor2b,GPIO.OUT) 16 | def forward(): 17 | GPIO.output(Motor1a,0) 18 | GPIO.output(Motor1b,1) 19 | GPIO.output(Motor2a,0) 20 | GPIO.output(Motor2b,1) 21 | def stop(): 22 | GPIO.output(Motor1a,0) 23 | GPIO.output(Motor1b,0) 24 | GPIO.output(Motor2a,0) 25 | GPIO.output(Motor2b,0) 26 | while True: 27 | F_value = adc0.get_last_result() 28 | F = (1.0 / (F_value / 13.15)) - 0.35 29 | min_dist = 5 If F < min_dist: 30 | stop() -------------------------------------------------------------------------------- /Chapter07/7.2.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | GPIO.setmode(GPIO.BCM) 4 | 5 | import Adafruit_ADS1x15 6 | adc0 = Adafruit_ADS1x15.ADS1115() 7 | 8 | GAIN = 1 9 | 10 | adc0.start_adc(0, gain=GAIN) 11 | 12 | Motor1a = 20 13 | Motor1b = 21 14 | Motor2a = 23 15 | Motor2b = 24 16 | 17 | GPIO.setup(Motor1a,GPIO.OUT) 18 | GPIO.setup(Motor1b,GPIO.OUT) 19 | GPIO.setup(Motor2a,GPIO.OUT) 20 | GPIO.setup(Motor2b,GPIO.OUT) 21 | 22 | def forward(): 23 | GPIO.output(Motor1a,0) 24 | GPIO.output(Motor1b,1) 25 | GPIO.output(Motor2a,0) 26 | GPIO.output(Motor2b,1) 27 | 28 | def turn(): 29 | GPIO.output(Motor1a,0) 30 | GPIO.output(Motor1b,1) 31 | GPIO.output(Motor2a,1) 32 | GPIO.output(Motor2b,0) 33 | ) 34 | 35 | while True: 36 | forward() 37 | 38 | F_value = adc0.get_last_result() 39 | F = (1.0 / (F_value / 13.15)) - 0.35 40 | 41 | min_dist = 20 42 | 43 | while F < min_dist: 44 | turn() -------------------------------------------------------------------------------- /Chapter07/7.3.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | 4 | GPIO.setmode(GPIO.BCM) 5 | 6 | import Adafruit_ADS1x15 7 | adc0 = Adafruit_ADS1x15.ADS1115() 8 | 9 | GAIN = 1 10 | adc0.start_adc(0, gain=GAIN) 11 | 12 | Motor1a = 20 13 | Motor1b = 21 14 | Motor2a = 23 15 | Motor2b = 24 16 | 17 | GPIO.setup(Motor1a,GPIO.OUT) 18 | GPIO.setup(Motor1b,GPIO.OUT) 19 | GPIO.setup(Motor2a,GPIO.OUT) 20 | GPIO.setup(Motor2b,GPIO.OUT) 21 | 22 | def forward(): 23 | GPIO.output(Motor1a,0) 24 | GPIO.output(Motor1b,1) 25 | GPIO.output(Motor2a,0) 26 | GPIO.output(Motor2b,1) 27 | 28 | def right(): 29 | GPIO.output(Motor1a,0) 30 | GPIO.output(Motor1b,1) 31 | GPIO.output(Motor2a,1) 32 | GPIO.output(Motor2b,0) 33 | 34 | def left(): 35 | GPIO.output(Motor1a,1) 36 | GPIO.output(Motor1b,0) 37 | GPIO.output(Motor2a,0) 38 | GPIO.output(Motor2b,1) 39 | 40 | def stop(): 41 | GPIO.output(Motor1a,0) 42 | GPIO.output(Motor1b,0) 43 | GPIO.output(Motor2a,0) 44 | GPIO.output(Motor2b,0) 45 | 46 | while True: 47 | 48 | forward() 49 | 50 | F_value = adc0.get_last_result() 51 | F = (1.0 / (F_value / 13.15)) - 0.35 52 | 53 | min_dist = 20 54 | if F< min_dist: 55 | 56 | stop() 57 | 58 | right() 59 | time.sleep(1) 60 | 61 | F_value = adc0.get_last_result() 62 | F = (1.0 / (F_value / 13.15)) - 0.35 63 | R = F 64 | 65 | left() 66 | time.sleep(2) 67 | 68 | F_value = adc0.get_last_result() 69 | F = (1.0 / (F_value / 13.15)) - 0.3 70 | 71 | L = F 72 | 73 | if L < R: 74 | right() 75 | time.sleep(2) 76 | 77 | else: 78 | forward() -------------------------------------------------------------------------------- /Chapter08/8.1.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | 4 | GPIO.setmode(GPIO.BCM) 5 | GPIO.setup(14,GPIO.OUT) 6 | 7 | pwm = GPIO.PWM(14, 50) 8 | pwm.start(0) 9 | 10 | while 1: 11 | 12 | pwm.ChangeDutyCycle(2.5) 13 | time.sleep(2) 14 | 15 | pwm.ChangeDutyCycle(5) 16 | time.sleep(2) 17 | 18 | pwm.ChangeDutyCycle(7.5) 19 | time.sleep(2) 20 | 21 | pwm.ChangeDutyCycle(10) 22 | time.sleep(2) 23 | 24 | pwm.ChangeDutyCycle(12.5) 25 | time.sleep(2) -------------------------------------------------------------------------------- /Chapter08/8.2.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | import Adafruit_ADS1x15 4 | 5 | adc = Adafruit_ADS1x15.ADS1115() 6 | GAIN = 1 7 | 8 | adc.start_adc(0, gain=GAIN) 9 | GPIO.setmode(GPIO.BCM) 10 | GPIO.setup(14,GPIO.OUT) 11 | GPIO.setwarnings(False) 12 | 13 | servo = GPIO.PWM(14, 50) 14 | 15 | servo.start(0) 16 | 17 | Def Distance(): 18 | D_value = adc0.get_last_result() 19 | D = (1.0 / (F_value / 13.15)) - 0.35 20 | Return D 21 | 22 | j=12.5 23 | k=2.5 24 | i=0 25 | 26 | distLR=[] 27 | distRL=[] 28 | 29 | while True: 30 | while k<=12.5: 31 | servo.ChangeDutyCycle(k) 32 | time.sleep(.1) 33 | distLR.insert(i,Distance()) 34 | k = k + 2.5 35 | i = i + 1 36 | print distLR 37 | 38 | i=0 39 | k=0 40 | 41 | del distLR[:] 42 | 43 | while j>=2.5: 44 | servo.ChangeDutyCycle(j) 45 | time.sleep(.1) 46 | j = j - 2.5 47 | distRL.insert(i,Distance()) 48 | i = i + 1 49 | 50 | print distRL 51 | 52 | i=0 53 | k=2.5 54 | j=12.5 55 | 56 | del distRL[:] -------------------------------------------------------------------------------- /Chapter08/8.3.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | import Adafruit_ADS1x15 4 | 5 | adc0 = Adafruit_ADS1x15.ADS1115() 6 | GAIN = 1 7 | adc0.start_adc(0, gain=GAIN) 8 | 9 | GPIO.setmode(GPIO.BCM) 10 | GPIO.setup(14,GPIO.OUT) 11 | 12 | servo = GPIO.PWM(14, 50) 13 | servo.start(0) 14 | 15 | def Distance(): 16 | D_value = adc0.get_last_result() 17 | D = (1.0 / (F_value / 13.15)) - 0.35 18 | Return D 19 | 20 | GPIO.setup(20,GPIO.OUT) 21 | GPIO.setup(21,GPIO.OUT) 22 | GPIO.setup(23,GPIO.OUT) 23 | GPIO.setup(24,GPIO.OUT) 24 | 25 | LForward = GPIO.PWM(20, 50) 26 | LReverse = GPIO.PWM(21, 50) 27 | RForward = GPIO.PWM(23,50) 28 | RReverse = GPIO.PWM(24,50) 29 | 30 | def stop(): 31 | LForward.changeDutyCycle(0) 32 | LReverse.changeDutyCycle(0) 33 | RForward.changeDutyCycle(0) 34 | RReverse.changeDutyCycle(0) 35 | 36 | 37 | def direction(index): 38 | 39 | if index == 0 : 40 | LForward.changeDutyCycle(0) 41 | LReverse.changeDutyCycle(30) 42 | RForward.changeDutyCycle(30) 43 | RReverse.changeDutyCycle(0) 44 | 45 | elif index == 1 46 | 47 | LForward.changeDutyCycle(20) 48 | LReverse.changeDutyCycle(0) 49 | RForward.changeDutyCycle(50) 50 | RReverse.changeDutyCycle(0) 51 | 52 | elif index == 2 : 53 | 54 | LForward.changeDutyCycle(50) 55 | LReverse.changeDutyCycle(0) 56 | RForward.changeDutyCycle(50) 57 | RReverse.changeDutyCycle(0) 58 | 59 | elif index == 3 : 60 | 61 | LForward.changeDutyCycle(50) 62 | LReverse.changeDutyCycle(0) 63 | RForward.changeDutyCycle(20) 64 | RReverse.changeDutyCycle(0) 65 | 66 | 67 | elif index == 4 : 68 | 69 | LForward.changeDutyCycle(20) 70 | LReverse.changeDutyCycle(0) 71 | RForward.changeDutyCycle(0) 72 | RReverse.changeDutyCycle(20) 73 | 74 | else: 75 | stop() 76 | 77 | j=12.5 78 | k=2.5 79 | i=0 80 | 81 | dist1=[] 82 | dist2=[] 83 | 84 | while True: 85 | 86 | while k<=12.5: 87 | servo.ChangeDutyCycle(k) 88 | time.sleep(.2) 89 | dist1.insert(i,Distance()) 90 | k = k + 2.5 91 | i = i + 1 92 | 93 | print dist1 94 | 95 | i=0 96 | k=2 97 | 98 | max_dist1 = max(dist1) 99 | max_dist1_index = dist1.index(max_dist1) 100 | 101 | direction(max_dist1_index) 102 | 103 | del dist1[:] 104 | 105 | print max_dist1 106 | print max_dist1_index 107 | 108 | while j>=2.5: 109 | servo.ChangeDutyCycle(j) 110 | time.sleep(.2) 111 | j = j - 2.5 112 | dist2.insert(i,Distance()) 113 | i = i + 1 114 | 115 | print dist2 116 | 117 | i=0 118 | j=12 119 | 120 | max_dist2 = max(dist2) 121 | max_dist2_index = dist2.index(max_dist2) 122 | 123 | direction(max_dist2_index) 124 | 125 | del dist2[:] 126 | 127 | print max_dist2 128 | print max_dist2_index -------------------------------------------------------------------------------- /Chapter09/9.1.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | cap = cv2.VideoCapture(0) 4 | 5 | while True: 6 | _, image = cap.read() 7 | cv2.imshow("Frame", image) 8 | hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) 9 | 10 | 11 | lowerGreen = np.array([80,50,50]) 12 | upperGreen = np.array([130,255,255]) 13 | 14 | mask = cv2.inRange(hsv, lowerGreen, upperGreen) 15 | res = cv2.bitwise_and(image, image, mask=mask) 16 | cv2.imshow('mask',mask) 17 | cv2.imshow('result',res) 18 | key = cv2.waitKey(1) & 0xFF 19 | 20 | 21 | if key == ord('q'): 22 | break 23 | cv2.destroyAllWindows() 24 | cap.release() -------------------------------------------------------------------------------- /Chapter10/10.1.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 5 | 6 | cap = cv2.VideoCapture(0) 7 | 8 | while True: 9 | 10 | ret, img = cap.read() 11 | gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 12 | faces = face_cascade.detectMultiScale(gray) 13 | 14 | for (x,y,w,h) in faces: 15 | cv2.rectangle(img, (x,y), (x+w, y+h), (255,0,0), 2) 16 | 17 | cv2.imshow('img',img) 18 | 19 | k = cv2.waitKey(1) & 0xff 20 | if k == ord(‘q’): 21 | break 22 | 23 | cap.release() 24 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Chapter10/10.2.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | 4 | faceDetect = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 5 | cam = cv2.VideoCapture(0) 6 | 7 | sampleNum = 0 8 | 9 | id = raw_input('enter user id') 10 | 11 | while True: 12 | ret,img = cam.read() 13 | gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 14 | faces = faceDetect.detectMultiScale(gray,1.3,5) 15 | 16 | for (x,y,w,h) in faces: 17 | sampleNum = sampleNum + 1 18 | cv2.imwrite("dataSet/User."+str(id)+"."+str(sampleNum)+".jpg", gray[y:y+h, x:x+w]) 19 | 20 | cv2.rectangle(img, (x,y), (x+w,y+h), (0,0,255), 2) 21 | cv2.waitKey(100) 22 | cv2.imshow("Face", img) 23 | cv2.waitKey(1) 24 | if sampleNum>20: 25 | 26 | break 27 | cam.release() 28 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Chapter10/10.3.py: -------------------------------------------------------------------------------- 1 | import os 2 | import cv2 3 | import numpy as np 4 | from PIL import Image 5 | 6 | recognizer = cv2.face.LBPHFaceRecognizer_create() 7 | 8 | path = 'dataSet' 9 | 10 | def getImageID(path): 11 | imagePaths = [os.path.join(path,f) for f in os.listdir(path)] 12 | 13 | faces=[] 14 | IDs=[] 15 | 16 | for imagePath in imagePaths: 17 | faceImg = Image.open(imagePath).convert('L') 18 | 19 | faceNp = np.array(faceImg, 'uint8') 20 | 21 | ID = int(os.path.split(imagePath)[-1].split('.')[1]) 22 | 23 | faces.append(faceNp) 24 | print ID 25 | IDs.append(ID) 26 | 27 | return IDs, faces 28 | 29 | Ids, faces = getImageID(path) 30 | recognizer.train(faces, np.array(Ids)) 31 | recognizer.save('recognizer/trainningData.yml') 32 | 33 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Chapter10/10.4.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | 4 | faceDetect = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 5 | 6 | cam = cv2.VideoCapture(0) 7 | rec = cv2.face.LBPHFaceRecognizer_create() 8 | 9 | rec.read("recognizer/trainningData.yml") 10 | id = 0 11 | font = cv2.FONT_HERSHEY_SIMPLEX 12 | 13 | while True: 14 | 15 | ret, img = cam.read() 16 | gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 17 | faces = faceDetect.detectMultiScale(gray,1.3,5) 18 | 19 | for (x,y,w,h) in faces: 20 | cv2.rectangle(img, (x,y), (x+w, y+h), (0,0,255), 2) 21 | id, conf = rec.predict(gray[y:y+h, x:x+w]) 22 | 23 | if id==1: 24 | id = "BEN" 25 | cv2.putText(img, str(id), (x,y+h),font,2, (255,0,0),1,) 26 | 27 | cv2.imshow("face", img) 28 | 29 | if cv2.waitKey(1)==ord('q'): 30 | break 31 | 32 | cam.release() 33 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Chapter10/10.5.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import cv2 3 | Import RPi.GPIO as GPIO 4 | 5 | Motor1F = 20 6 | Motor1R = 21 7 | Motor2F = 2 8 | Motor2R = 3 9 | Buzzer = 24 10 | 11 | GPIO.setmode(GPIO.BCM) 12 | GPIO.setwarnings(False) 13 | GPIO.setup(Motor1a,GPIO.OUT) 14 | GPIO.setup(Motor1b,GPIO.OUT) 15 | GPIO.setup(Motor2a,GPIO.OUT) 16 | GPIO.setup(Motor2b,GPIO.OUT) 17 | GPIO.setup(Buzzer, GPIO.OUT) 18 | 19 | def forward(): 20 | 21 | GPIO.output(Motor1F,1) 22 | GPIO.output(Motor1R,0) 23 | GPIO.output(Motor2F,1) 24 | GPIO.output(Motor2R,0) 25 | 26 | def backward(): 27 | 28 | GPIO.output(Motor1F,0) 29 | GPIO.output(Motor1R,1) 30 | GPIO.output(Motor2F,0) 31 | GPIO.output(Motor2R,1) 32 | 33 | def stop(): 34 | 35 | GPIO.output(Motor1F,0) 36 | GPIO.output(Motor1R,0) 37 | GPIO.output(Motor2F,0) 38 | GPIO.output(Motor2R,0) 39 | 40 | faceDetect = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 41 | 42 | cam = cv2.VideoCapture(0) 43 | rec = cv2.face.LBPHFaceRecognizer_create() 44 | rec.read("recognizer/trainningData.yml") 45 | 46 | id = 0 47 | font = cv2.FONT_HERSHEY_SIMPLEX 48 | 49 | while True: 50 | 51 | ret, img = cam.read() 52 | gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 53 | faces = faceDetect.detectMultiScale(gray,1.3,5) 54 | 55 | for (x,y,w,h) in faces: 56 | cv2.rectangle(img, (x,y), (x+w, y+h), (0,0,255), 2) 57 | id, conf = rec.predict(gray[y:y+h, x:x+w]) 58 | 59 | if id==1: 60 | id = "BEN" 61 | 62 | forward() 63 | time.sleep(1) 64 | stop() 65 | time.sleep(5) 66 | backward() 67 | time.sleep(1) 68 | 69 | else : 70 | 71 | GPIO.output(Buzzer, 1) 72 | time.sleep(5) 73 | 74 | cv2.putText(img, str(id), (x,y+h),font,2, (255,0,0),1,cv2.LINE_AA) 75 | cv2.imshow("face", img) 76 | 77 | id = 0 78 | if cv2.waitKey(1)==ord('q'): 79 | break 80 | 81 | cam.release() 82 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /Chapter11/11.1.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | 4 | LIGHT = 23 5 | 6 | GPIO.setmode(GPIO.BCM) 7 | GPIO.setwarnings(False) 8 | GPIO.setup(LIGHT,GPIO.OUT) 9 | 10 | import datetime 11 | 12 | H = datetime.datetime.now().strftime('%H') 13 | M = datetime.datetime.now().strftime('%M') 14 | 15 | 16 | while True: 17 | 18 | if H = '06'and M < 20 : 19 | GPIO.output(LIGHT,GPIO.HIGH) 20 | 21 | else: 22 | GPIO.output(LIGHT,GPIO.LOW) -------------------------------------------------------------------------------- /Chapter11/11.2.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | 4 | LIGHT = 23 5 | PIR = 24 6 | Irritation_flag = 3 7 | 8 | GPIO.setmode(GPIO.BCM) 9 | GPIO.setwarnings(False) 10 | 11 | GPIO.setup(LIGHT,GPIO.OUT) 12 | GPIO.setup(PIR, GPIO.IN) 13 | 14 | import datetime 15 | 16 | H = datetime.datetime.now().strftime('%H') 17 | M = datetime.datetime.now().strftime('%M') 18 | 19 | 20 | while True: 21 | 22 | if H = '07' and M <= '15' and Iriitation_Flag > 0 and GPIO.input(PIR) == 0: 23 | 24 | GPIO.output(LIGHT,GPIO.HIGH) 25 | 26 | 27 | if H = '07'and GPIO.input(PIR)==1: 28 | 29 | GPIO.output(LIGHT,GPIO.LOW) 30 | time.sleep(10) 31 | Irritation_Flag = Irritation_Flag - 1 32 | 33 | 34 | for H = '07'and M > '15' and Irritation_Flag > 0 and GPIO.input(PIR) = 0: 35 | 36 | GPIO.output(LIGHT,GPIO.HIGH) 37 | time.sleep(5) 38 | GPIO.output(LIGHT,GPIO.LOW) 39 | time.sleep(5) 40 | 41 | 42 | if H != '07': 43 | 44 | Irritation_flag = 3 45 | GPIOP.output(LIGHT, GPIO.LOW) -------------------------------------------------------------------------------- /Chapter11/11.3.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | 4 | import Adafruit_ADS1x15 5 | adc0 = Adafruit_ADS1x15.ADS1115() 6 | 7 | GAIN = 1 8 | 9 | adc0.start_adc(0, gain=GAIN) 10 | 11 | LIGHT = 23 12 | PIR = 24 13 | Irritation_flag = 1 14 | IR = 2 15 | 16 | GPIO.setmode(GPIO.BCM) 17 | GPIO.setwarnings(False) 18 | 19 | GPIO.setup(LIGHT,GPIO.OUT) 20 | GPIO.setup(PIR, GPIO.IN) 21 | GPIO.setup(IR. GPIO.IN) 22 | 23 | import datetime 24 | 25 | H = datetime.datetime.now().strftime('%H') 26 | M = datetime.datetime.now().strftime('%M') 27 | 28 | 29 | while True: 30 | 31 | if H = '07' and M <= '15' and Iriitation_Flag > 0 and GPIO.input(PIR) == 0: 32 | 33 | GPIO.output(LIGHT,GPIO.HIGH) 34 | 35 | 36 | if H = '07'and GPIO.input(PIR)==1: 37 | 38 | M_snooze = datetime.datetime.now().strftime('%M') 39 | M_snooze = M_snooze + 5 40 | 41 | for M <= M_snooze 42 | 43 | GPIO.output(LIGHT,GPIO.LOW) 44 | 45 | F_value = adc0.get_last_result() 46 | F1 = (1.0 / (F_value / 13.15)) - 0.35 47 | 48 | time.sleep(0.1) 49 | 50 | F_value = adc0.get_last_result() 51 | F2 = (1.0 / (F_value / 13.15)) - 0.35 52 | 53 | F_final = F1-F2 54 | 55 | M = datetime.datetime.now().strftime('%M') 56 | 57 | if F_final > 25 58 | 59 | Irritation_flag = 0 60 | 61 | 62 | 63 | for H = '07'and M > '15' and Irritation_Flag > 0 and GPIO.input(PIR) = 0: 64 | 65 | GPIO.output(LIGHT,GPIO.HIGH) 66 | time.sleep(5) 67 | GPIO.output(LIGHT,GPIO.LOW) 68 | time.sleep(5) 69 | 70 | if H != '07': 71 | 72 | Irritation_flag = 1 -------------------------------------------------------------------------------- /Chapter12/12.1.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | GPIO.setmode(GPIO.BCM) 4 | GPIO.setwarnings(False) 5 | PIR = 24 6 | LIGHT = 23 7 | GPIO.setup(DOPPLER,GPIO.IN) 8 | GPIO.setup(BUZZER,GPIO.OUT) 9 | While True: 10 | if GPIO.input(PIR) == 1: 11 | GPIO.output(LIGHT,GPIO.HIGH) 12 | if GPIO.input(PIR) == 0: 13 | GPIO.output(LIGHT,GPIO.LOW) -------------------------------------------------------------------------------- /Chapter12/12.2.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | 4 | GPIO.setmode(GPIO.BCM) 5 | GPIO.setwarnings(False) 6 | 7 | PIR = 24 8 | LIGHT = 23 9 | TIME = 5 10 | 11 | GPIO.setup(PIR,GPIO.IN) 12 | GPIO.setup(BUZZER,GPIO.OUT) 13 | 14 | While True: 15 | 16 | If GPIO.input(PIR) == 1: 17 | 18 | M = datetime.datetime.now().strftime('%M') 19 | M_final= M + TIME 20 | 21 | for M < M_final: 22 | 23 | GPIO.output(LIGHT,GPIO.HIGH) 24 | M = datetime.datetime.now().strftime('%M') 25 | 26 | if GPIO.input(PIR) == 1: 27 | M_final = M_final + 1 28 | 29 | 30 | if GPIO.input(PIR) = 0: 31 | 32 | GPIO.output(LIGHT, GPIO.LOW)} -------------------------------------------------------------------------------- /Chapter12/12.3.py: -------------------------------------------------------------------------------- 1 | import GPIO library 2 | import RPi.GPIO as GPIO 3 | import time 4 | 5 | import Adafruit_ADS1x15 6 | adc0 = Adafruit_ADS1x15.ADS1115() 7 | 8 | GAIN = 1 9 | LIGHT = 23 10 | 11 | adc0.start_adc(0, gain=GAIN) 12 | adc1.start_adc(1, gain=GAIN) 13 | 14 | GPIO.setmode(GPIO.BCM) 15 | GPIO.setwarnings(False) 16 | 17 | 18 | while True: 19 | 20 | 21 | F_value = adc0.get_last_result() 22 | F1 = (1.0 / (F_value / 13.15)) - 0.35 23 | 24 | time.sleep(0.1) 25 | 26 | F_value = adc0.get_last_result() 27 | F2 = (1.0 / (F_value / 13.15)) - 0.35 28 | 29 | F0_final = F1-F2 30 | 31 | if F0 > 10 : 32 | 33 | Time0 = time.time() 34 | 35 | 36 | 37 | F_value = adc1.get_last_result() 38 | F1 = (1.0 / (F_value / 13.15)) - 0.35 39 | 40 | time.sleep(0.1) 41 | 42 | F_value = adc1.get_last_result() 43 | F2 = (1.0 / (F_value / 13.15)) - 0.35 44 | 45 | F1_final = F1-F2 46 | 47 | if F1 > 10: 48 | 49 | Time1 = time.time() 50 | 51 | 52 | if Time1 > Time0: 53 | 54 | GPIO.output(LIGHT, GPIO.HIGH) 55 | 56 | 57 | if Time1 < Time0: 58 | 59 | GPIO.output(LIGHT, GPIO.LOW) } -------------------------------------------------------------------------------- /Chapter12/12.4.py: -------------------------------------------------------------------------------- 1 | import GPIO library 2 | import RPi.GPIO as GPIO 3 | import time 4 | import time 5 | import Adafruit_ADS1x15 6 | adc0 = Adafruit_ADS1x15.ADS1115() 7 | GAIN = 1 8 | adc0.start_adc(0, gain=GAIN) 9 | adc1.start_adc(1, gain=GAIN) 10 | GPIO.setmode(GPIO.BCM) 11 | GPIO.setwarnings(False) 12 | PCount = 0 13 | while True: 14 | F_value = adc0.get_last_result() 15 | F1 = (1.0 / (F_value / 13.15)) - 0.35 16 | time.sleep(0.1) 17 | F_value = adc0.get_last_result() 18 | F2 = (1.0 / (F_value / 13.15)) - 0.35 19 | F0_final = F1-F2 20 | if F0 > 10 : 21 | Time0 = time.time() 22 | F_value = adc1.get_last_result() 23 | F1 = (1.0 / (F_value / 13.15)) - 0.35 24 | time.sleep(0.1) 25 | F_value = adc1.get_last_result() 26 | F2 = (1.0 / (F_value / 13.15)) - 0.35 27 | F1_final = F1-F2 28 | if F1 > 10: 29 | Time1 = time.time() 30 | if Time1 > Time0: 31 | PCount = PCount + 1 32 | if Time1 < Time0: 33 | PCount = PCount - 1 34 | 35 | if PCount > 0: 36 | 37 | GPIO.output(LIGHT, GPIO.HIGH) 38 | else if PCount = 0: 39 | GPIO.output(LIGHT, GPIO.LOW) 40 | -------------------------------------------------------------------------------- /Chapter12/12.5.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | GPIO.setmode(GPIO.BCM) 4 | GPIO.setup(18,GPIO.OUT) 5 | I = 0 6 | pwm= GPIO.PWM(18,50) 7 | 8 | for I < 100: 9 | 10 | I = I+1 11 | pwm.start(I) 12 | time.sleep(0.1) 13 | 14 | 15 | GPIO.cleanup()} -------------------------------------------------------------------------------- /Chapter12/12.6.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | import Adafruit_DHT 4 | 5 | GPIO.setmode(GPIO.BCM) 6 | 7 | FAN = 18 8 | AC = 17 9 | 10 | pwm= GPIO.PWM(18,50) 11 | GPIO.setup(FAN,GPIO.OUT) 12 | GPIO.setup(AC, GPIO.OUT) 13 | 14 | while True: 15 | 16 | humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) 17 | 18 | if temperature =>20 && temperature <=30: 19 | 20 | Duty = 50 + ((temprature-25)*10) 21 | pwm.start(Duty) 22 | 23 | if temperature <22 : 24 | 25 | GPIO.output(AC, GPIO.LOW) 26 | 27 | if temperature >= 24 28 | 29 | GPIO.output(AC, GPIO.HIGH)} -------------------------------------------------------------------------------- /Chapter12/12.7.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | import Adafruit_DHT 4 | 5 | GPIO.setmode(GPIO.BCM) 6 | 7 | FAN = 18 8 | AC = 17 9 | PIR = 22 10 | PIN = 11 11 | Sensor = 4 12 | 13 | pwm= GPIO.PWM(18,50) 14 | GPIO.setup(FAN,GPIO.OUT) 15 | GPIO.setup(AC, GPIO.OUT) 16 | 17 | while True: 18 | 19 | humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) 20 | H = datetime.datetime.now().strftime('%H') 21 | M = datetime.datetime.now().strftime('%M') 22 | 23 | if H <= 6 && H <= 22: 24 | 25 | if M <=58 : 26 | 27 | M = datetime.datetime.now().strftime('%M') 28 | humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) 29 | 30 | if GPIO.input(PIR) == 0 : 31 | 32 | Movement = Movement + 1 33 | time.sleep(10) 34 | 35 | if temperature < 28: 36 | 37 | if Movement > 5 : 38 | 39 | Duty = Duty + 10 40 | pwm.start(Duty) 41 | Movement = 0 42 | 43 | if M = 59 : 44 | 45 | if Movement = 0 : 46 | 47 | Duty = Duty -10 48 | pwm.start(Duty) 49 | 50 | Movement = 0 51 | 52 | if temperature <22 : 53 | 54 | GPIO.output(AC, GPIO.LOW) 55 | 56 | if temperature >= 24 && H <= 6 && H >= 22: 57 | 58 | GPIO.output(AC, GPIO.HIGH) 59 | 60 | if temperature > 27 61 | 62 | pwm.start(100) 63 | 64 | for H > 7 && H < 20 65 | 66 | GPIO.output(AC, GPIO.LOW) 67 | 68 | if H = 20 69 | 70 | GPIO.output(AC,GPIO.HIGH) 71 | } -------------------------------------------------------------------------------- /Chapter12/12.8.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | 4 | GPIO.setmode(GPIO.BCM) 5 | GPIO.setwarnings(False) 6 | 7 | S0 = 21 8 | S1 = 22 9 | S2 = 23 10 | S3 = 24 11 | 12 | GPIO.setup(S0,GPIO.OUT) 13 | GPIO.setup(S1,GPIO.OUT) 14 | GPIO.setup(S2,GPIO.OUT) 15 | 16 | While True: 17 | 18 | GPIO.output(S0,1) 19 | GPIO.output(S1,0) 20 | GPIO.output(S2,1) 21 | GPIO.output(S4,1) 22 | 23 | time.sleep(1) 24 | 25 | GPIO.output(S0,1) 26 | GPIO.output(S1,1) 27 | GPIO.output(S2,1) 28 | GPIO.output(S4,1) 29 | 30 | time.sleep(1) 31 | 32 | GPIO.output(S0,1) 33 | GPIO.output(S1,0) 34 | GPIO.output(S2,0) 35 | GPIO.output(S4,1) 36 | 37 | time.sleep(1) 38 | 39 | 'GPIO.output(S0,0) 40 | GPIO.output(S1,0) 41 | GPIO.output(S2,0) 42 | GPIO.output(S4,1) 43 | 44 | time.sleep(1) 45 | 46 | GPIO.output(S0,0) 47 | GPIO.output(S1,1) 48 | GPIO.output(S2,0) 49 | GPIO.output(S4,1) 50 | 51 | time.sleep(1) } -------------------------------------------------------------------------------- /Chapter13/13_1.py: -------------------------------------------------------------------------------- 1 | import time 2 | import paho.mqtt.client as mqtt 3 | import RPi.gpio as gpio 4 | pir = 23 5 | gpio.setmode(gpio.BCM) 6 | gpio.setup(pir, gpio.IN) 7 | client = mqtt.Client() 8 | broker="broker.hivemq.com" 9 | port = 1883 10 | pub_topic = "IntruderDetector_Home" 11 | def SendData(): 12 | client.publish(pub_topic,"WARNING : SOMEONE DETECTED AT YOUR PLACE") 13 | 14 | def on_connect(client, userdata, flag,rc): 15 | print("connection returned" + str(rc)) 16 | SendData() 17 | while True: 18 | client.connect(broker,port) 19 | client.on_connect = on_connect 20 | if gpio.output(pir) == gpio.HIGH : 21 | SendData() 22 | client.loop_forever() 23 | -------------------------------------------------------------------------------- /Chapter13/13_2.py: -------------------------------------------------------------------------------- 1 | import time 2 | import paho.mqtt.client as paho 3 | import RPi.GPIO as GPIO 4 | GPIO.setmode(GPIO.BCM) 5 | GPIO.setup(14,GPIO.OUT) 6 | broker="broker.hivemq.com" 7 | sub_topic = light/control 8 | client = paho.Client() 9 | def on_message(client, userdata, message): 10 | print('message is : ') 11 | print(str(message.payload)) 12 | data = str(message.payload) 13 | if data == "on": 14 | GPIO.output(3,GPIO.HIGH) 15 | elif data == "off": 16 | GPIO.output(3,GPIO.LOW) 17 | 18 | def on_connect(client,userdata, flag, rc): 19 | print("connection returned" + str(rc)) 20 | client.subscribe(sub_topic) 21 | client.connect(broker,port) 22 | client.on_connect = on_connect 23 | client.on_message=on_message 24 | client.loop_forever() -------------------------------------------------------------------------------- /Chapter14/14_1.py: -------------------------------------------------------------------------------- 1 | import os 2 | from time import sleep 3 | os.system('echo "hello! i am raspberry pi robot"|festival --tts ') 4 | sleep(2) 5 | os.system('echo "how are you?"| festival --tts ') 6 | sleep(2) 7 | os.system('echo "I am having fun."| festival --tts ') 8 | sleep(2) -------------------------------------------------------------------------------- /Chapter14/14_2.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | Import os 4 | GPIO.setmode(GPIO.BCM) 5 | PIR = 13 6 | GPIO.setup(PIR,GPIO.IN) 7 | while True: 8 | 9 | if GPIO.input(PIR) == 1 : 10 | os.system('echo "Hello, welcome to my house"|festival --tts ') 11 | time.sleep(0.2) 12 | os.system('echo "If you are a delivery agent then please leave the package here"|festival --tts ') 13 | time.sleep(0.2) 14 | os.system('echo "If you are a guest then I'm sorry I have to leave I will be back after 7pm"|festival --tts ') 15 | time.sleep(0.2) 16 | os.system('echo "also Kindly don't step over the grass, its freshly grown and needs some time"|festival --tts ') 17 | time.sleep(1) 18 | os.system('echo "Thank you !"|festival --tts ') -------------------------------------------------------------------------------- /Chapter14/14_3.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | import os 4 | GPIO.setmode(GPIO.BCM) 5 | LIGHT = 2 6 | GPIO.setup(LIGHT,GPIO.OUT) 7 | GPIO.output(LIGHT, GPIO.HIGH) 8 | os.system('echo "LIGHTS TURNED ON "|festival --tts') -------------------------------------------------------------------------------- /Chapter14/14_4.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | import os 4 | GPIO.setmode(GPIO.BCM) 5 | LIGHT = 23 6 | GPIO.setup(LIGHT,GPIO.OUT) 7 | GPIO.output(LIGHT, GPIO.LOW) 8 | os.system('echo "LIGHTS TURNED OFF "|festival --tts') -------------------------------------------------------------------------------- /Chapter14/14_5.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | Import os 4 | GPIO.setmode(GPIO.BCM) 5 | FAN = 22 6 | GPIO.setup(FAN,GPIO.OUT) 7 | GPIO.output(LIGHT, GPIO.HIGH) 8 | os.system('echo "FAN TURNED ON "|festival --tts') 9 | -------------------------------------------------------------------------------- /Chapter14/14_6.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | Import os 4 | GPIO.setmode(GPIO.BCM) 5 | FAN = 22 6 | GPIO.setup(FAN,GPIO.OUT) 7 | GPIO.output(LIGHT, GPIO.LOW) 8 | os.system('echo "FAN TURNED OFF "|festival --tts') -------------------------------------------------------------------------------- /Chapter15/15_1.py: -------------------------------------------------------------------------------- 1 | import signal 2 | import flicklib 3 | import time 4 | def message(value): 5 | print value 6 | @flicklib.move() 7 | def move(x, y, z): 8 | global xyztxt 9 | xyztxt = '{:5.3f} {:5.3f} {:5.3f}'.format(x,y,z) 10 | @flicklib.flick() 11 | def flick(start,finish): 12 | global flicktxt 13 | flicktxt = 'FLICK-' + start[0].upper() + finish[0].upper() 14 | message(flicktxt) 15 | def main(): 16 | global xyztxt 17 | global flicktxt 18 | xyztxt = '' 19 | flicktxt = '' 20 | flickcount = 0 21 | while True: 22 | 23 | xyztxt = '' 24 | if len(flicktxt) > 0 and flickcount < 5: 25 | flickcount += 1 26 | else: 27 | flicktxt = '' 28 | flickcount = 0 29 | main() -------------------------------------------------------------------------------- /Chapter15/15_2.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Robotics-Projects/17221304cb3e15e486af855b442927f64fdcc738/Chapter15/15_2.py -------------------------------------------------------------------------------- /Chapter16/16.1.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import pandas as pd 3 | from sklearn.neighbors import KNeighborsClassifier 4 | 5 | knn = KNeighborsClassifier(n_neighbors=5) 6 | data = pd.read_csv('dataset.csv') 7 | 8 | x = np.array(data[['Time', 'Temp']]) 9 | y = np.array(data[['State']]).ravel() 10 | 11 | knn.fit(x,y) 12 | 13 | time = raw_input("Enter time") 14 | temp = raw_input("Enter temp") 15 | 16 | data =. [] 17 | 18 | data.append(float(time)) 19 | data.append(float(temp)) 20 | 21 | a = knn.predict([data]) 22 | 23 | print(a[0])} -------------------------------------------------------------------------------- /Chapter17/17_1.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Robotics-Projects/17221304cb3e15e486af855b442927f64fdcc738/Chapter17/17_1.py -------------------------------------------------------------------------------- /Chapter17/17_2.py: -------------------------------------------------------------------------------- 1 | import smbus 2 | from time import sleep 3 | import RPi.GPIO as GPIO 4 | int1 = 12 5 | int2 = 16 6 | int3 = 18 7 | int4 = 15 8 | GPIO.setup(int1, GPIO.OUT) 9 | GPIO.setup(int2, GPIO.OUT) 10 | GPIO.setup(int3, GPIO.OUT) 11 | GPIO.setup(int4, GPIO.OUT) 12 | PWM1 = GPIO.PWM(12, 100) 13 | PWM2 = GPIO.PWM(16, 100) 14 | PWM3 = GPIO.PWM(18, 100) 15 | PWM4 = GPIO.PWM(15, 100) 16 | PWM1.start(0) 17 | PWM2.start(0) 18 | PWM3.start(0) 19 | PWM4.start(0) 20 | PWR_MGMT_1 = 0x6B 21 | SMPLRT_DIV = 0x19 22 | CONFIG = 0x1A 23 | GYRO_CONFIG = 0x1B 24 | INT_ENABLE = 0x38 25 | ACCEL_XOUT_H = 0x3B 26 | ACCEL_YOUT_H = 0x3D 27 | ACCEL_ZOUT_H = 0x3F 28 | GYRO_XOUT_H = 0x43 29 | GYRO_YOUT_H = 0x45 30 | GYRO_ZOUT_H = 0x47 31 | 32 | def MPU_Init(): 33 | bus.write_byte_data(Device_Address, SMPLRT_DIV, 7) 34 | bus.write_byte_data(Device_Address, PWR_MGMT_1, 1) 35 | bus.write_byte_data(Device_Address, CONFIG, 0) 36 | bus.write_byte_data(Device_Address, GYRO_CONFIG, 24) 37 | bus.write_byte_data(Device_Address, INT_ENABLE, 1) 38 | 39 | def read_raw_data(addr): 40 | high = bus.read_byte_data(Device_Address, addr) 41 | low = bus.read_byte_data(Device_Address, addr+1) 42 | value = ((high << 8) | low) 43 | if(value > 32768): 44 | value = value - 65536 45 | return value 46 | bus = smbus.SMBus(1) 47 | Device_Address = 0x68 48 | 49 | MPU_Init() 50 | while True: 51 | acc_x = read_raw_data(ACCEL_XOUT_H) 52 | acc_y = read_raw_data(ACCEL_YOUT_H) 53 | acc_z = read_raw_data(ACCEL_ZOUT_H) 54 | gyro_x = read_raw_data(GYRO_XOUT_H) 55 | gyro_y = read_raw_data(GYRO_YOUT_H) 56 | gyro_z = read_raw_data(GYRO_ZOUT_H) 57 | Ax = (gyro_x/327) 58 | Ay = (gyro_y/327) 59 | for Ax > 20: 60 | PWM1.changeDutyCycle(Ax) 61 | PWM3.changeDutyCycle(Ax) 62 | for Ax < -20: 63 | PWM2.changeDutyCycle(Ax) 64 | PWM4.changeDutyCycle(Ax) 65 | 66 | for Ay > 20: 67 | PWM1.changeDutyCycle(Ax) 68 | PWM4.changeDutyCycle(Ax) 69 | for Ay < -20: 70 | PWM2.changeDutyCycle(Ax) 71 | PWM3.changeDutyCycle(Ax) 72 | -------------------------------------------------------------------------------- /Chapter17/17_3.py: -------------------------------------------------------------------------------- 1 | import smbus 2 | from time import sleep 3 | import RPi.GPIO as GPIO 4 | int1 = 12 5 | int2 = 16 6 | int3 = 18 7 | int4 = 15 8 | GPIO.setup(int1, GPIO.OUT) 9 | GPIO.setup(int2, GPIO.OUT) 10 | GPIO.setup(int3, GPIO.OUT) 11 | GPIO.setup(int4, GPIO.OUT) 12 | PWM1 = GPIO.PWM(12, 100) 13 | PWM2 = GPIO.PWM(16, 100) 14 | PWM3 = GPIO.PWM(18, 100) 15 | PWM4 = GPIO.PWM(15, 100) 16 | PWM1.start(0) 17 | PWM2.start(0) 18 | PWM3.start(0) 19 | PWM4.start(0) 20 | PWR_MGMT_1 = 0x6B 21 | SMPLRT_DIV = 0x19 22 | CONFIG = 0x1A 23 | GYRO_CONFIG = 0x1B 24 | INT_ENABLE = 0x38 25 | ACCEL_XOUT_H = 0x3B 26 | ACCEL_YOUT_H = 0x3D 27 | ACCEL_ZOUT_H = 0x3F 28 | GYRO_XOUT_H = 0x43 29 | GYRO_YOUT_H = 0x45 30 | GYRO_ZOUT_H = 0x47 31 | 32 | def MPU_Init(): 33 | bus.write_byte_data(Device_Address, SMPLRT_DIV, 7) 34 | bus.write_byte_data(Device_Address, PWR_MGMT_1, 1) 35 | bus.write_byte_data(Device_Address, CONFIG, 0) 36 | bus.write_byte_data(Device_Address, GYRO_CONFIG, 24) 37 | bus.write_byte_data(Device_Address, INT_ENABLE, 1) 38 | def read_raw_data(addr): 39 | high = bus.read_byte_data(Device_Address, addr) 40 | low = bus.read_byte_data(Device_Address, addr+1) 41 | value = ((high << 8) | low) 42 | if(value > 32768): 43 | value = value - 65536 44 | return value 45 | bus = smbus.SMBus(1) 46 | Device_Address = 0x68 47 | MPU_Init() 48 | while True: 49 | acc_x = read_raw_data(ACCEL_XOUT_H) 50 | acc_y = read_raw_data(ACCEL_YOUT_H) 51 | acc_z = read_raw_data(ACCEL_ZOUT_H) 52 | gyro_x = read_raw_data(GYRO_XOUT_H) 53 | gyro_y = read_raw_data(GYRO_YOUT_H) 54 | gyro_z = read_raw_data(GYRO_ZOUT_H) 55 | Ax = (gyro_x/160)- 16384 56 | Ay = (gyro_y/160)-16384 57 | if Ax > 20: 58 | if Ay > 20: 59 | dc1 = Ax - Ay 60 | PWM1.changeDutyCycle(dc1) 61 | dc3 = Ax + Ay 62 | PWM3.changeDutyCycle(dc3) 63 | elif Ay <- 20: 64 | dc2 = Ax + Ay 65 | PWM1.changeDutyCycle(dc) 66 | dc4 = Ax - Ay 67 | PWM3.changeDutyCycle(dc4) 68 | else: 69 | dc1=Ax 70 | PWM1.changeDutyCycle(dc) 71 | dc3=Ax 72 | PWM3.changeDutyCycle(dc) 73 | if Ax < -20: 74 | if Ay > 20: 75 | dc1 = Ax - Ay 76 | dc3 = Ax + Ay 77 | PWM1.changeDutyCycle(dc1) 78 | PWM3.changeDutyCycle(dc3) 79 | if Ay <- 20: 80 | dc2 = Ax + Ay 81 | dc4 = Ax - Ay 82 | PWM2.changeDutyCycle(dc2) 83 | PWM4.changeDutyCycle(dc4) 84 | else: 85 | dc2=Ax 86 | dc4=Ax 87 | PWM2.changeDutyCycle(dc2) 88 | PWM4.changeDutyCycle(dc4) -------------------------------------------------------------------------------- /Chapter18/18.1.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | 4 | GPIO.setmode(GPIO.BCM) 5 | GPIO.setup(14,GPIO.OUT) 6 | GPIO.setup(16,GPIO.OUT) 7 | GPIO.setup(18,GPIO.OUT) 8 | GPIO.setup(20,GPIO.OUT) 9 | GPIO.setup(21,GPIO.OUT) 10 | GPIO.setup(22,GPIO.OUT) 11 | 12 | 13 | GPIO.setwarnings(False) 14 | 15 | pwm1 = GPIO.PWM(14, 50) 16 | pwm2 = GPIO.PWM(16, 50) 17 | pwm3 = GPIO.PWM(18, 50) 18 | pwm4 = GPIO.PWM(20, 50) 19 | pwm5 = GPIO.PWM(21, 50) 20 | pwm6 = GPIO.PWM(22, 50) 21 | 22 | pwm1.start(0) 23 | pwm2.start(0) 24 | pwm3.start(0) 25 | pwm4.start(0) 26 | pwm5.start(0) 27 | pwm6.start(0) 28 | 29 | def cvt_angle(angle): 30 | dc = float(angle/90) + 0.5 31 | return dc 32 | 33 | while 1: 34 | 35 | j = input('select servo') 36 | 37 | if j == 1: 38 | 39 | i = input('select value to rotate') 40 | pwm1.ChangeDutyCycle(cvt_angle(i)) 41 | time.sleep(2) 42 | pwm1.ChangeDutyCycle(cvt_angle(90)) 43 | 44 | elif j ==2: 45 | 46 | i = input('select value to rotate') 47 | pwm2.ChangeDutyCycle(cvt_angle(i)) 48 | time.sleep(2) 49 | pwm2.ChangeDutyCycle(cvt_angle(90)) 50 | 51 | 52 | elif j ==3: 53 | 54 | i = input('select value to rotate') 55 | pwm3.ChangeDutyCycle(cvt_angle(i)) 56 | time.sleep(2) 57 | pwm3.ChangeDutyCycle(cvt_angle(90)) 58 | 59 | elif j ==4: 60 | 61 | i = input('select value to rotate') 62 | pwm4.ChangeDutyCycle(cvt_angle(i)) 63 | time.sleep(2) 64 | pwm4.ChangeDutyCycle(cvt_angle(90)) 65 | 66 | elif j ==5: 67 | 68 | i = input('select value to rotate') 69 | pwm5.ChangeDutyCycle(cvt_angle(i)) 70 | time.sleep(2) 71 | pwm5.ChangeDutyCycle(cvt_angle(90)) 72 | 73 | elif j ==6: 74 | 75 | i = input('select value to rotate') 76 | pwm6.ChangeDutyCycle(cvt_angle(i)) 77 | time.sleep(2) 78 | pwm6.ChangeDutyCycle(cvt_angle(90)) } -------------------------------------------------------------------------------- /Chapter18/18.2.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | import time 3 | 4 | GPIO.setmode(GPIO.BCM) 5 | GPIO.setup(14,GPIO.OUT) 6 | GPIO.setup(16,GPIO.OUT) 7 | GPIO.setup(18,GPIO.OUT) 8 | GPIO.setup(20,GPIO.OUT) 9 | GPIO.setup(21,GPIO.OUT) 10 | GPIO.setup(22,GPIO.OUT) 11 | 12 | 13 | GPIO.setwarnings(False) 14 | 15 | pwm1 = GPIO.PWM(14, 50) 16 | pwm2 = GPIO.PWM(16, 50) 17 | pwm3 = GPIO.PWM(18, 50) 18 | pwm4 = GPIO.PWM(20, 50) 19 | pwm5 = GPIO.PWM(21, 50) 20 | pwm6 = GPIO.PWM(22, 50) 21 | 22 | pwm1.start(cvt_angle(90)) 23 | pwm2.start(cvt_angle(90)) 24 | pwm3.start(cvt_angle(90)) 25 | pwm4.start(cvt_angle(90)) 26 | pwm5.start(cvt_angle(90)) 27 | pwm6.start(cvt_angle(90)) 28 | 29 | def cvt_angle(angle): 30 | dc = float(angle/90) + 0.5 31 | return dc 32 | 33 | while True: 34 | 35 | a = raw_input("enter a list of 6 values") 36 | 37 | if a[0] < 160 and a[0] > 30: 38 | pwm1.ChangeDutyCycle(cvt_angle(a[0])) 39 | 40 | if a[1] < 160 and a[1] > 30: 41 | pwm2.ChangeDutyCycle(cvt)angle(a[1])) 42 | 43 | if a[0] < 160 and a[0] > 30: 44 | pwm3.ChangeDutyCycle(cvt_angle(a[2])) 45 | 46 | if a[0] < 160 and a[0] > 30: 47 | pwm4.ChangeDutyCycle(cvt_angle(a[3])) 48 | 49 | if a[0] < 160 and a[0] > 30: 50 | pwm5.ChangeDutyCycle(cvt_angle(a[4])) 51 | 52 | if a[0] < 160 and a[0] > 30: 53 | pwm6.ChangeDutyCycle(cvt_angle(a[5]))} -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # Python Robotics Projects 5 | This is the code repository for [Python Robotics Projects](https://www.packtpub.com/hardware-and-creative/python-robotics-projects?utm_source=github&utm_medium=repository&utm_campaign=9781788832922), published by [Packt](https://www.packtpub.com/?utm_source=github). It contains all the supporting project files necessary to work through the book from start to finish. 6 | ## About the Book 7 | Robotics is a fast-growing industry. Multiple surveys state that investment in the field has increased tenfold in the last 6 years, and is set to become a $100-billion sector by 2020. Robots are prevalent throughout all industries, and they are all set to be a part of our domestic lives. This book starts with the installation and basic steps in configuring a robotic controller. You'll then move on to setting up your environment to use Python with the robotic controller. You'll dive deep into building simple robotic projects, such as a pet-feeding robot, and more complicated projects, such as machine learning enabled home automation system (Jarvis), vision processing based robots and a self-driven robotic vehicle using Python. 8 | 9 | 10 | ## Instructions and Navigation 11 | All of the code is organized into folders. For example, Chapter02. 12 | 13 | 14 | 15 | The code will look like the following: 16 | ``` 17 | for i in range(3): 18 | GPIO.output(23, GPIO.HIGH) 19 | sleep(.5) 20 | GPIO.output(23, GPIO.LOW) 21 | sleep(.5) 22 | sleep(1) 23 | ``` 24 | 25 | This book is for those who have a will to learn robotics and get familiar with the latest technology using the latest programming language. Age is no limit whether you are 12 years young or 60 years old; you can read this book and convert your ideas into reality. 26 | 27 | ## Related Products 28 | * [Raspberry Pi Robotic Projects - Third Edition](https://www.packtpub.com/hardware-and-creative/raspberry-pi-robotic-projects-third-edition?utm_source=github&utm_medium=repository&utm_campaign=9781786467966) 29 | 30 | * [Mastering ROS for Robotics Programming - Second Edition](https://www.packtpub.com/hardware-and-creative/mastering-ros-robotics-programming-second-edition?utm_source=github&utm_medium=repository&utm_campaign=9781788478953) 31 | 32 | * [Data Visualization Projects in Python [Video]](https://www.packtpub.com/virtualization-and-cloud/data-visualization-projects-python-video?utm_source=github&utm_medium=repository&utm_campaign=9781788830416) 33 | ### Download a free PDF 34 | 35 | If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.
36 |

https://packt.link/free-ebook/9781788832922

--------------------------------------------------------------------------------