Skip to content

Instantly share code, notes, and snippets.

@dmalawey
Created October 8, 2019 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmalawey/d82cdece2fbd93b607b432eaf9b2d416 to your computer and use it in GitHub Desktop.
Save dmalawey/d82cdece2fbd93b607b432eaf9b2d416 to your computer and use it in GitHub Desktop.
Telemetry outputs from SCUTTLE to nodeRed
# data output functions to txt files for NodeRed and MQTT
# Import external programs
import numpy as np # for array manipulation
import time # for keeping time
# Import internal programs
import L1_encoder as enc
import L2_log as log
import L2_heading as head
import L1_bmp as bmp
import L2_kinematics as kin
import L1_gamepad as gp
import L1_adc as adc
while 1:
axes = head.getXY()
myAxes = np.take(axes, [0,1]) # take only the first two elements
myAxes = head.scale(myAxes) # scale based on calibration. Returns each axis' ratio to it's max
myAxes = np.round(myAxes, 3) # round the result
log.NodeRed2(myAxes) # log the values to NodeRed via files a.txt and b.txt
arcTan = np.round((np.arctan2(myAxes[0], myAxes[1])) * (180 / 3.14),2) # arctan2 returns 4 quadrants of info
log.uniqueFile(arcTan, "c.txt") # arguments: 1 value and name of file, "c.txt"
#print("my Axes", myAxes, "arctan:", arcTan)
time.sleep(0.2)
# SECTION FOR LOGGING ENCODERS
encoders = enc.read()
encoders = np.round((encoders *(359 / 2**14)), 2) # scale values to get degrees
log.uniqueFile(encoders[0], "encL.txt")
log.uniqueFile(encoders[1], "encR.txt")
#print("encoders", encoders)
# SECTION FOR READING AIR PRESSURE
p = bmp.pressure()
t = bmp.temp()
log.uniqueFile(p, "p.txt")
log.uniqueFile(t, "t.txt")
# SECTION FOR READING kinematics
B = kin.getPdCurrent() # Grab XD, TD
# print("XD, TD:", C)
# Log Phi Dots
log.uniqueFile(B[0], "pdl.txt")
log.uniqueFile(B[1], "pdr.txt")
C = kin.getMotion() # Grab PDs
# Log XD, TD
log.uniqueFile(C[0], "xdot.txt")
log.uniqueFile(C[1], "tdot.txt")
# SECTION FOR READING GAMEPAD
myGP = gp.getGP()
fwd1 = myGP[2]
log.uniqueFile(fwd1, "gpup.txt")
# SECTION FOR MQTT OUTPUTS
battV = adc.getDcJack()
log.uniqueFile(battV, "batt_v.txt")
low = 9.0
high = 12.6
battP = round((battV - low) / ( high - low ),3)*100 # calculate battery percentage
log.uniqueFile(battP, "batt_p.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment