def sunsensor_read(delay, track_time, filter_mode, ss_read, SS1_id, SS1_com, SS1_baudrate, SS2_id, SS2_com, SS2_baudrate, SS3_id, SS3_com, SS3_baudrate, SS1_queue, SS2_queue, SS3_queue, ss_eshim_x, ss_eshim_y): from ss import SS ss1 = SS(inst_id=SS1_id, com_port=SS1_com, baudrate=SS1_baudrate) ss2 = SS(inst_id=SS2_id, com_port=SS2_com, baudrate=SS2_baudrate) ss3 = SS(inst_id=SS3_id, com_port=SS3_com, baudrate=SS3_baudrate) time_start = time.time() print('i am starting') while True: #SS1 time_ss1_0 = time.time() ss1.read_data_all() #Read all data from sun sensor using SS class time_ss1_1 = time.time() ss1_tstamp = time.time() - (time_ss1_1 - time_ss1_0) / 2. if filter_mode == 2: #Use filtered data if filter mode=2, otherwise use raw data if (SS1_queue.full() == False): SS1_queue.put([ ss1.ang_x_filt + ss_eshim_x[0], ss1.ang_y_filt + ss_eshim_y[0], ss1_tstamp ]) #add electronic shims to angle offset for tracking else: SS1_queue.get() SS1_queue.put([ ss1.ang_x_filt + ss_eshim_x[0], ss1.ang_y_filt + ss_eshim_y[0], ss1_tstamp ]) else: if (SS1_queue.full() == False): #print([ss1.ang_x_raw + ss_eshim_x[0],ss1.ang_y_raw + ss_eshim_y[0],ss1_tstamp]) SS1_queue.put([ ss1.ang_x_raw + ss_eshim_x[0], ss1.ang_y_raw + ss_eshim_y[0], ss1_tstamp ]) else: #print('too full') SS1_queue.get() SS1_queue.put([ ss1.ang_x_raw + ss_eshim_x[0], ss1.ang_y_raw + ss_eshim_y[0], ss1_tstamp ]) #SS2 time_ss2_0 = time.time() ss2.read_data_all() #Read all data from sun sensor using SS class time_ss2_1 = time.time() ss2_tstamp = time.time() - (time_ss2_1 - time_ss2_0) / 2. if filter_mode == 2: #Use filtered data if filter mode=2, otherwise use raw data if (SS2_queue.full() == False): SS2_queue.put([ ss2.ang_x_filt + ss_eshim_x[1], ss2.ang_y_filt + ss_eshim_y[1], ss2_tstamp ]) #add electronic shims to angle offset for tracking else: SS2_queue.get() SS2_queue.put([ ss2.ang_x_filt + ss_eshim_x[1], ss2.ang_y_filt + ss_eshim_y[1], ss2_tstamp ]) else: if (SS2_queue.full() == False): SS2_queue.put([ ss2.ang_x_raw + ss_eshim_x[1], ss2.ang_y_raw + ss_eshim_y[1], ss2_tstamp ]) else: SS2_queue.get() SS2_queue.put([ ss2.ang_x_filt + ss_eshim_x[1], ss2.ang_y_filt + ss_eshim_y[1], ss2_tstamp ]) #SS3 time_ss3_0 = time.time() # ss3.read_data_all() #Read all data from sun sensor using SS class # time_ss3_1=time.time() # ss3_tstamp=time.time() - (time_ss3_1-time_ss3_0)/2. # if filter_mode == 2: #Use filtered data if filter mode=2, otherwise use raw data # if(SS3_queue.full()==False): # SS3_queue.put([ss3.ang_x_filt + ss_eshim_x[2],ss3.ang_y_filt + ss_eshim_y[2],ss3_tstamp]) #add electronic shims to angle offset for tracking # else: # SS3_queue.get() # SS3_queue.put([ss3.ang_x_filt + ss_eshim_x[2],ss3.ang_y_filt + ss_eshim_y[2],ss3_tstamp]) # else: # if(SS3_queue.full()==False): # SS3_queue.put([ss3.ang_x_raw + ss_eshim_x[2],ss3.ang_y_raw + ss_eshim_y[2],ss3_tstamp]) # else: # SS3_queue.get() # SS3_queue.put([ss3.ang_x_filt + ss_eshim_x[2],ss3.ang_y_filt + ss_eshim_y[2],ss3_tstamp]) #Ensure you are at the rate time_diff = time.time() - time_ss1_0 if delay - time_diff > 0: #print('sleeping off my delay ',delay-time_diff) time.sleep(delay - time_diff) # Exit the function once tracking time has been reached if ((time.time() - time_start) > track_time): #Note: try catch to stop PTU is not commented here, ensure if it would be able to be called #ptu.cmd('ps0') #ptu.cmd('ts0') print("Tracking complete!") return
mpl.rcParams['axes.labelsize'] = base_size mpl.rcParams['lines.markersize'] = 4 # markersize, in points mpl.rcParams['legend.markerscale'] = 1 # line width in points mpl.rcParams[ 'lines.markeredgewidth'] = 0.4 # the line width around the marker symbol mpl.rcParams['lines.linewidth'] = 4 colors = [ 'tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan' ] ################################################################################ from ptu_newmark import PTU from ss import SS import time ss1 = SS(inst_id=1, com_port='COM6', baudrate=115200) ptu_x = PTU(com_port='COM11', baudrate=115200) ptu_y = PTU(com_port='COM9', baudrate=115200) scan_speed = 80000 scan_increment = 7.5 #degrees for each grid block scan_x_count = 1 scan_y_count = 1 scan_detect_limit = 4 deg2pos = 20000 ss_eshim_x = 0.0 ss_eshim_y = 0.0 ptu_x.cmd('@01SSPD' + str(scan_speed) + '\r') ptu_y.cmd('@01SSPD' + str(scan_speed) + '\r')
# -*- coding: utf-8 -*- """ Created on Sun Jul 8 14:57:47 2018 @author: Bailey group PC """ from ss import SS import time from datetime import datetime #ss1 = SS(inst_id=2,com_port='COM4',baudrate=115200) #ss1 = SS(inst_id=1,com_port='COM6',baudrate=115200) ss1 = SS(inst_id=4, com_port='COM6', baudrate=115200) #ss1 = SS(inst_id=1,com_port='COM6',baudrate=115200) hz = 2 rec_time = 50000 delay = 1.0 / hz t0 = time.time() while time.time() - t0 < rec_time: d_time = datetime.now() #Read data ss1.read_data_all() print('x=', ss1.ang_x_raw, 'y=', ss1.ang_y_raw) #Ensure that this loop iterates at desired data rate t_diff = time.time() - t0 if (delay - t_diff) > 0: time.sleep(delay - t_diff) else:
#Define data collection parameters track_time=120 #number of seconds to capture data/track hz=10 #data sample rate cnt=0 delay = 1.0/hz #Define directory to save data in #save_dir = 'C:/git_repos/GLO/Tutorials/tracking/' save_dir= 'C:/Users/Bobby/Documents/GitHub/GLO_Tracking/' #Obtain ephemeris data ep = ephem.Observer() #Establish communication with sun sensor/s - store in a list ss=[SS(inst_id=1,com_port='COM7',baudrate=115200), SS(inst_id=2,com_port='COM4',baudrate=115200), SS(inst_id=3,com_port='COM7',baudrate=115200)] #List of sun sensors to read data from ss_read = [2,3] #List of sun sensors to use for tracking ss_track = [2,3] # ss_eshim_x = [-1.763, -1.547, -1.578] #Specify electronic shims (x-dir) for sun sensors # ss_eshim_y = [-2.290, -2.377, -2.215] #Specify electronic shims (y-dir) for sun sensors ss_eshim_x = [0.0,0.0,0.0] #Specify electronic shims (x-dir) for sun sensors ss_eshim_y = [0.0,0.0,0.0] #Specify electronic shims (y-dir) for sun sensors #Establish communication with IMU
#Define tracking/data collection parameters track_time = params.track_time #20 #number of seconds to capture data/track hz = params.hz #15 #data sample rate cnt = 0 delay = 1.0 / hz #Define directory to save data in save_dir = params.save_dir #'C:/git_repos/GLO/Tutorials/tracking/' #Obtain ephemeris data ep = ephem.Observer() #Establish communication with sun sensor/s - store in a list ss = [ SS(inst_id=params.ss1_inst_id, com_port=params.ss1_com_port, baudrate=params.ss1_baud_rate), SS(inst_id=params.ss2_inst_id, com_port=params.ss2_com_port, baudrate=params.ss2_baud_rate), SS(inst_id=params.ss3_inst_id, com_port=params.ss3_com_port, baudrate=params.ss3_baud_rate) ] #List of sun sensors to read data from (reduce number of sensors to increase sampling rate) ss_read = [2] #List of sun sensors to use for tracking ss_track = [] if params.ss1_track:
hz = 15 #data sample rate cnt = 0 delay = 1.0 / hz #Define directory to save data in save_dir = 'C:/git_repos/GLO/Tutorials/tracking/' #Obtain ephemeris data ep = ephem.Observer() #Establish communication with IMU #imu = IMU(com_port='COM7',baudrate=115200) #921600 #Establish communication with sun sensor/s - store in a list ss = [ SS(inst_id=1, com_port='COM6', baudrate=115200), SS(inst_id=2, com_port='COM8', baudrate=115200), SS(inst_id=3, com_port='COM4', baudrate=115200) ] #List of sun sensors to read data from ss_read = [1, 2, 3] #List of sun sensors to use for tracking ss_track = [1, 2, 3] # ss_eshim_x = [-1.763, -1.547, -1.578] #Specify electronic shims (x-dir) for sun sensors # ss_eshim_y = [-2.290, -2.377, -2.215] #Specify electronic shims (y-dir) for sun sensors ss_eshim_x = [0.0, 0.0, 0.0] #Specify electronic shims (x-dir) for sun sensors ss_eshim_y = [0.0, 0.0,