コード例 #1
0
import board
import busio
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
import time
import json
from mqtt_client.publisher import Publisher

i2c = busio.I2C(board.SCL, board.SDA)

ads = ADS.ADS1115(i2c)
ads.gain = 1
chan = AnalogIn(ads, ADS.P0)

pubber = Publisher(client_id="adc-values")


def publish_compas_status():
    message = {
        'value': chan.value,
        'voltage': chan.voltage,
    }
    print(json.dumps(message))
    app_json = json.dumps(message)
    pubber.publish("/status/adc", app_json)


try:
    while True:
        publish_adc_status()
        time.sleep(1)
コード例 #2
0
jet2_current = 0 #port
pack_voltage = 0
vector = 0
magnitude = 0
gyro_z = 0
kalman_lp = 0
kalman = 0

logging_stopped=False
prev_name = None
cur_name = None

# Base Name for Log files
_LOG_BASE = "log"

pubber = Publisher(client_id="logger-pubber")
exists = False

def on_log_received(client, userdata, message):
    global _LOG_BASE
    global exists

    log_title = message.payload.decode("utf-8")
    time = datetime.today()
    log_time = (
        f"{time.year}-{time.month}-{time.day}-{time.hour}:{time.minute}:{time.second}"
    )
    _LOG_BASE = log_title + "_" + log_time
    print("received")
    exists = True
    
コード例 #3
0
from tkinter import *
import tkinter as tk
import tk_tools
from mqtt_client.publisher import Publisher

pubber = Publisher(client_id="log_command", broker_ip="192.168.1.170")
stop = False


class Application(tk.Frame):
    #GUI

    def __init__(self, master):
        tk.Frame.__init__(self, master)
        self.grid()
        self.create_widgets()
        # self.updater()

    def create_widgets(self):
        global stop

        # Pack Voltage Gauge
        self.pvgauge = tk_tools.Gauge(self,
                                      height=200,
                                      width=400,
                                      min_value=10,
                                      max_value=20,
                                      label='Pack Voltage',
                                      unit=' V',
                                      divisions=30,
                                      yellow=66,
コード例 #4
0
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
 
base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + w1_slave'

# Setup ADC Sensor
i2c = busio.I2C(board.SCL, board.SDA)

ads = ADS.ADS1115(i2c)
ads.gain = 1
chan = AnalogIn(ads, ADS.P0)
chan2 = AnalogIn(ads,ADS.P1)
# Setup Pubber
pubber = Publisher(client_id="jet-pubber")

def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    f.close()
    return lines
 
def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
コード例 #5
0
ファイル: pubber.py プロジェクト: rwm-boat/coms-common
from mqtt_client.publisher import Publisher
import time

# ==================
# -- MAIN METHOD --
# ==================
if __name__ == '__main__':

    pubber = Publisher(client_id="time_pubber", broker_ip="192.168.1.170")

    while (True):
        milli = time.time() * 1000
        pubber.publish("/status/time", str(milli))
        #time.sleep(.01)
コード例 #6
0
ファイル: vector_pub.py プロジェクト: rwm-boat/nav-firmware
import math
import gps_pub
from haversine import haversine,Unit
import numpy as np
import nvector as nv
from mqtt_client.publisher import Publisher
import time
import json

# Setup publisher
pubber = Publisher(client_id="vector-pubber")

#vector math
wgs84 = nv.FrameE(name='WGS84')
distance = 0

def publish_vector():

	global distance
	# --------- CONSTANTS ---------
	# 5 - full chat
	# 4 - comfortable planning
	# 3 - min-plane-speed
	# 2 - max efficency displacement
	# 1 - low speed trolling
	# 0 - stop
	FULL_CHAT = 0.5 # ~ 100 meters
	PLANE = 0.5 
	MIN_PLANE = 0.5
	MAX_EFFICENCY = 0.00674946 # ~ 25m
	TROLL = 0.008 # ~ 15m radius
コード例 #7
0
ファイル: nav-testing.py プロジェクト: rwm-boat/nav-firmware
#calibration function values
ext_magXmin = 0
ext_magYmin = 0
ext_magXmax = 0
ext_magYmax = 0
ext_magZmax = 0
ext_magZmin = 0

IMU.detectIMU()  #Detect if BerryIMUv1 or BerryIMUv2 is connected.
IMU.initIMU()  #Initialise the accelerometer, gyroscope and compass

a = datetime.datetime.now()

# Setup publisher
pubber = Publisher(client_id="nav-pubber")

speed = 0
current_lat = 0
current_lon = 0

#vector math
wgs84 = nv.FrameE(name='WGS84')
distance = 0


def publish_gps_status():
    global prev_pos
    global current_pos
    global total_distance
    global distance_traveled
コード例 #8
0
ファイル: compass_pub.py プロジェクト: rwm-boat/nav-firmware
gyroXangle = 0.0
gyroYangle = 0.0
gyroZangle = 0.0
CFangleX = 0.0
CFangleY = 0.0

i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_lsm9ds0.LSM9DS0_I2C(i2c)

M_PI = 3.14159265358979323846
G_GAIN = 0.070
RAD_TO_DEG = 57.29578
AA = 0.40  # Complementary filter constant

pubber = Publisher(client_id="compass-pubber")

a = datetime.datetime.now()

current = 0
previous = 0

### sqrt of the variance is the error distance (aka. meters or degrees) ###
# how much error there is in the process model (how much do we trust the model)
process_var = 4.
# how much error there is in each sensor measurement (how much do we trust the sensor)
sensor_var = .3

## Initial State ##
# [position, variance, sensor_var] sensor state
# [(meters, degrees), (meters, degrees), ] ## remember sqrt of variance is distance error
コード例 #9
0
a = datetime.datetime.now()


def getCurLat():
    return lat


def getCurLon():
    return lon


def getCurSpeed():
    return speed


pubber = Publisher(client_id="gps-values")

try:

    while True:
        report = gpsd.next()
        if report['class'] == 'TPV':
            lat = getattr(report, 'lat', 0.0)
            lon = getattr(report, 'lon', 0.0)
            speed = getattr(report, 'speed', 'nan')

        time.sleep(.2)

        #  #Read the accelerometer,gyroscope and magnetometer values
        # ACCx = IMU.readACCx()
        # ACCy = IMU.readACCy()
コード例 #10
0
from gps3.agps3threaded import AGPS3mechanism
import time
import json
from mqtt_client.publisher import Publisher

agps_thread = AGPS3mechanism()  # Instantiate AGPS3 Mechanisms
agps_thread.stream_data()  # From localhost (), or other hosts, by example, (host='gps.ddns.net')
agps_thread.run_thread()  # Throttle time to sleep after an empty lookup, default '()' 0.2 two tenths of a second

pubber = Publisher(client_id="gps-values")

def publish_gps_status():
    message = {
        'time' :  agps_thread.data_stream.time,
        'latitude' : agps_thread.data_stream.lat,
        'longitude' : agps_thread.data_stream.lon,
        'speed (m/s)' : agps_thread.data_stream.speed,
        'speed (kn)' : agps_thread.data_stream.speed * 1.943844,
        'course': agps_thread.data_stream.track
    }

    app_json = json.dumps(message)
    pubber.publish("/status/gps",app_json)
    time.sleep(0.1)

while True:  # All data is available via instantiated thread data stream attribute.
    publish_gps_status()



コード例 #11
0
from mqtt_client.publisher import Publisher
import json

pubber = Publisher(client_id="log_command", broker_ip="192.168.8.170")

while True:
    # Wait for the broker to retur the message
    command = str.lower(input("Enter the log filename base, `start`, or `stop` : "))

    # Check the start stop function
    if command == 'start':
        message = {
            'running': 1
        }
        print('Starting the Logger')
        pubber.publish("/command/log/startstop", json.dumps(message))
    elif command == 'stop':
        message = {
            'running': 0
        }
        print('Stopping the Logger')
        pubber.publish("/command/log/startstop", json.dumps(message))
    else:
        message = {
            'name': str(command)
        }
        print('Renaming the Log')
        pubber.publish("/command/log/name", json.dumps(message))


コード例 #12
0
agps_thread.stream_data(
)  # From localhost (), or other hosts, by example, (host='gps.ddns.net')
agps_thread.run_thread(
)  # Throttle time to sleep after an empty lookup, default '()' 0.2 two tenths of a second

#global variables
speed = 0
current_lat = 0
current_lon = 0
distance_traveled = 0
total_distance = 0
current_pos = (0, 0)
prev_pos = (0, 0)

# Setup publisher
pubber = Publisher(client_id="gps-pubber")


def publish_gps_status():
    global prev_pos
    global current_pos
    global total_distance
    global distance_traveled
    global speed
    global current_lat
    global current_lon

    try:
        # determine if real values are being produced, convert to knots, then calculate distance traveled
        if (agps_thread.data_stream.speed != 'n/a'
                and agps_thread.data_stream.speed != 0):
コード例 #13
0
import time
import numpy
import board
import busio
import json
from mqtt_client.publisher import Publisher

import adafruit_lsm9ds0

# I2C connection:
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_lsm9ds0.LSM9DS0_I2C(i2c)
pubber = Publisher(client_id="compass-values")


def publish_compas_status():
    mag_x, mag_y, mag_z = sensor.magnetic
    temp = sensor.temperature
    compass = round(-(24 + numpy.degrees(numpy.arctan2(mag_x, mag_y))))

    if compass < 0:
        compass = 360 + compass
    message = {
        'temp': temp,
        'compass': compass,
    }
    print(json.dumps(message))
    app_json = json.dumps(message)
    pubber.publish("/status/compass", app_json)