Skip to content

Commit b3b4951

Browse files
committed
Feat: Change the pipe organization
1 parent 98c0e1b commit b3b4951

5 files changed

Lines changed: 27 additions & 26 deletions

File tree

src/Simulateur/controllers/controllerWorldSupervisor/controllerWorldSupervisor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ def __init__(self, vehicle_rank: int):
112112
self.receiver.setChannel(2 * self.vehicle_rank + 1)
113113

114114

115-
log(f"CLIENT{simulation_rank}/{vehicle_rank} : begins init")
116-
log(f"CLIENT{simulation_rank}/{vehicle_rank} : {simulation_rank}toserver.pipe")
117-
self.fifo_w = open(f"/tmp/autotech/{simulation_rank}toserver.pipe", "wb")
118-
log(f"CLIENT{simulation_rank}/{vehicle_rank} : serverto{simulation_rank}.pipe")
119-
self.fifo_r = open(f"/tmp/autotech/serverto{simulation_rank}.pipe", "rb")
115+
log(f"CLIENT{simulation_rank}/{vehicle_rank}_{vehicle_rank} : begins init")
116+
log(f"CLIENT{simulation_rank}/{vehicle_rank}_{vehicle_rank} : {simulation_rank}_{vehicle_rank}toserver.pipe")
117+
self.fifo_w = open(f"/tmp/autotech/{simulation_rank}_{vehicle_rank}toserver.pipe", "wb")
118+
log(f"CLIENT{simulation_rank}/{vehicle_rank} : serverto{simulation_rank}_{vehicle_rank}.pipe")
119+
self.fifo_r = open(f"/tmp/autotech/serverto{simulation_rank}_{vehicle_rank}.pipe", "rb")
120120

121121
# Last data received from the car
122122
self.last_data = np.zeros(n_sensors + lidar_horizontal_resolution + camera_horizontal_resolution, dtype=np.float32)

src/Simulateur/launch_train_multiprocessing.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ class WebotsSimulationGymEnvironment(gym.Env):
3636
supervisor: the supervisor of the simulation
3737
"""
3838

39-
def __init__(self, simulation_rank: int):
39+
def __init__(self, simulation_rank: int, vehicle_rank: int):
4040
super().__init__()
4141
self.simulation_rank = simulation_rank
42+
self.vehicle_rank = vehicle_rank
4243

4344
# this is only true if lidar_horizontal_resolution = camera_horizontal_resolution
4445
box_min = np.zeros([2, context_size, lidar_horizontal_resolution], dtype=np.float32)
@@ -50,21 +51,21 @@ def __init__(self, simulation_rank: int):
5051
if not os.path.exists("/tmp/autotech"):
5152
os.mkdir("/tmp/autotech")
5253

53-
log(f"SERVER{simulation_rank} : {simulation_rank=}")
54+
log(f"SERVER{simulation_rank}_{vehicle_rank} : {simulation_rank}_{vehicle_rank}")
5455

55-
os.mkfifo(f"/tmp/autotech/{simulation_rank}toserver.pipe")
56-
os.mkfifo(f"/tmp/autotech/serverto{simulation_rank}.pipe")
56+
os.mkfifo(f"/tmp/autotech/{simulation_rank}_{vehicle_rank}toserver.pipe")
57+
os.mkfifo(f"/tmp/autotech/serverto{simulation_rank}_{vehicle_rank}.pipe")
5758

5859
# --mode=fast --minimize --no-rendering --batch --stdout
5960
os.system(f"""
6061
webots {__file__.rsplit('/', 1)[0]}/worlds/piste{simulation_rank % n_map}.wbt --mode=fast --minimize --no-rendering --batch --stdout &
61-
echo $! {simulation_rank} >>/tmp/autotech/simulationranks
62+
echo $! {simulation_rank}_{vehicle_rank} >>/tmp/autotech/simulationranks
6263
""")
63-
log(f"SERVER{simulation_rank} : {simulation_rank}toserver.pipe")
64-
self.fifo_r = open(f"/tmp/autotech/{simulation_rank}toserver.pipe", "rb")
65-
log(f"SERVER{simulation_rank} : serverto{simulation_rank}.pipe")
66-
self.fifo_w = open(f"/tmp/autotech/serverto{simulation_rank}.pipe", "wb")
67-
log(f"SERVER{simulation_rank} : fifo opened :D and init done")
64+
log(f"SERVER{simulation_rank}_{vehicle_rank} : {simulation_rank}_{vehicle_rank}toserver.pipe")
65+
self.fifo_r = open(f"/tmp/autotech/{simulation_rank}_{vehicle_rank}toserver.pipe", "rb")
66+
log(f"SERVER{simulation_rank}_{vehicle_rank} : serverto{simulation_rank}_{vehicle_rank}.pipe")
67+
self.fifo_w = open(f"/tmp/autotech/serverto{simulation_rank}_{vehicle_rank}.pipe", "wb")
68+
log(f"SERVER{simulation_rank}_{vehicle_rank} : fifo opened :D and init done")
6869
log("-------------------------------------------------------------------")
6970

7071
def reset(self, seed=0):
@@ -77,19 +78,19 @@ def reset(self, seed=0):
7778
return obs, info
7879

7980
def step(self, action):
80-
log(f"SERVER{self.simulation_rank} : sending {action=}")
81+
log(f"SERVER{self.simulation_rank}_{self.vehicle_rank} : sending {action=}")
8182
self.fifo_w.write(action.tobytes())
8283
self.fifo_w.flush()
8384

8485
# communication with the supervisor
8586
cur_state = np.frombuffer(self.fifo_r.read(np.dtype(np.float32).itemsize * (n_sensors + lidar_horizontal_resolution + camera_horizontal_resolution)), dtype=np.float32)
86-
log(f"SERVER{self.simulation_rank} : received {cur_state=}")
87+
log(f"SERVER{self.simulation_rank}_{self.vehicle_rank} : received {cur_state=}")
8788
reward = np.frombuffer(self.fifo_r.read(np.dtype(np.float32).itemsize), dtype=np.float32)[0] # scalar
88-
log(f"SERVER{self.simulation_rank} : received {reward=}")
89+
log(f"SERVER{self.simulation_rank}_{self.vehicle_rank} : received {reward=}")
8990
done = np.frombuffer(self.fifo_r.read(np.dtype(np.bool).itemsize), dtype=np.bool)[0] # scalar
90-
log(f"SERVER{self.simulation_rank} : received {done=}")
91+
log(f"SERVER{self.simulation_rank}_{self.vehicle_rank} : received {done=}")
9192
truncated = np.frombuffer(self.fifo_r.read(np.dtype(np.bool).itemsize), dtype=np.bool)[0] # scalar
92-
log(f"SERVER{self.simulation_rank} : received {truncated=}")
93+
log(f"SERVER{self.simulation_rank}_{self.vehicle_rank} : received {truncated=}")
9394
info = {}
9495

9596
cur_state = np.nan_to_num(cur_state[n_sensors:], nan=0., posinf=30.)
@@ -119,11 +120,11 @@ def step(self, action):
119120
if B_DEBUG:
120121
print("Webots started", file=open("/tmp/autotech/logs", "w"))
121122

122-
def make_env(rank: int):
123+
def make_env(rank: int, rank_v: int):
123124
log(f"CAREFUL !!! created an SERVER env with {rank=}")
124-
return WebotsSimulationGymEnvironment(rank)
125+
return WebotsSimulationGymEnvironment(rank, rank_v)
125126

126-
envs = SubprocVecEnv([lambda rank=rank : make_env(rank) for rank in range(n_simulations)])
127+
envs = SubprocVecEnv([lambda rank=rank, rank_v =rank_v : make_env(rank, rank_v) for rank_v in range(n_vehicles) for rank in range(n_simulations)])
127128

128129
ExtractorClass = TemporalResNetExtractor
129130

src/Simulateur/worlds/.piste0.wbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Webots Project File version R2025a
2-
perspectives: 000000ff00000000fd00000002000000010000011c00000177fc0200000001fb0000001400540065007800740045006400690074006f00720000000016000001770000004500ffffff00000003000006c000000216fc0100000001fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c0100000000000006c00000008700ffffff000006c0000001c400000001000000020000000100000008fc00000000
2+
perspectives: 000000ff00000000fd00000002000000010000011c00000177fc0200000001fb0000001400540065007800740045006400690074006f00720000000016000001770000003f00ffffff00000003000004f400000039fc0100000001fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c0100000000000004f40000006900ffffff000004f40000017c00000001000000020000000100000008fc00000000
33
simulationViewPerspectives: 000000ff0000000100000002000001000000017d0100000002010000000100
44
sceneTreePerspectives: 000000ff00000001000000030000001f0000013e000000fa0100000002010000000200
55
maximizedDockId: -1

src/Simulateur/worlds/.piste1.wbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Webots Project File version R2025a
2-
perspectives: 000000ff00000000fd0000000200000001000000870000028afc0200000001fb0000001400540065007800740045006400690074006f007201000000000000028a0000004500ffffff00000003000006c000000150fc0100000002fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c0100000000000006c00000008700fffffffb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c010000000000000a000000000000000000000006370000028a00000001000000020000000100000008fc00000000
2+
perspectives: 000000ff00000000fd0000000200000001000000870000017cfc0200000001fb0000001400540065007800740045006400690074006f007201000000130000017c0000003f00ffffff00000003000004f400000039fc0100000002fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c0100000000000004f40000006900fffffffb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c010000000000000a0000000000000000000000046b0000017c00000001000000020000000100000008fc00000000
33
simulationViewPerspectives: 000000ff00000001000000020000012b000005a50100000002010000000100
44
sceneTreePerspectives: 000000ff00000001000000030000001e00000364000000fa0100000002010000000200
55
minimizedPerspectives: 000000ff00000000fd0000000200000001000000750000017bfc0200000001fb0000001400540065007800740045006400690074006f007201000000160000017b0000003f00ffffff000000030000039b00000039fc0100000002fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c01000000000000039b0000006900fffffffb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c010000000000000a000000000000000000000003240000017b00000001000000020000000100000008fc00000000

src/Simulateur/worlds/.piste2.wbproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Webots Project File version R2025a
2-
perspectives: 000000ff00000000fd0000000200000001000001910000036ffc0200000001fb0000001400540065007800740045006400690074006f007200000000160000036f0000003f00ffffff000000030000039b00000039fc0100000002fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c01000000000000039b0000006900fffffffb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c01000000000000078000000000000000000000039b0000036a00000001000000020000000100000008fc00000000
2+
perspectives: 000000ff00000000fd0000000200000001000001910000036ffc0200000001fb0000001400540065007800740045006400690074006f007200000000160000036f0000003f00ffffff000000030000078000000039fc0100000002fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c0100000000000007800000006900fffffffb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c0100000000000007800000000000000000000007800000038c00000001000000020000000100000008fc00000000
33
simulationViewPerspectives: 000000ff00000001000000020000014d000006310100000002010000000100
44
sceneTreePerspectives: 000000ff00000001000000030000001d0000013c000000fa0100000002010000000200
55
maximizedDockId: -1

0 commit comments

Comments
 (0)