-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestdrivenet.py
58 lines (41 loc) · 1.57 KB
/
testdrivenet.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
from keras.models import Sequential
from keras.models import model_from_json
from keras.layers import Dense
import numpy as np
import pybullet as p
import pybullet_data
from goodbot import Goodbot
from road import Road
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
phyCl = p.connect(p.GUI) # SETTING UP THE ENVIRONMENT
p.setAdditionalSearchPath(pybullet_data.getDataPath())
plane = p.loadURDF("plane.urdf") # load the plane
p.setGravity(0, 0, -10) # set gravity
p.setRealTimeSimulation(1)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" a road point is 0.3x0.3 coordinates big"""
p.resetDebugVisualizerCamera(25, 0, -89.9, [0, 0, 0])
road = Road('road/blender_road.txt')
robot = Goodbot("goodbot/goodbot.urdf", road.fetchStart() + [0.3])
p.setRealTimeSimulation(1)
velocity = 30
force = 100
p.setGravity(0, 0, -30)
json_file = open('keras/model.json', 'r')
model = json_file.read()
json_file.close()
model = model_from_json(model)
model.load_weights('keras/model.h5')
robot.go_forward(velocity, force)
while 1:
inputArray = road.serveNet(robot)
inputArray = np.reshape(inputArray, (inputArray.shape[0], 1, inputArray.shape[1]))
prediction = model.predict(inputArray)
# print(prediction) # right, left, forwards, backwards
robot.turn_ahead()
print(prediction[0][0], prediction[0][1], prediction[0][2])
if(prediction[0][0] >= 0.4 or prediction[0][1] >= 0.4):
if(prediction[0][0] > prediction[0][1]):
robot.turn_right()
else:
robot.turn_left()