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 main(): try: opts, args = getopt.getopt( sys.argv[1:], "h", ["help", "name=", "task=", "show-config", "reboot", "test"]) except getopt.GetoptError as err: print("Error: ", err) sys.exit(2) name = None tasks = [] for o, a in opts: if o in "--reboot": Control.rebootXPS() sys.exit() elif o in "--name": name = a elif o in "--test": task = os.path.dirname( os.path.abspath(__file__)) + "\\tasks\\" + "test.json" name = "test" if os.path.exists(task): tasks.append(task) else: logger.error("Task test task does'nt exist!") elif o in "--task": if not os.path.isabs(a): a = os.path.dirname( os.path.abspath(__file__)) + "\\tasks\\" + a for i in a.split(','): t = i + '.json' if os.path.exists(t): tasks.append(t) else: logger.error("Task file %s does'nt exist!", a) elif o in "--show-config": print(vars(Config)) else: usage() sys.exit(2) if len(tasks) < 1: usage() sys.exit() for t in tasks: Control.start(t, name)
class controlThread(QtCore.QThread): 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 run(self): # print("start controlThread") while self.running: if not control_q.empty(): # print("got cmd windows data") cmd_all_list=control_q.get() self.runed_looptimes=cmd_all_list[0] self.loopflag=True while self.loopflag: for t in range(self.runed_times,self.runed_looptimes): #循环次数 # print(self.flag) if self.flag: if self.running: counts=t+1 self.emit(QtCore.SIGNAL("getcounts(QString)"),_fromUtf8(str(counts))) for i in range(1,(len(cmd_all_list))): msg_list=cmd_all_list[i] dev_class_type=msg_list[0] cmd_list=msg_list[1] self.control_instance.devices_c(dev_class_type,cmd_list) # print("send control cmd to server") else: break else: self.runed_times=t break if self.flag: self.loopflag=False else: self.loopflag=True def pause(self): self.flag=False def resume(self): self.running=True self.loopflag=True #用于循环暂停 self.flag=True def stop(self): self.loopflag=True #用于循环暂停 self.flag=True # 将线程从暂停状态恢复, 如何已经暂停的话 self.running=False self.runed_times=0 #用于记录暂停前的执行的次数 self.runed_looptimes=1 #用于记录暂停前要循环执行的次数
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): 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 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 __init__(self, path, flags, *mode): self.control = Control.getInstance() print "attempting to open path: %s" % (path) base, name = os.path.split(path) print "makedirs: %s" % (base) os.makedirs(base) print path, flag2mode(flags) self.file = open(path, flag2mode(flags)) self.fd = self.file.fileno()
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, 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 = 'shooter3.png' #pygame.mixer.init() #pygame.mixer.music('display/sounds/background.wav') #pygame.mixer.music.play() sound_path = os.path.join('display', 'sounds', 'bac2.wav') pygame.mixer.Sound(sound_path).play(-1) return
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 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): 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()
class PygameClient(PygameSocketGame): """ This class connects the control and display for the game. You shouldn't need to make changes here. """ 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 game_logic(self, keys, newkeys, buttons, newbuttons, mouse_position): self.control.control(self.engine, keys, newkeys, buttons, newbuttons, mouse_position) if self.control.get_state() == CONTROL_STATE_WANT_DUAL: self.new_game(game_engine.MODE_DUAL) elif self.control.get_state() == CONTROL_STATE_WANT_SINGLE: self.new_game(game_engine.MODE_SINGLE) elif self.control.get_state() == CONTROL_STATE_WANT_TOURNAMENT: self.new_game(game_engine.MODE_TOURNAMENT) elif self.control.get_state() == CONTROL_STATE_WANT_VIEW: self.new_game(game_engine.MODE_VIEW) if self.engine and self.engine.get_data().get_game_over(): self.game_over_pause += 1 if self.game_over_pause > self.frames_per_second * POST_GAME_WAIT_TIME: self.disconnect_from_server() self.set_engine(None) return def paint(self, surface): self.display.paint(surface, self.engine, self.control) return def new_game(self, mode): self.set_engine(ClientGameEngine(self.name, mode)) self.disconnect_from_server() self.connect_to_server() self.game_over_pause = 0 return
class PygameClient(PygameSocketGame): """ This class connects the control and display for the game. You shouldn't need to make changes here. """ 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 = 'shooter3.png' #pygame.mixer.init() #pygame.mixer.music('display/sounds/background.wav') #pygame.mixer.music.play() sound_path = os.path.join('display', 'sounds', 'bac2.wav') pygame.mixer.Sound(sound_path).play(-1) return def game_logic(self, keys, newkeys, buttons, newbuttons, mouse_position): self.control.control(self.engine, keys, newkeys, buttons, newbuttons, mouse_position) if self.control.get_state() == CONTROL_STATE_WANT_DUAL: self.new_game(game_engine.MODE_DUAL) elif self.control.get_state() == CONTROL_STATE_WANT_SINGLE: self.new_game(game_engine.MODE_SINGLE) elif self.control.get_state() == CONTROL_STATE_WANT_TOURNAMENT: self.new_game(game_engine.MODE_TOURNAMENT) elif self.control.get_state() == CONTROL_STATE_WANT_VIEW: self.new_game(game_engine.MODE_VIEW) if self.engine and self.engine.get_data().get_game_over(): self.game_over_pause += 1 if self.game_over_pause > self.frames_per_second * POST_GAME_WAIT_TIME: self.disconnect_from_server() self.set_engine(None) return def paint(self, surface): self.display.paint(surface, self.engine, self.control) return def new_game(self, mode): self.set_engine(ClientGameEngine(self.name, mode)) self.disconnect_from_server() self.connect_to_server() self.game_over_pause = 0 return
class PygameClient(PygameSocketGame): """ This class connects the control and display for the game. You shouldn't need to make changes here. """ 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 game_logic(self, keys, newkeys, buttons, newbuttons, mouse_position): self.control.control(self.engine, keys, newkeys, buttons, newbuttons, mouse_position) if self.control.get_state() == CONTROL_STATE_WANT_DUAL: self.new_game(game_engine.MODE_DUAL) elif self.control.get_state() == CONTROL_STATE_WANT_SINGLE: self.new_game(game_engine.MODE_SINGLE) elif self.control.get_state() == CONTROL_STATE_WANT_TOURNAMENT: self.new_game(game_engine.MODE_TOURNAMENT) elif self.control.get_state() == CONTROL_STATE_WANT_VIEW: self.new_game(game_engine.MODE_VIEW) #elif self.control.get_state() == CONTROL_STATE_WANT_SELECT: self.new_game(game_engine.MODE_SELECT) if self.engine and self.engine.get_data().get_game_over(): self.game_over_pause += 1 if self.game_over_pause > self.frames_per_second * POST_GAME_WAIT_TIME: self.disconnect_from_server() self.set_engine(None) return def paint(self, surface): self.display.paint(surface, self.engine, self.control) return def new_game(self, mode): self.set_engine(ClientGameEngine(self.name, mode)) self.disconnect_from_server() self.connect_to_server() self.game_over_pause = 0 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()
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
import time import os import sys from control.control import Control from control import Control c = Control() stop_distance = 20 # Drive arounf em301 if __name__ == '__main__': c.turnTo(-136) c.driveForwardUntilWall(30) c.turnRight90Degrees() c.turnLeft90Degrees() c.driveBackwardUntilWall(30)
#! /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'
def __init__(self): """ Initializes the aap and creates an control instance """ super().__init__(sys.argv) self.c = Control()
def __init__(self, *args, **kw): Fuse.__init__(self, *args, **kw) self.root = '/' #self.file_class = FuseBaffsFile self.control = Control.getInstance()
class NdControl(): 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() def cb_mode(self, msg_mode): self.mode = msg_mode.value rospy.loginfo('Mode: ' + str(self.mode)) def cb_control(self, msg_control): self.power = msg_control.power self.setpoint = msg_control.setpoint Kp = msg_control.kp Ki = msg_control.ki Kd = msg_control.kd self.control.pid.set_setpoint(self.setpoint) self.control.pid.set_parameters(Kp, Ki, Kd) rospy.loginfo('Params: ' + str(msg_control)) def cb_geometry(self, msg_geo): time = msg_geo.header.stamp.to_sec() if self.mode == MANUAL: value = self.control.pid.power(self.power) self.msg_power.value = value elif self.mode == AUTOMATIC: minor_axis = msg_geo.minor_axis if minor_axis > 0.5: value = self.control.pid.update(minor_axis, time) else: value = self.control.pid.power(self.power) self.msg_power.value = value else: major_axis = msg_geo.major_axis if major_axis: value = self.control.pid.update(major_axis, time) else: value = self.control.pid.power(self.power) self.msg_power.value = value print '# Timestamp', time, '# Power', self.msg_power.value self.pub_power.publish(self.msg_power)
class NdControl(): 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() def cb_mode(self, msg_mode): self.mode = msg_mode.value rospy.loginfo('Mode: ' + str(self.mode)) def cb_control(self, msg_control): self.power = msg_control.power self.setpoint = msg_control.setpoint Kp = msg_control.kp Ki = msg_control.ki Kd = msg_control.kd self.control.pid.set_setpoint(self.setpoint) self.control.pid.set_parameters(Kp, Ki, Kd) rospy.loginfo('Params: ' + str(msg_control)) def cb_geometry(self, msg_geo): time = msg_geo.header.stamp.to_sec() if self.mode == MANUAL: value = self.control.pid.power(self.power) self.msg_power.value = value elif self.mode == AUTOMATIC: minor_axis = msg_geo.minor_axis if minor_axis > 0.5: value = self.control.pid.update(minor_axis, time) else: value = self.control.pid.power(self.power) self.msg_power.value = value else: major_axis = msg_geo.major_axis if major_axis: value = self.control.pid.update(major_axis, time) else: value = self.control.pid.power(self.power) self.msg_power.value = value print '# Timestamp', time, '# Power', self.msg_power.value self.pub_power.publish(self.msg_power)
# 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")
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 sys from control.control import Control from control import Control c = Control() if __name__ == "__main__": try: c.driveStraight(50, 13) # 50% speed for 11.5s c.turnRight90Degrees() c.driveStraight(50, 15) c.turnRight90Degrees() except KeyboardInterrupt: c.motors.stop()