def pre_run(): afe = atm90e26() afe.setup('spi') cfg = {k: base_config[k] for k in base_config} local_overrides = json.load(open('./device_params.json')) for k in local_overrides: cfg[k] = local_overrides[k] if cfg.get('calibration', None) is not None: afe.loadCalibration(cfg['calibration']) afe.reset() cfg['lights'] = Lights.Lights() cfg['afe'] = afe cfg['serial'] = getSerial() cfg['ips'] = getIPaddrs() sdn = sdnotify.SystemdNotifier() cfg['sdnotify'] = sdn sdn.notify('READY=1') i = iSetup(cfg) cfg['iconn'] = i return cfg
def get_request(): if request.method == 'POST': payload = request.get_json(silent=True) if 'plants' in payload: plants = Plants.Plants(payload) plants.handle_plants() if 'lights' in payload: lights = Lights.Lights(payload) lights.handle_lights() else: print ('nothing in the payload') #print ("Got data: " + str(payload)) return {'succeeded with query' : str(payload)}
def __init__(self): ip = "0.0.0.0" port = 8005 self._topcommunicator = TcpCommunicator(ip, port, bind=True) self._botcommunicator = I2cCommunicator() self._myhardware = Hardware(self._botcommunicator) #===============AVR self._Avr1address = 6 self._Avr2address = 7 self._myhardware.addAVR(self._Avr1address) self._myhardware.addAVR(self._Avr2address) #===============Devices motorsbasepwm = 1440 zero = 0 cameraservobase = 1500 RGBwhite = 7 self._myhardware._avrList[0].addDevice("Front_Right_Thruster", motorsbasepwm, 2) self._myhardware._avrList[0].addDevice("Front_Left_Thruster", motorsbasepwm, 2) self._myhardware._avrList[0].addDevice("Back_Right_Thruster", motorsbasepwm, 2) self._myhardware._avrList[0].addDevice("Back_Left_Thruster", motorsbasepwm, 2) self._myhardware._avrList[0].addDevice("Up_Front_Thruster", motorsbasepwm, 2) self._myhardware._avrList[0].addDevice("Up_Back_Thruster", motorsbasepwm, 2) self._myhardware._avrList[0].addDevice("DC", zero, 1) self._myhardware._avrList[1].addDevice("Camera_Servo", cameraservobase, 2) self._myhardware._avrList[1].addDevice("LED", RGBwhite, 1) self._myhardware._avrList[1].addDevice("Cycle_Flag", zero, 1) #=============Components #identifiers must be in the form of a list self._rovmanipulator = Manipulator(self._myhardware, {"grip": 0}) self._rovLights = Lights(self._myhardware, {"led": 7}) self._rovCamera = Camera(self._myhardware, {"cam": 0}) self._rovmotion = Motion(self._myhardware, { "x": 0, "y": 0, "z": 0, "r": 0, "currentmode": "normal" }) modules = [ self._rovmanipulator, self._rovLights, self._rovCamera, self._rovmotion ] #=============PostOffcie self.mypostoffice = PostOffice() for module in modules: self.mypostoffice.registerEventListner("TCP", module.mail) self.mypostoffice.registerEventListner("TCP ERROR", module.mail) self.mypostoffice.registerEventListner("I2C", self._rovmanipulator.mail) self.mypostoffice.registerEventListner( "I2C", self._myhardware._avrList[1].mail) self.mypostoffice.registerEventListner( "I2C", self._myhardware._avrList[0].mail) self.mypostoffice.registerEventListner("Sensors", self._topcommunicator._send) self._topcommunicator.registerCallBack(self.mypostoffice.triggerEvent) #=============Sensors # self._mysensors=SensorRegistry() # self._mysensors.registerSensor(sensor) # self._mysensors.registerCallBack(self.mypostoffice.triggerEvent) #=====intterupts self._interruptor = Interrupt() self._interruptor.register(23, False, self.mypostoffice.triggerEvent, "I2C") self._topcommunicator._mainLoop()