def executeIOInteraction(self, intId, instruction): instElems = instruction.split(":", ) if instElems[0] == "i2c": if instElems[1] == "pwm": if instElems[2] == 'dir': if cc_configuration.isHardwareSupported(): self.pwm.set_pwm( cc_configuration.CAR_STEER_PWM_CHANNEL, 0, self.calculateServoPWMValue(instElems[3])) logging.debug( intId + ' EXECUTE I2C-PCA9685 STEER: ' + str(cc_configuration.CAR_STEER_PWM_CHANNEL) + ' Value: ' + str(self.calculateServoPWMValue(instElems[3]))) if instElems[2] == 'thr': if cc_configuration.isHardwareSupported(): self.pwm.set_pwm( cc_configuration.CAR_THROTTLE_PWM_CHANNEL, 0, self.calculateThrottlePWMValue(instElems[3])) logging.debug( intId + ' EXECUTE I2C-PCA9685 THROTTLE: ' + str(cc_configuration.CAR_STEER_PWM_CHANNEL) + ' Value: ' + str(self.calculateServoPWMValue(instElems[3]))) logging.debug(intId + ' EXECUTE I2C-PCA9685 Channel: ' + str(instElems[2]) + ' Value: ' + str(instElems[3])) if instElems[1] == "oled": if cc_configuration.isHardwareSupported(): self.oled.writeText(instElems[2]) elif instElems[0] == "gpio": if instElems[1] == "pin": #print "EXECUTE GPIO PIN CHANGE" #convert to pin number here #gpo operation logging.debug(intId + ' EXECUTE GPIO-PIN Number: ' + str(instElems[2]) + ' Value: ' + str(instElems[3])) else: print "Message Unrecognized - IGNORE"
def readSystemMetrix(self): if cc_configuration.isHardwareSupported(): #cmd =["vcgencmd measure_temp | egrep -o '[0-9]*\.[0-9]*'"] cmd = [ "vcgencmd measure_temp | egrep -o '[0-9]*\.' | egrep -o '[0-9]*'" ] address = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) (out, err) = address.communicate() system_data = {"core_temp": int(out), "cpu_util": 34} self.sensors['system'] = system_data self.sensors['system_flt'] = self.filterSystemReading(system_data) else: static_system_data = {"core_temp": 33.05555555555, "cpu_util": 34} self.sensors['system'] = static_system_data self.sensors['system_flt'] = self.filterSystemReading( static_system_data)
def __init__(self): self.read_sensor_cycle_timer = 0 self.sensors = {} self.control = {} self.sensorCycle = [1, 0, 0] self.kf = EWMAFilter() self.filtersSMA = {} self.filtersEWMA = {} self.pwm = None self.oled = None self.accelerometer = None self.power = None self.sonar = None self.sonar = cc_uart_prox_HCSR04Array() print "Hardware Init" if cc_configuration.isHardwareSupported(): self.pwm = cc_i2c_pwm_PCA9685() self.oled = cc_i2c_oled_SSD1306() self.accelerometer = cc_i2c_accel_MPU6050() self.power = cc_i2c_adc_ADS1115() self.sonar = cc_uart_prox_HCSR04Array()
def readSensorsI2C(self): if cc_configuration.isHardwareSupported(): accelerometer_data = self.accelerometer.getData() power_data = self.power.getPowerData() self.sensors['accel'] = accelerometer_data self.sensors['power'] = power_data self.sensors['accel_flt'] = self.filterAccelerometerReading( accelerometer_data) self.sensors['power_flt'] = self.filterPowerReading(power_data) else: self.sensors['accel'] = { 'x': -1.7860744384765623, 'y': -9.016563452148437, 'z': 2.205059729003906 } self.sensors['power'] = { "battery_volt": 8.1, "pi_volt": 5.1, "pi_current": 1.6 } self.sensors['accel_flt'] = self.filterAccelerometerReading({ 'x': -1.7860744384765623, 'y': -9.016563452148437, 'z': 2.205059729003906 }) self.sensors['power_flt'] = self.filterPowerReading({ "battery_volt": 7.5, "pi_volt": 5.1, "pi_current": 3.2 })
def readSensors1W(self): if cc_configuration.isHardwareSupported(): self.sensors['1w'] = "" else: self.sensors['1w'] = {'sensor1': 23}
def readSensorsGPS(self): if cc_configuration.isHardwareSupported(): self.sensors['gps'] = {"qqq": "dds"} else: self.sensors['gps'] = {"qqq": "dds"}
import logging import random import string import os import time import subprocess import cc_configuration from cc_sensor_filters import * import json from cc_uart_prox_HCSR04Array import cc_uart_prox_HCSR04Array if cc_configuration.isHardwareSupported(): #import Adafruit_PCA9685 #from mpu6050 import mpu6050 from cc_i2c_pwm_PCA9685 import cc_i2c_pwm_PCA9685 from cc_i2c_accel_MPU6050 import cc_i2c_accel_MPU6050 from cc_i2c_oled_SSD1306 import cc_i2c_oled_SSD1306 from cc_i2c_adc_ADS1115 import cc_i2c_adc_ADS1115 from cc_uart_prox_HCSR04Array import cc_uart_prox_HCSR04Array logging.basicConfig( level=logging.DEBUG, format='(%(threadName)-9s) %(message)s', ) #Hardware init #READ_SENSORS_CYCLE_SKIP = 4000000
def fetchNetworkData(self): if cc_configuration.isHardwareSupported(): return self.fetchIP() + ";" + self.fetchAPR_Pi() else: return self.fetchIP() + ";" + self.fetchAP()