Skip to content

Commit

Permalink
Merge branch 'developRR'
Browse files Browse the repository at this point in the history
  • Loading branch information
renerichter committed Dec 17, 2019
2 parents b4ced82 + 065c188 commit 5d0704a
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,23 @@ public class MainActivity extends AppCompatActivity implements SeekBar.OnSeekBar
String serverUri = "0.0.0.0";



// Assign Random ID for the Client
Random rand = new Random();
String rand_id = String.format("%04d", rand.nextInt(1000));
final String clientId = "AND123"+rand_id;

boolean is_vibration = false;
// TAG
String TAG = "UC2 Controler";
String TAG = "UC2 Controller";

// Save settings for later
private final String PREFERENCE_FILE_KEY = "myAppPreference";

// MQTT Topics
// environment variables
public static String experiment_id = "1";
public static String topic_prefix_setup = "/S004/";
public static String experiment_id = "5";
public static String topic_prefix_setup = "/S005/";
public static final String topic_prefix_dev1 = "MOT01/";
public static final String topic_prefix_dev2 = "MOT02/";
public static final String topic_prefix_dev3 = "LAR01/";
Expand Down Expand Up @@ -139,7 +140,7 @@ protected void onCreate(Bundle savedInstanceState) {
// Manage the Actionbar settings
ActionBar actionBar = getSupportActionBar();
actionBar.setLogo(R.mipmap.ic_launcher);
actionBar.setTitle("UC2 Controler");
actionBar.setTitle("UC2 Controller");
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);

Expand Down Expand Up @@ -258,7 +259,7 @@ public void run() {
} else if (tap_counter_ipadress_button == 2) {
//Double click
tap_counter_ipadress_button = 0;
serverUri = "192.168.43.88";
serverUri = "21.3.2.103";
EditTextIPAddress.setText(serverUri);
Toast.makeText(MainActivity.this, "IP-Address set to default: " + serverUri, Toast.LENGTH_SHORT).show();
stopConnection();
Expand Down
22 changes: 22 additions & 0 deletions GUI/RASPBERRY_PI/RASPIapp_py3/SCRIPTS/MQTT_fluo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# %% imports
import sys
import os
import subprocess

# %% parameters
msetup = 8
mdev = "MOT01"
mtopic = "/S00" + str(msetup) + "/" + mdev + "/RECM"
mcmd = "FLUO+"

# %% scripts
while True:
in_val = int(input(
"Please input an integer between 0 (=off) and 100 (=max). Anything else ends the program."))
if in_val >= 0 and in_val < 101:
mcmdsend = ["mosquitto_pub", "-h", "localhost",
"-t", mtopic, "-m", mcmd + str(in_val)]
subprocess.run(mcmdsend)
print("Changed to {} ".format(" ".join(mcmdsend)))
else:
break
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
awbGain:
- 1.5
- 1.5
awbMode: 'off'
awbMode: 'auto'
brightness: 50
colorEffects: null
contrast: 0
Expand All @@ -18,11 +18,12 @@ iso: 100
meterMode: average
previewLength: 3
resolution:
- 2592
- 1944
- 3280
- 2464
rotation: 0
saturation: 0
sharpness: 0
shutterSpeed: 0
shutterSpeed: 1000000
sensor_mode: 4
vflip: false
videoStabilization: false
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
awbGain:
- 1.5
- 1.5
awbMode: 'off'
awbMode: 'auto'
brightness: 50
colorEffects: null
contrast: 0
Expand All @@ -11,18 +11,19 @@ crop:
- 1.0
- 1.0
exposureCompensation: 0
exposureMode: false
exposureMode: auto
hflip: []
imageEffects: none
iso: 100
meterMode: average
previewLength: 3
resolution:
- 2592
- 1944
- 3280
- 2464
rotation: 0
saturation: 0
sharpness: 0
shutterSpeed: 0
shutterSpeed: 1000000
sensor_mode: 4
vflip: false
videoStabilization: false
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ snap_num: 0
success: false
time_left: 119
time_passed: 1
take_raw: 1
tm_backlash: 10
tm_endPOS: 200
tm_motor: Z
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
alpha: 255
extension: .jpg
fullscreen: 0
speed: 0.1
speed: 2.0
window:
- 2
- 40
Expand Down
6 changes: 3 additions & 3 deletions GUI/RASPBERRY_PI/RASPIapp_py3/config/camera_properties.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
awbGain:
- 1.5
- 1.5
awbMode: 'off'
awbMode: auto
brightness: 50
colorEffects: null
contrast: 0
Expand All @@ -18,8 +18,8 @@ iso: 100
meterMode: average
previewLength: 3
resolution:
- 2592
- 1944
- 3280
- 2464
rotation: 0
saturation: 0
sharpness: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ last_expt_num: 1
path_last_expt: C:\Users\renelachmann\Documents\Programming\UC2_Software-GIT\GUI\RASPBERRY_PI\RASPIapp_py3\data\20191203\expt_001
snap_num: 0
success: false
take_raw: 1
time_left: 119
time_passed: 1
take_raw: 1
tm_backlash: 10
tm_endPOS: 200
tm_motor: Z
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
alpha: 255
extension: .jpg
fullscreen: 0
speed: 0.1
speed: 2.0
window:
- 2
- 40
Expand Down
2 changes: 1 addition & 1 deletion GUI/RASPBERRY_PI/RASPIapp_py3/config/light_properties.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ color_picked:
- 255
- 255
- 255
color_picker_counter: 4
color_picker_counter: 0
default:
- - - 0
- 0
Expand Down
73 changes: 46 additions & 27 deletions GUI/RASPBERRY_PI/RASPIapp_py3/fluidiscopeToolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import usb
#import cv2 as cv
from PIL import Image
import picamera
import numpy as np
from fractions import Fraction
from kivy.clock import Clock
Expand Down Expand Up @@ -565,7 +566,7 @@ def run_measurement(self, instance):
if instance.uid == self.ids['btn_snap'].uid:
select_method(self, instance, "take_image")
activate(instance)
take_image(self)
take_image_callback(self)
abort_measurement(self, instance)
else:
# rewrite button-text if necessary
Expand Down Expand Up @@ -713,9 +714,23 @@ def take_image_now(self,imaging_cause='MEAS', filename='', method='CUS'):
return image
else:
fg.camera.capture(filename)
if 'Fluor' in fg.experiment['experiment']['imaging_method']:
fg.camera.c
return True
if 'Fluor' in fg.config['experiment']['active_methods']:
logger.debug("RAW: Start acquistion into RAM, extract and concat Green-Channel.")
filename[:-4] + '-rawG.npz'
stream = picamera.array.PiBayerArray(fg.camera)
fg.camera.capture(stream, 'jpeg', bayer=True) #'rgb' -> Error: unable to locate bayer-pattern at end of buffer
rawstream = np.transpose(np.dstack((stream.array[1::2,::2,1],stream.array[::2,1::2,1])),[2,0,1])
logger.debug("RAW: Save as compressed numpy.")
np.savez_compressed(filename, rawstream) # and lossless compressed
logger.debug("RAW: done.")
return True

def take_image_callback(self, *args):
'''
Callback function to make sure GUI stays responsive while image is taken. Event is only called once and hence will delete itself.
'''
fg.EVENT['take_image_callback'] = Clock.schedule_once(partial(take_image, self),0.01)
return True

def take_image(self, *args):
'''
Expand Down Expand Up @@ -790,14 +805,18 @@ def take_image(self, *args):
fg.ledarr.send("CLEAR")
elif active_method== "FPM":
# 1 image per LED
fnwh = file_name_write
fnwh_raw = file_name_write + datetime.strftime(datetime.now(),"%H%M%S" )
logger.debug("Starting FPM.")
for myc in range(64):
fnwh += "-" + str(myc).zfill(2)
fnwh = fnwh_raw + "-" + str(myc).zfill(2)
time.sleep(0.04) # fastened
fg.ledarr.send("PXL", myc, col,col,col)
time.sleep(fg.config['imaging']['speed'])
#time.sleep(fg.config['imaging']['speed'])
time.sleep(1.0) # fastened
tin_returnval = take_image_now(self,fg.config['experiment']['imaging_cause'], fnwh)
logger.debug("Storing LED={} to {}.".format(myc,fnwh))
fg.ledarr.send("CLEAR")
time.sleep(0.04)
elif active_method== "RECT":
# set now with small NA image
file_name_write = uni.Path(fg.expt_path, image_name)
Expand All @@ -822,7 +841,6 @@ def take_image(self, *args):
camera_preview(self,True)
for x in active_modes:
buttons_light(self, self.ids[x])

# True -> normal images taken;
# image -> case of autofocus
return tin_returnval
Expand Down Expand Up @@ -872,25 +890,26 @@ def camera_set_parameter(method='CUS'):
if method in ['CUS','qDPC','Bright','BG','FG']:
method_key = 'cam'
fg.camera.resolution = tuple(fg.config[method_key]['resolution'])
fg.camera.contrast = fg.config[method_key]['contrast']
fg.camera.sharpness = fg.config[method_key]['sharpness']
fg.camera.brightness = fg.config[method_key]['brightness']
fg.camera.saturation = fg.config[method_key]['saturation']
fg.camera.ISO = fg.config[method_key]['iso']
fg.camera.video_stabilization = fg.config[method_key]['videoStabilization']
fg.camera.exposure_compensation = fg.config[method_key]['exposureCompensation']
fg.camera.exposure_mode = fg.config[method_key]['exposureMode']
fg.camera.meter_mode = fg.config[method_key]['meterMode']
fg.camera.awb_mode = fg.config[method_key]['awbMode']
#fg.camera.contrast = fg.config[method_key]['contrast']
#fg.camera.sharpness = fg.config[method_key]['sharpness']
#fg.camera.brightness = fg.config[method_key]['brightness']
#fg.camera.saturation = fg.config[method_key]['saturation']
#fg.camera.ISO = fg.config[method_key]['iso']
#fg.camera.video_stabilization = fg.config[method_key]['videoStabilization']
#fg.camera.exposure_compensation = fg.config[method_key]['exposureCompensation']
#fg.camera.exposure_mode = fg.config[method_key]['exposureMode']
#fg.camera.meter_mode = fg.config[method_key]['meterMode']
#fg.camera.awb_mode = fg.config[method_key]['awbMode']
if fg.config[method_key]['awbMode'] == 'off':
fg.camera.awb_gains = (Fraction(200, 128), Fraction(200, 128)) # (red, blue) [0..8] TODO: Get values from YAML, Only some randomly chosen values! fg.config[method_key]['awbGain']
fg.camera.image_effect = fg.config[method_key]['imageEffects']
fg.camera.color_effects = fg.config[method_key]['colorEffects']
fg.camera.rotation = fg.config[method_key]['rotation']
fg.camera.hflip = fg.config[method_key]['hflip']
fg.camera.vflip = fg.config[method_key]['vflip']
fg.camera.crop = tuple(fg.config[method_key]['crop'])
#fg.camera.image_effect = fg.config[method_key]['imageEffects']
#fg.camera.color_effects = fg.config[method_key]['colorEffects']
#fg.camera.rotation = fg.config[method_key]['rotation']
#fg.camera.hflip = fg.config[method_key]['hflip']
#fg.camera.vflip = fg.config[method_key]['vflip']
#fg.camera.crop = tuple(fg.config[method_key]['crop'])
fg.camera.shutter_speed = fg.config[method_key]['shutterSpeed']
fg.camera.sensor_mode = fg.config[method_key]['sensor_mode']
elif method == 'Fluor':
method_key = 'cam_fluo'
fg.camera.resolution = tuple(fg.config[method_key]['resolution'])
Expand All @@ -913,8 +932,8 @@ def camera_set_parameter(method='CUS'):
fg.camera.vflip = fg.config[method_key]['vflip']
fg.camera.crop = tuple(fg.config[method_key]['crop'])
fg.camera.shutter_speed = fg.config[method_key]['shutterSpeed']
logger.debug("Camera shutter_speed={}, exposure_speed={} at ISO=.".format(fg.camera.shutter_speed, fg.camera.exposure_speed, fg.camera.iso))
logger.debug("Camera preparation done for method=".format(method))
logger.debug("Camera shutter_speed={}, exposure_speed={}, ISO={}, AWB={},AWB_gains={}.".format(fg.camera.shutter_speed, fg.camera.exposure_speed,fg.camera.awb_mode, fg.camera.iso, fg.camera.awb_gains))
logger.debug("Camera preparation done for method={}.".format(method))
return True

def crop_image():
Expand Down Expand Up @@ -943,7 +962,7 @@ def imaging_callback(self, instance, *largs):
if not fg.config['experiment']['is_autofocus_busy']:
# take image
fg.config['experiment']['imaging_method']='MEAS'
take_image(self)
take_image_callback(self)
deact_me = False
if (fg.config['experiment']['time_left']-fg.config['experiment']['interval']) >= 0:
# update config entries
Expand Down
6 changes: 3 additions & 3 deletions GUI/RASPBERRY_PI/RASPIapp_py3/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# I/O
if (1):
import os
os.environ['KIVY_TEXT'] = 'egl_rpi'
os.environ['KIVY_WINDOW'] = 'egl_rpi' # 'sdl2'
os.environ['KIVY_GL_BACKEND'] = 'gl'
#os.environ['KIVY_TEXT'] = 'egl_rpi'
os.environ['KIVY_WINDOW'] = 'sdl2' # 'egl_rpi' # 'sdl2'
#os.environ['KIVY_GL_BACKEND'] = 'gl'
# time.sleep(1)
pass
# Fluidiscope
Expand Down

0 comments on commit 5d0704a

Please sign in to comment.