-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSPC_AIPlanner.py
150 lines (117 loc) · 4.45 KB
/
SPC_AIPlanner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
"""
Project: Smart Park Capsule
Course: Smart City and IOT
Institute: Service Computing Department, IAAS, University of Stuttgart
---------------- Team Members -----------
Sl.No | Names
1 | Swathi Shridhar
2 | Badruddin Mukadam
3 | Suraj Sakpal
4 | Anish Krishna Navalgund
-----------------------------------------
File Description: SPC_AIPlanner.py is the main file to perform AI-Planning. The code will generate
the plan dynamically as the per the input sensor data.
Timestamp: 10th July 2022
"""
# Import required python packages
from ast import Global
import os
import time
import datetime as dt
from tkinter import DISABLED
from unittest import result
from SPC_GUI import led_pg, led_spot2, cv, entry2, exit2
from tkinter import *
import tkinter as tk
import tk_tools
from tkinter.font import BOLD
import paho.mqtt.client as paho
flag_US = False
# Function to extract the action from the recieved plan
def parseFile(filename):
action_out={}
f = open(filename, 'r')
lines = f.readlines()[0:4]
#to remove first character '('
for i in range(0,4):
# lines = lines[1:]
line_split = lines[i].split()#split at spaces
if '(decreasetemperature' in line_split[0] or '(increasetemperature' in line_split[0]:
action_out['temp_action'] = line_split[0]
elif '(opendoor' in line_split[0] or '(closedoor' in line_split[0]:
action_out['pir_action'] = line_split[0]
elif '(switchonlight' in line_split[0] or '(switchofflight' in line_split[0]:
action_out['light_action'] = line_split[0]
elif '(spotnotoccupied' in line_split[0] or '(spotoccupied' in line_split[0]:
action_out['ultra_action'] = line_split[0]
else:
print('error')
return action_out
#Function to call the planner via command line statement by passing the planner.py Domain.pddl Problem.pddl plan.text
def run_planner(domainname, problem, out):
myCmd = 'python SPC_RunOnlineAIPlanner.py {0} {1} {2}'
myCmd = myCmd.format(domainname, problem, out)
os.system(myCmd)
action = parseFile(out)
return action
def generate_problemfile(excel_data):
global flag_US
f = open("SPC_ProblemFile.pddl", "w")
f.write("""(define (problem SPCProblem) (:domain SPCDomain)
(:objects
TempSensor - sensor
Fan - actuator
LightSensor - sensor
Light - actuator
IRSensor - sensor
Door - actuator
Parkingvacancy - spot
UltrasonicSensor - sensor
Led - actuator
)
(:init""")
f.write("\n")
flag = 0
flag_high = 0
try:
if excel_data['humidity'] is not None:
if excel_data['humidity'] > 55.0: #temp is high
f.write("\t(TempHigh TempSensor)\n")
elif excel_data['humidity'] <= 55.0:
f.write("\t(FanOn Fan)\n")
except:
print('temp= nan')
if excel_data['Lightsensor'] < 200 :
f.write("\t(LuminosityLow LightSensor)\n")
print("In Light IF")
else:
f.write("\t(LuminosityHigh LightSensor)\n\t(LightOn Light)\n") #turn led off
print("In Light ELSE")
if excel_data['IR_sensor'] == 1.0 :
f.write("\t(Notmax Parkingvacancy)\n") #open door
led_pg.to_green()
else:
f.write("\t(IRHigh IRSensor)\n\t(DoorOpen Door)\n")
led_pg.to_red()
if excel_data['Ultrasonic-2'] <= 11.0 :
f.write("\t(LedOn Led)\n") #off#car present
led_spot2.to_red()
timenow_2in = time.strftime("%H:%M:%S")
entry2.insert(0,timenow_2in)
entry2.config(state=DISABLED)
cv.create_window(730, 380, window=entry2)
flag_US = True
else:
f.write("\t(UltrasonicHigh UltrasonicSensor)\n")
led_spot2.to_green()
if flag_US is True:
timenow_2out = time.strftime("%H:%M:%S")
exit2.insert(0,timenow_2out)
exit2.config(state=DISABLED)
cv.create_window(880, 380, window=exit2)
flag_US = False
f.write(""")
(:goal (and (TempSuitable TempSensor) (LuminositySuitable LightSensor) (DoorSuitable Door) (suitable UltrasonicSensor));Turn on LED to indicate free spot
)
)""")
f.close()