forked from M-Labs/artiq
1
0
Fork 0

examples: add remote_exec_controller

This commit is contained in:
Sebastien Bourdeauducq 2016-03-24 00:49:56 +08:00
parent e6809397a3
commit 3c624c777a
2 changed files with 72 additions and 0 deletions

View File

@ -199,6 +199,20 @@
"command": "lda_controller -p {port} --bind {bind} --simulation" "command": "lda_controller -p {port} --bind {bind} --simulation"
}, },
"camera_sim": {
"type": "controller",
"host": "::1",
"port": 6283,
"target_name": "camera_sim",
"command": "./remote_exec_controller.py"
},
"camera_sim_rexec": {
"type": "controller_aux_target",
"controller": "camera_sim",
"target_name": "camera_sim_rexec"
},
"ttl_out": "ttl0", "ttl_out": "ttl0",
"ttl_out_serdes": "ttl0", "ttl_out_serdes": "ttl0",

View File

@ -0,0 +1,58 @@
#!/usr/bin/env python3.5
import numpy as np
from numba import jit
from artiq.protocols.remote_exec import simple_rexec_server_loop
@jit(nopython=True)
def compute_picture(r, img_h, img_w,
gaussian_w, gaussian_h,
gaussian_cx, gaussian_cy,
noise_level):
for y in range(img_h):
for x in range(img_w):
ds = ((gaussian_cx-x)/gaussian_w)**2
ds += ((gaussian_cy-y)/gaussian_h)**2
r[x, y] = np.exp(-ds/2) + noise_level*np.random.random()
class CameraSimulation:
def __init__(self):
self.img_w = 320
self.img_h = 200
self.gaussian_w = 4
self.gaussian_h = 3
self.gaussian_cx = self.img_w//2
self.gaussian_cy = self.img_h//2
self.noise_level = 0.1
def set_gaussian_width(self, wx, wy=None):
if wy is None:
wy = wx
self.gaussian_w = wx
self.gaussian_h = wy
def set_gaussian_center(self, x, y):
self.gaussian_cx = x
self.gaussian_cy = y
def set_noise_level(self, noise_level):
self.noise_level = noise_level
def get_picture(self):
r = np.empty((self.img_w, self.img_h))
compute_picture(r, self.img_h, self.img_w,
self.gaussian_w, self.gaussian_h,
self.gaussian_cx, self.gaussian_cy,
self.noise_level)
return r
def main():
simple_rexec_server_loop("camera_sim", CameraSimulation(),
"::1", 6283)
if __name__ == "__main__":
main()