def bge_get_location_from_placename(name): """Use the coil's place string to get its coordinates as displayed onscreen.""" # get the index of the coil import scripts.ema_blender.coil_info as ci ind = ci.find_sensor_index(name) # get the location of the appropriately-named cube import scripts.ema_blender.ema_bge.bge_standard_gamefns as sgf scene, objs, *_ = sgf.get_scene_info() cubeobj = objs.get('CoilCube{}'.format(str(ind).zfill(2)), False) if cubeobj: return cubeobj.worldPosition else: return None
def get_obj_from_placename(name): """Get the bge object from the placename""" # get the location of the appropriately-named cube import scripts.ema_blender.ema_bge.bge_standard_gamefns as sgf scene, objs, *_ = sgf.get_scene_info() literal_obj = objs.get(name, False) # scene has an object called name if literal_obj: return literal_obj import scripts.ema_blender.coil_info as ci ind = ci.find_sensor_index(name) cubeobj = objs.get(bsh.ema_mesh_name_rule(ind), False) if cubeobj: return cubeobj else: return None
def get_obj_from_placename(name): """Get the bge object from the placename""" scene = bpy.context.scene literal_obj = scene.objects.get(name, False) if literal_obj: return literal_obj # no object with that name, must look in sensor_index file import scripts.ema_blender.coil_info as ci ind = ci.find_sensor_index(name) # get the location of the appropriately-named cube cubeobj = scene.objects.get(bsh.ema_mesh_name_rule(ind), False) if cubeobj: return cubeobj else: return None
def gs_record_biteplate_now(self): print("Performing a biteplate recording, current values:", self.bp_in_rs, self.rp_in_gs) """read the biteplate into BitePlane class - create mapping from global space to biteplate space""" response = self.inform_recording_start() # if streaming ready, stream biteplate recording for 5 seconds if response == 1: print('NOW DOING HEAD-CORRECTION') # get information about which sensors are head-correction and which are biteplate active, biteplate, reference = ci.get_sensor_roles_no_blender() print('these are sensor roles', active, biteplate, reference) server.repl._stop_b = True # stop the normal behaviour of the data queue print('replies queue lives', server.repl._b.is_alive()) # start streaming, get either 1 or (in properties) defined seconds of streaming data server.gs_start_streaming() print('started streaming') time.sleep(2 if pps.head_correction_time is None else pps. head_correction_time) # stop streaming server.gs_stop_streaming() print('stopped streaming') time.sleep(1) # access all the streamed data, empty the queue, saved elements in replies print('qsize is ', server.repl._q34.qsize()) all_streamed = [] while not server.repl._q34.empty(): streamed_df = DataFrame(rawdf=server.repl._q34.get()[2]) print('streamed df was', streamed_df) all_streamed.append(streamed_df) server.repl.latest_df = None server.repl.last_x_dfs.clear() print('\n\nstreamed data looks like', all_streamed[:1]) server.repl._stop_b = False # restart the normal behaviour of streamed data last_frames = dm.remove_first_ms_of_list( all_streamed, ms=1 if pps.head_correction_exclude_first_ms is None else pps.head_correction_exclude_first_ms) no_outliers = dm.remove_outliers(last_frames) average_bp = DataFrame(fromlist=no_outliers) print(average_bp) # prepare the transformations # isolate the coil objects refcoils = [ average_bp.give_coils()[reference[x][0]] for x in range(len(reference)) ] bpcoils = [ average_bp.give_coils()[biteplate[x][0]] for x in range(len(biteplate)) ] lind, rind, find = [ ci.find_sensor_index(n) for n in ['BP1', 'BP2', 'BP3'] ] #todo: check order # create a coordinate-system based on reference sensors (fully-defined here) rp_in_gs = ReferencePlane(*[x.abs_loc for x in refcoils[:3]]) for c in bpcoils: c.ref_loc = rp_in_gs.project_to_lcs(c.abs_loc) # create the bp_in_rs (origin still to be determined) print('biteplate coils are:', lind, rind, find, *[average_bp.give_coils()[x] for x in [lind, rind, find]]) bp_in_rs = BitePlane(*[ average_bp.give_coils()[x].ref_loc for x in [lind, rind, find] ]) pickle.dump( bp_in_rs, open( os.path.normpath(os.getcwd() + os.path.sep + pps.biteplate_cs_storage), 'wb')) pickle.dump( rp_in_gs, open( os.path.normpath(os.getcwd() + os.path.sep + pps.refspace_cs_storage), 'wb')) # now rp_in_gs and bp_in_gs can be used to add attributes to the dataframes server.repl.print_tsv = cl_args.print print('correcting matrices are:', rp_in_gs.give_local_to_global_mat(), bp_in_rs.give_global_to_local_mat()) if os.name == 'nt': import ctypes notification = ctypes.windll.user32.MessageBoxA( 0, b"Set up your wave/server for streaming of active sensor data", b"Biteplate recording finished", 0) else: # no popup yet for linux/mac print('NOW PREPARE FOR NORMAL STREAMING') return bp_in_rs, rp_in_gs else: # presses cancel recording biteplate do nothing. return None, None
def gs_record_biteplate_now(self): print("Performing a biteplate recording, current values:", self.bp_in_rs, self.rp_in_gs) """read the biteplate into BitePlane class - create mapping from global space to biteplate space""" response = self.inform_recording_start() # if streaming ready, stream biteplate recording for 5 seconds if response == 1: print('NOW DOING HEAD-CORRECTION') # get information about which sensors are head-correction and which are biteplate active, biteplate, reference = ci.get_sensor_roles_no_blender() print('these are sensor roles', active, biteplate, reference) server.repl._stop_b = True # stop the normal behaviour of the data queue print('replies queue lives', server.repl._b.is_alive()) # start streaming, get either 1 or (in properties) defined seconds of streaming data server.gs_start_streaming() print('started streaming') time.sleep(2 if pps.head_correction_time is None else pps.head_correction_time) # stop streaming server.gs_stop_streaming() print('stopped streaming') time.sleep(1) # access all the streamed data, empty the queue, saved elements in replies print('qsize is ',server.repl._q34.qsize()) all_streamed = [] while not server.repl._q34.empty(): streamed_df = DataFrame(rawdf=server.repl._q34.get()[2]) print('streamed df was', streamed_df) all_streamed.append(streamed_df) server.repl.latest_df = None server.repl.last_x_dfs.clear() print('\n\nstreamed data looks like', all_streamed[:1]) server.repl._stop_b = False # restart the normal behaviour of streamed data last_frames = dm.remove_first_ms_of_list(all_streamed, ms=1 if pps.head_correction_exclude_first_ms is None else pps.head_correction_exclude_first_ms) no_outliers= dm.remove_outliers(last_frames) average_bp = DataFrame(fromlist=no_outliers) print(average_bp) # prepare the transformations # isolate the coil objects refcoils = [average_bp.give_coils()[reference[x][0]] for x in range(len(reference))] bpcoils = [average_bp.give_coils()[biteplate[x][0]] for x in range(len(biteplate))] lind, rind, find = [ci.find_sensor_index(n) for n in ['BP1', 'BP2', 'BP3']] #todo: check order # create a coordinate-system based on reference sensors (fully-defined here) rp_in_gs = ReferencePlane(*[x.abs_loc for x in refcoils[:3]]) for c in bpcoils: c.ref_loc = rp_in_gs.project_to_lcs(c.abs_loc) # create the bp_in_rs (origin still to be determined) print('biteplate coils are:', lind, rind, find,*[average_bp.give_coils()[x] for x in [lind, rind, find]]) bp_in_rs = BitePlane(*[average_bp.give_coils()[x].ref_loc for x in [lind, rind, find]]) pickle.dump(bp_in_rs, open(os.path.normpath(os.getcwd() + os.path.sep + pps.biteplate_cs_storage), 'wb')) pickle.dump(rp_in_gs, open(os.path.normpath(os.getcwd() + os.path.sep + pps.refspace_cs_storage), 'wb')) # now rp_in_gs and bp_in_gs can be used to add attributes to the dataframes server.repl.print_tsv = cl_args.print print('correcting matrices are:', rp_in_gs.give_local_to_global_mat(), bp_in_rs.give_global_to_local_mat()) if os.name == 'nt': import ctypes notification = ctypes.windll.user32.MessageBoxA(0, b"Set up your wave/server for streaming of active sensor data", b"Biteplate recording finished", 0) else: # no popup yet for linux/mac print('NOW PREPARE FOR NORMAL STREAMING') return bp_in_rs, rp_in_gs else: # presses cancel recording biteplate do nothing. return None, None