From cb5dc8f5816da12203897a8c63f9f821dd321f41 Mon Sep 17 00:00:00 2001 From: Evangelos Oulis Date: Fri, 17 Jan 2020 13:11:00 +0200 Subject: [PATCH 1/3] Update v1.3 --- project.adoc | 4 +++- serverNode/serv.py | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/project.adoc b/project.adoc index 8ca0426..602cf21 100644 --- a/project.adoc +++ b/project.adoc @@ -162,7 +162,9 @@ image::Photos/itops-pizza_as_a_service.png[1000,800] == Διεπαφή Χρήστη (4~ο~ μέρος) -Η διεπαφή του χρήσρη π +Η διεπαφή του χρήστη αποτελείται από μία HTML σελίδα η οποία ενσωματώνει και δύο JavaScript Processes. +Σκοπός αυτής είναι η ανααπαράσταση της κατάστασης του Parking. Η σελίδα λοιπόν ενσωματώνει για κάθε θέση +parking == Autonomous Parking diff --git a/serverNode/serv.py b/serverNode/serv.py index 778f532..2668b93 100644 --- a/serverNode/serv.py +++ b/serverNode/serv.py @@ -33,13 +33,16 @@ myCursor = mydb.cursor() # Define a function that gets the parking status # for all parking codes. def getParkings(): - parks = dict() + parks = [] myCursor.execute("SELECT * FROM PARKING") myRes = myCursor.fetchall() for res in myRes: - parks[res[0]] = res[1] + if res[1] == 1: + parks.append({"no": res[0], "status": True}) + else: + parks.append({"no": res[0], "status": False}) return parks # ================================================================== @@ -65,18 +68,26 @@ class ParkingStatus(Resource): # SQL get all Parking places status. parks = getParkings() + currentParking = {} + for park in parks: + if park['no'] == data['no']: + currentParking = park + break; + thereIs = False toUpdate = False try: - if parks[int(data['no'])] != int(data['status']): + if currentParking['status'] != data['status']: toUpdate = True thereIs = True except IndexError: # handle Index Error thereIs = False + toUpdate = False except KeyError: # handle the KeyError thereIs = False + toUpdate = False if not thereIs: # Make a new insert entry for a new Parking Code. @@ -91,7 +102,7 @@ class ParkingStatus(Resource): mydb.commit() parks = getParkings() - return parks[data['no']], 201 + return currentParking, 201 # ================================================================== From dca3cc120b0b1315c7f361548c934a80789f81d5 Mon Sep 17 00:00:00 2001 From: Evangelos Oulis Date: Fri, 17 Jan 2020 13:25:09 +0200 Subject: [PATCH 2/3] Update v1.3 --- autonomousCarGateway/carClient.py | 44 +++++++++++++++---------------- project.adoc | 4 +-- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/autonomousCarGateway/carClient.py b/autonomousCarGateway/carClient.py index 2147afc..6f20203 100644 --- a/autonomousCarGateway/carClient.py +++ b/autonomousCarGateway/carClient.py @@ -11,28 +11,28 @@ server_port = "443" API_ENDPOINT = 'https://' + server_ip + ':' + server_port + '/' try: - ser = serial.Serial( - port='/dev/ttyACM0', - baudrate = 9600, - parity=serial.PARITY_NONE, - stopbits=serial.STOPBITS_ONE, - bytesize=serial.EIGHTBITS, - timeout=1 - ) - - c = requests.get(url=API_ENDPOINT, params = {}) - doc = c.json() +# ser = serial.Serial( +# port='/dev/ttyACM0', +# baudrate = 9600, +# parity=serial.PARITY_NONE, +# stopbits=serial.STOPBITS_ONE, +# bytesize=serial.EIGHTBITS, +# timeout=1 +# ) + + c = requests.get(url=API_ENDPOINT, params = {}) + doc = c.json() - parking = None - for park in doc: - if doc[str(park)] == 1: - parking = park - break - - print ("Free parking is Number: " + parking) - ser.write("b'" + parking + "'") - ser.flush() + parking = None + for park in doc: + if park['status'] == True: + parking = park #{"no": park['no'], "status": park['status']} + break + + print ("Free parking is Number: " + str(parking['no'])) +# ser.write("b'" + parking['no'] + "'") +# ser.flush() except (NameError, TypeError) as e: - print ("No free parking") + print ("No free parking") except requests.exceptions.ConnectionError: - print("No Internet access") + print("No Internet access") diff --git a/project.adoc b/project.adoc index 2e7b6d6..602cf21 100644 --- a/project.adoc +++ b/project.adoc @@ -195,8 +195,8 @@ parking * 1 x Raspberry Pi ==== Υλοποίηση και Προγραμματισμός -Ο motor driver, το Servo motor καθώς και ο Ultrasonic αισθητήρας συνδέονται στον μικροελεγκτή Arduino Uno που χρησιμοποιούμε, -τον οποίο τον εγκαθηστούμε πάνω στο καλούπι του οχήματος το οποίο έχει εγκατεστημένα 4 τροχούς. Οι τροχοί οδηγούνται από 4 moters +Ο motor driver, το Servo motor καθώς και ο Ultrasonic αισθητήρας κουμπώνουν στον μικροελεγκτή Arduino Uno που χρησιμοποιούμε, +τον οποίο τον εγκαθηστούμε πάνω στο καλούπι του οχήματος το οποίο έχει εγκατεστημένα 4 τροχούς. Οι τροχοί οδηοούνται από 4 moters τα οποία τροφοδοτούνται από τον motor driver. Η συνδεσμολογία έχει την διάταξη που παρουσιάζεται παρακάτω: From a4925739363f066457a17d4c039bbe93c0311576 Mon Sep 17 00:00:00 2001 From: Evangelos Oulis Date: Sat, 18 Jan 2020 11:30:16 +0200 Subject: [PATCH 3/3] Update v1.2 --- autonomousCar/autonomousCar.ino | 69 +++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/autonomousCar/autonomousCar.ino b/autonomousCar/autonomousCar.ino index 23de2eb..1b67a78 100644 --- a/autonomousCar/autonomousCar.ino +++ b/autonomousCar/autonomousCar.ino @@ -255,37 +255,56 @@ void moveCar(){ } } -void park() { - turnRight(255); +void park(int parkingNo) { + int row = (parkingNo / 2) + 1; + int side = (parking % 2) //If side is 1 then the parking is to right + // else if is 0 the parking is to left. + + while (row > 0) { + absolute(255); + forward(); + delay(FORWARD_STEP); + motor_stop(); + + r--; + } + + //Check the side value to turn. + if (side == 1) { + turnRight(255); + else { + turnLeft(255); + } forward(); delay(TURN_TIME); - absolute(255); motor_stop(); + + absolute(255); forward(); delay(400); } - String inString; - void Serial_Input() - { - - while (Serial.available() > 0) { - int inChar = Serial.read(); - if (isDigit(inChar)) { - // convert the incoming byte to a char and add it to the string: - inString += (char)inChar; - } - // if you get a newline, print the string, then the string's value: - if (inChar == '\n') { - Serial.print("Value:"); - Serial.println(inString.toInt()); - Serial.print("String: "); - Serial.println(inString); - // clear the string for new input: - inString = ""; + + +int Serial_Input() +{ + int number; + if (Serial.available() > 0) { + number = Serial.parseInt(); + while (number <= 0) { + // convert the incoming byte to a char and add it to the string: + number = Serial.parseInt(); + } + + // if you get a newline, print the string, then the string's value: + + Serial.print("Value:"); + Serial.println(number); + // clear the string for new input: } - } - } + + return number; +} void loop() { // Calculating the distance @@ -295,8 +314,8 @@ void loop() { //Serial.print("Distance: "); //Serial.println(distance); // Read serial input: - Serial_Input(); - park(); + + park(Serial_Input()); //delay(1000); // if (distance <15) { // // Change direction to motors