def __init__(self): rospy.init_node('control') rospy.Subscriber('/tachyon/geometry', MsgGeometry, self.cb_geometry, queue_size=1) rospy.Subscriber('/control/mode', MsgMode, self.cb_mode, queue_size=1) rospy.Subscriber('/control/parameters', MsgControl, self.cb_control, queue_size=1) rospy.Subscriber('/supervisor/status', MsgStatus, self.cb_status, queue_size=1) self.pub_power = rospy.Publisher('/control/power', MsgPower, queue_size=10) self.msg_power = MsgPower() self.mode = MANUAL self.status = False self.time_step = None self.control = Control() self.updateParameters() self.setPowerParameters(rospy.get_param('/control/power')) self.control.pid.set_limits(self.power_min, self.power_max) self.control.pid.set_setpoint(self.setpoint) rospy.spin()
def trigger_post(action=None): data = request.get_json(force=True) key = data['key'] if 'key' in data else None durationInMinutes = data[ 'durationInMinutes'] if 'durationInMinutes' in data else None deviceName = data['deviceName'] if 'deviceName' in data else None targetState = data['targetState'] if 'targetState' in data else False if (key is None) or (durationInMinutes is None) or (deviceName is None): return jsonify({"statusCode": 400, "message": "Missing data"}), 400 if key != config['SECURITY_KEY']: return jsonify({"statusCode": 403, "message": "Unauthorised"}), 403 print("New action ({}) on {} in {} minutes".format( ('on' if targetState else 'off'), deviceName, durationInMinutes)) durationInSeconds = int(durationInMinutes) * 60 control = Control(deviceName, config['IFTTT']) if targetState: control.off_to_on(durationInSeconds) elif not targetState: control.on_to_off(durationInSeconds) else: return jsonify({ "statusCode": 400, "message": "Wrong 'targetState' option" }), 400 return jsonify({"statusCode": 200})
def __init__(self): QtCore.QThread.__init__(self) self.control_instance=Control() self.running=True #用于停止线程 self.flag=True #用于暂停线程 self.runed_times=0 #用于记录暂停前的执行的次数 self.runed_looptimes=1 #用于记录暂停前要循环执行的次数 self.loopflag=True #用于循环暂停
def create_control(self, control_json, addon): control = Control(control_json, addon) collection = self.controls try: collection.insert(control.__dict__) except errors.DuplicateKeyError as e: print(e)
def main(): try: opts, args = getopt.getopt( sys.argv[1:], "hs:lL:n:t:", ["help", "server=", "localhost", "logging=", "name=", "title="]) except getopt.GetoptError as e: print(str(e)) usage() sys.exit(1) show_help = False server = "rookie.cs.dixie.edu" name = DEFAULT_TEAM_NAME title = DEFAULT_GAME_TITLE logging_level = "error" for o, a in opts: if o in ("-h", "--help"): show_help = True elif o in ("-s", "--server"): server = a elif o in ("-l", "--localhost"): server = "127.0.0.1" elif o in ("-L", "--logging"): logging_level = a elif o in ("-n", "--name"): name = a elif o in ("-t", "--title"): title = a else: print("Unexpected option: %s" % (o)) usage() sys.exit(1) if show_help: usage() sys.exit(1) if logging_level == "info": logging.basicConfig(level=logging.INFO) elif logging_level == "debug": logging.basicConfig(level=logging.DEBUG) elif logging_level == "warning": logging.basicConfig(level=logging.WARNING) elif logging_level == "error": logging.basicConfig(level=logging.ERROR) else: logging.basicConfig(level=logging.ERROR) display = Display(WINDOW_WIDTH, WINDOW_HEIGHT) control = Control(WINDOW_WIDTH, WINDOW_HEIGHT) g = PygameClient(display, control, WINDOW_WIDTH, WINDOW_HEIGHT, FRAMES_PER_SECOND, name, title, server) g.main_loop() return
def __init__(self): """ Initializes the app and creates an control instance """ super().__init__(sys.argv) self.control = Control() while self.control.view.isVisible(): self.control.view.update() self.processEvents() sys.exit()
def main(): """ CONTROL """ # Start the control control_thread = Control(name="ControlThread") control_thread.start() """ GUI """ # S E T U P root = tk.Tk() # S T A R T pro_gui = PROTrainerGUI(root=root, control_thread=control_thread) pro_gui.mainloop()
def __init__(self, width, height, frame_rate, name, title, server_host="localhost", server_port=20149): PygameSocketGame.__init__(self, title, width, height, frame_rate, server_host, server_port) self.name = name self.display = Display(width, height) self.control = Control(width, height) self.control.player_image = "duck2.png" # music_path = os.path.join('display', 'music', 'LukHash_-_ARCADE_JOURNEYS.wav') # pygame.mixer.music(music_path).play(-1) return
def __init__(self): rospy.init_node('control') rospy.Subscriber('/tachyon/geometry', MsgGeometry, self.cb_geometry, queue_size=1) rospy.Subscriber('/control/mode', MsgMode, self.cb_mode, queue_size=1) rospy.Subscriber('/control/parameters', MsgControl, self.cb_control, queue_size=1) self.pub_power = rospy.Publisher('/control/power', MsgPower, queue_size=10) power_min = rospy.get_param('~power_min', 0.0) power_max = rospy.get_param('~power_max', 1500.0) power = rospy.get_param('~power', 1000) setpoint = rospy.get_param('~setpoint', 3.0) Kp = rospy.get_param('~Kp', 5.0) Ki = rospy.get_param('~Ki', 100.0) Kd = rospy.get_param('~Kd', 0.0) print 'Kp:', Kp, 'Ki:', Ki, 'Kd', Kd self.msg_power = MsgPower() self.msg_labjack = MsgLabJack() self.mode = MANUAL self.power = power self.setpoint = setpoint self.control = Control() self.control.load_conf(os.path.join(path, 'config/control.yaml')) self.control.pid.set_limits(power_min, power_max) self.control.pid.set_setpoint(self.setpoint) rospy.spin()
except queue.Empty: break if __name__ == '__main__': pid = os.getpid() print('seedling: pid %d' % pid) with open(PID_FILE, 'w') as f: f.write(str(pid)) msg_queue = Queue() rsp_queue = Queue() app.config['msg_queue'] = msg_queue app.config['rsp_queue'] = rsp_queue control = Control(msg_queue, rsp_queue) control_proc = Process(target=control.main_loop, daemon=False) control_proc.start() # print('seedling: control process started, daemon: %s' % control_proc.daemon) # serve(app, listen='0.0.0.0:8080') web_proc = Process(target=serve, args=(app, ), kwargs={'listen': '0.0.0.0:8080'}, daemon=False) web_proc.start() # print('seedling: web process started, daemon: %s' % web_proc.daemon)
# Import from control.control import Control # Variabili boolD = False # Funzioni if __name__ == '__main__': if boolD: print("Inizio Programma\n") Control() if boolD: print("\nFine Programma")
def __init__(self, width, height, frame_rate, name, title, server_host="localhost", server_port=20149): PygameSocketGame.__init__(self, title, width, height, frame_rate, server_host, server_port) self.name = name self.display = Display(width, height) self.control = Control(width, height) return
def __init__(self): """ Initializes the aap and creates an control instance """ super().__init__(sys.argv) self.c = Control()
#! /usr/bin/python import sys from PyQt4 import QtGui from gui.gui import Gui from gui.threadgui import ThreadGui from control.control import Control from control.threadcontrol import ThreadControl import signal signal.signal(signal.SIGINT, signal.SIG_DFL) if __name__ == '__main__': control = Control() app = QtGui.QApplication(sys.argv) print 'app creada' window = Gui() window.setControl(control) window.show() print 'window' t1 = ThreadControl(control) t1.start() print 'threadcontrol' t2 = ThreadGui(window) t2.start() print 'threadgui'