-
Notifications
You must be signed in to change notification settings - Fork 3
/
test6_two_robot.py
178 lines (119 loc) · 4.69 KB
/
test6_two_robot.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
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 19 23:09:34 2017
This test file is dependent on vrep.
To run this file, please open vrep file scene/scene_double.ttt first
@author: cz
"""
from scene import Scene
from sceneplot import ScenePlot
# from robot import Robot
import numpy as np
# from data import Data
from DeepFCL2 import DeepFCL
fcl = DeepFCL(50, 50, 2, 2)
sc = None
def generateData():
sc = Scene(recordData = True)
sp = ScenePlot(sc)
#sc.occupancyMapType = sc.OCCUPANCY_MAP_THREE_CHANNEL
sc.occupancyMapType = sc.OCCUPANCY_MAP_BINARY
sc.dynamics = sc.DYNAMICS_MODEL_BASED_LINEAR # robot dynamics
try:
sc.addRobot(np.float32([[-2, 0, 0], [0.0, 0.0, 0.0]]), role = sc.ROLE_LEADER)
sc.addRobot(np.float32([[1, 3, 0], [-1.0, 0.0, 0.0]]), role = sc.ROLE_FOLLOWER)
# sc.addRobot(np.float32([[1, 3, 0], [-1.0, 0.0, 0.0]]), role = sc.ROLE_FOLLOWER, learnedController = fcl.test)
#==============================================================================
# sc.addRobot(np.float32([[1, 3, 0], [0, -1, 0]]),
# dynamics = sc.DYNAMICS_LEARNED,
# learnedController = fcl.test)
#==============================================================================
# No leader
sc.setADjMatrix(np.uint8([[0, 0], [1, 0]]))
# Set robot 0 as the leader.
# vrep related
sc.initVrep()
# Choose sensor type
sc.SENSOR_TYPE = "VPL16" # None, 2d, VPL16, kinect
#sc.SENSOR_TYPE = "None" # None, 2d, VPL16, kinect
sc.objectNames = ['Pioneer_p3dx', 'Pioneer_p3dx_leftMotor', 'Pioneer_p3dx_rightMotor']
if sc.SENSOR_TYPE == "None":
sc.setVrepHandles(0, '')
sc.setVrepHandles(1, '#0')
elif sc.SENSOR_TYPE == "2d":
sc.objectNames.append('LaserScanner_2D_front')
sc.objectNames.append('LaserScanner_2D_rear')
sc.setVrepHandles(0, '')
sc.setVrepHandles(1, '#0')
elif sc.SENSOR_TYPE == "VPL16":
sc.objectNames.append('velodyneVPL_16') # _ptCloud
sc.setVrepHandles(0, '')
sc.setVrepHandles(1, '#0')
elif sc.SENSOR_TYPE == "kinect":
sc.objectNames.append('kinect_depth')
sc.objectNames.append('kinect_rgb')
sc.setVrepHandles(0, '')
sc.setVrepHandles(1, '#0')
#sc.renderScene(waitTime = 3000)
tf = 40 # must be greater than 1
sc.resetPosition()
sp.plot(3, tf)
while sc.simulate():
#sc.renderScene(waitTime = int(sc.dt * 1000))
sc.showOccupancyMap(waitTime = int(sc.dt * 1000))
#print("---------------------")
#print("t = %.3f" % sc.t, "s")
if sc.t > 1:
maxAbsError = sc.getMaxFormationError()
if maxAbsError < 0.01:
pass #tf = sc.t - 0.01
#sp.plot(0, tf)
sp.plot(2, tf)
#sp.plot(1, tf)
sp.plot(3, tf)
sp.plot(4, tf)
sp.plot(6, tf)
if sc.t > tf:
print('maxAbsError = ', maxAbsError)
break
#print('robot 0: ', sc.robots[0].xi.x, ', ', sc.robots[0].xi.y, ', ', sc.robots[0].xi.theta)
#print('robot 1: ', sc.robots[1].xi.x, ', ', sc.robots[1].xi.y, ', ', sc.robots[1].xi.theta)
#print('robot 2: ', sc.robots[2].xi.x, ', ', sc.robots[2].xi.y, ', ', sc.robots[2].xi.theta)
#print('y01: ' + str(sc.robots[1].xi.y - sc.robots[0].xi.y))
#print('x02: ' + str(sc.robots[2].xi.x - sc.robots[0].xi.x))
sc.deallocate()
except KeyboardInterrupt:
x = input('Quit?(y/n)')
sc.deallocate()
if x == 'y' or x == 'Y':
tf = sc.t - 0.01
sp.plot(2, tf)
sp.plot(3, tf)
sp.plot(4, tf)
sp.plot(6, tf)
raise Exception('Aborted.')
except:
sc.deallocate()
raise
if True: #maxAbsError < 0.01:
return sc
else:
return None
# main
numRun = 1000
dataList = []
fcl.init_test()
for i in range(0, numRun):
print('Run #: ', i, '...')
# First episode
sc = generateData()
if sc is not None:
# if the list is empty
if not dataList:
for robot in sc.robots:
dataList.append(robot.data)
else:
for j in range(len(sc.robots)):
dataList[j].append(sc.robots[j].data)
for j in range(len(sc.robots)):
dataList[j].store()