The MagPi Issue 22

Page 6

function that calculates the specific time durations from the imported sun azimuth tables. The durations are stored in the motor_time[ ] array. readDayData( )

Once the algorithm reaches the end of the imported file, the RST rotates CCW back to the home position so it is facing east the next day. For our data logging function, we used some of

the code from the Adafruit ADS1 x1 5 class combined with the Python threading class. The method itself is written as a thread that is kicked off in the main method. Once executed, the thread will open a new text file titled with the current date. Inside the file, the thread will log and timestamp data from inputs A1 and A2 every 1 0 seconds (0.1 Hz) until the daily tracking function ends and the thread stops.

i mport ti me, subprocess, threadi ng, dateti me, l oggi ng i mport RPi . GPIO as GPIO i mport numpy as np from Adafrui t_ADS1x15 i mport ADS1x15 # GPIO setup woul d go here #Returns the 3 l etter month abbrevi ati on of current month def getMonth(): temp = subprocess. Popen([" date" ] , stdout=subprocess. PIPE) date_stri ng = temp. communi cate()[0] t1, month, t2= date_stri ng. spl i t(' ' , 2) return month month_str = getMonth() fi l epath = ' /home/pi /RST/Months/' + month_str + ' . txt' rawData = np. l oadtxt(fi l epath, dtype=(str, fl oat), usecol s=(0, 2)) motor_const = 0. 462 # Uni ts of deg/sec based upon speed of motor angl e_deg = np. zeros((l en(rawData), 1), dtype=(fl oat)) motor_di r = np. zeros((l en(rawData), 1), dtype=(i nt)) motor_ti me = np. zeros((l en(rawData), 1), dtype=(i nt)) def readDayData(): z = 0 whi l e(z < l en(rawData)): l oop_ti me[z, 0] = i nt(convTi meSec(rawData[z, 0] )) i f(z == 0): i f(fl oat(rawData[z, 1] ) <= 90): angl e_deg[z, 0] = 90 - fl oat(rawData[z, 1] ) motor_di r[z, 0] = -1 motor_ti me[z, 0] = angl e_deg[z, 0] /motor_const el se: angl e_deg[z, 0] = fl oat(rawData[z, 1] ) - 90 motor_di r[z, 0] = 1 motor_ti me[z, 0] = angl e_deg[z, 0] /motor_const el se: angl e_deg[z, 0] = fl oat(rawData[z, 1] ) - fl oat(rawData[z-1, 1] ) motor_di r[z, 0] = 1 motor_ti me[z, 0] = angl e_deg[z, 0] /motor_const

z += 1

6


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.