From 3c624c777aff043072b4a7e99646b518de6c800b Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 24 Mar 2016 00:49:56 +0800 Subject: [PATCH] examples: add remote_exec_controller --- examples/master/device_db.pyon | 14 ++++++++ examples/remote_exec_controller.py | 58 ++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100755 examples/remote_exec_controller.py diff --git a/examples/master/device_db.pyon b/examples/master/device_db.pyon index ebc75b1ff..873971327 100644 --- a/examples/master/device_db.pyon +++ b/examples/master/device_db.pyon @@ -199,6 +199,20 @@ "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_serdes": "ttl0", diff --git a/examples/remote_exec_controller.py b/examples/remote_exec_controller.py new file mode 100755 index 000000000..70f859d68 --- /dev/null +++ b/examples/remote_exec_controller.py @@ -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()