Esempio n. 1
0
 def __init__(self):
     self.IF = ftrobopy('10.16.1.4')
     self.TrafficLights = TrafficLights(self.IF, 4, 5, 6)
     self.TrafficLights.set_pattern('red', [True, True, True, True])
     self.TrafficLights.set_new()
     self.TX = ComStack(self.IF)
     self.TX.setio(2, 2)
     self.TX.start_recieving()
     self.HRL = HRL(self.TX)
Esempio n. 2
0
def getControllers(controllerconfigs):
    # initialize new dict for the controllers
    controllers = {}
    while True:
        # get dict of uninitialized controllers
        pending = dict([(n, c) for n, c in controllerconfigs.items()
                        if n not in controllers])
        # if this is empty -> leave the loop
        if len(pending) == 0:
            break
        # iterate over pending controllers
        for n, c in pending.items():
            # jump to next if master not initialized yet
            if 'master' in c:
                if c['master'] not in controllers:
                    continue

            # get controller type
            controllertype = c['config']['type']
            # write controller config in new dict
            controllers[n] = c

            # choose between controller types
            if controllertype == 'txt':
                # TXT: just initialize
                from ftrobopy import ftrobopy
                controllers[n]['controller'] = ftrobopy(c['host'])

            elif controllertype == 'robointerface':
                # Robo Interface
                from ftifpy import ftifpy
                # initialize master controller
                controllers[n]['mastercontroller'] = ftifpy()
                # get master
                controllers[n]['controller'] = controllers[n][
                    'mastercontroller'].roboif()
            elif controllertype == 'roboextension':
                # Robo Entension
                # get the extension from the master
                controllers[n]['controller'] = controllers[
                    c['master']]['mastercontroller'].roboif(c['id'])

            elif controllertype == 'tx':
                # Robo TX Controller
                from fttxpy import fttxpy
                # initialize master controller
                controllers[n]['mastercontroller'] = fttxpy()
                # get master
                controllers[n]['controller'] = controllers[n][
                    'mastercontroller'].robotx()
            elif controllertype == 'txextsion':
                # Robo TX Controller Extension
                # get the extension from the master
                controllers[n]['controller'] = controllers[
                    c['master']]['mastercontroller'].robotx(c['id'])
    # return controllers
    return (controllers)
    def __init__(self, args):
        TouchApplication.__init__(self, args)

        # create the empty main window
        w = TouchWindow("Tut_3_5")

        txt_ip = os.environ.get('TXT_IP')                    # try to read TXT_IP environment variable
        if txt_ip == None: txt_ip = "localhost"              # use localhost otherwise
        try:
            self.txt = ftrobopy.ftrobopy(txt_ip, 65000)      # try to connect to IO server
        except:
            self.txt = None

        vbox = QVBoxLayout()

        if not self.txt:
            # display error of TXT could no be connected
            # error messages is centered and may span
            # over several lines
            err_msg = QLabel("Error connecting IO server")   # create the error message label
            err_msg.setWordWrap(True)                        # allow it to wrap over several lines
            err_msg.setAlignment(Qt.AlignCenter)             # center it horizontally
            vbox.addWidget(err_msg)                          # attach it to the main output area
        else:
            # initialization went fine. So the main gui
            # is being drawn
            button = QPushButton("Toggle O1")                # create a button labeled "Toggle O1"
            button.clicked.connect(self.on_button_clicked)   # connect button to event handler
            vbox.addWidget(button)                           # attach it to the main output area

            # configure all TXT outputs to normal mode
            M = [ self.txt.C_OUTPUT, self.txt.C_OUTPUT, self.txt.C_OUTPUT, self.txt.C_OUTPUT ]
            I = [ (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ) ]
            self.txt.setConfig(M, I)
            self.txt.updateConfig()

            # initially switch light on
            self.light_on = True                             # remember that the light is on
            self.txt.setPwm(0,512)                           # set PWm to 512 (full on)

            self.timer = QTimer(self)                        # create a timer
            self.timer.timeout.connect(self.on_timer)        # connect timer to on_timer slot
            self.timer.start(100);                           # fire timer every 100ms (10 hz)

            self.button_state = False                        # assume initually the button is not pressed

        w.centralWidget.setLayout(vbox)
        w.show()
        self.exec_()
Esempio n. 4
0
    def __init__(self, args):
        global txt
        global state
        txt_ip = os.environ.get('TXT_IP')
        if txt_ip == None: txt_ip = "localhost"
        try:
            txt = ftrobopy.ftrobopy(txt_ip, 65000)
        except:
            txt = None

        TxtApplication.__init__(self, args)
        self.w = TxtWindow("Ampel")

        # create a vbox layout for the content area
        vbox = QVBoxLayout()

        but = QCheckBox("blinken")
        but.stateChanged.connect(self.blink_toggle)
        vbox.addWidget(but)

        vbox.addStretch()

        vbox.addWidget(QLabel("Grünphase:"))
        self.dial = QDial()
        self.dial.setNotchesVisible(True)
        self.dial.setRange(2, 60)
        self.green_time_lbl = QLabel()
        self.green_time_lbl.setObjectName("smalllabel")
        self.green_time_lbl.setAlignment(Qt.AlignCenter)
        self.dial.valueChanged.connect(self.green_time_changed)
        self.dial.setValue(10)

        vbox.addWidget(self.dial)
        vbox.addWidget(self.green_time_lbl)

        self.w.centralWidget.setLayout(vbox)

        # poll button at 10 Hz
        state = "idle"
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.do_ampel)
        self.timer.start(100)

        if txt:
            # all outputs normal mode
            M = [txt.C_OUTPUT, txt.C_OUTPUT, txt.C_OUTPUT, txt.C_OUTPUT]
            I = [(txt.C_SWITCH, txt.C_DIGITAL), (txt.C_SWITCH, txt.C_DIGITAL),
                 (txt.C_SWITCH, txt.C_DIGITAL), (txt.C_SWITCH, txt.C_DIGITAL),
                 (txt.C_SWITCH, txt.C_DIGITAL), (txt.C_SWITCH, txt.C_DIGITAL),
                 (txt.C_SWITCH, txt.C_DIGITAL), (txt.C_SWITCH, txt.C_DIGITAL)]
            txt.setConfig(M, I)
            txt.updateConfig()

        self.w.show()
        self.exec_()
Esempio n. 5
0
    def __init__(self, ws_thread, ui_queue):
        global plugins
        plugins = self.Plugins()

        super(RunThread, self).__init__()

        self.pluginLoader = PluginLoader()

        self.speed = 90  # range 0 .. 100

        self.joystick = None

        self.ws_thread = ws_thread  # websocket server thread
        self.ui_queue = ui_queue  # output queue to the local gui

        # connect to TXT
        try:
            txt_ip = os.environ.get('TXT_IP')
            if not txt_ip: txt_ip = "localhost"
            self.txt = ftrobopy.ftrobopy(txt_ip, 65000)
        except:
            self.txt = None

        if self.txt:
            # all outputs normal mode
            self.M = [
                self.txt.C_OUTPUT, self.txt.C_OUTPUT, self.txt.C_OUTPUT,
                self.txt.C_OUTPUT
            ]
            self.I = [(self.txt.C_SWITCH, self.txt.C_DIGITAL),
                      (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                      (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                      (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                      (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                      (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                      (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                      (self.txt.C_SWITCH, self.txt.C_DIGITAL)]
            self.txt.setConfig(self.M, self.I)
            self.txt.updateConfig()

        self.motor = [None, None, None, None]
        self.mobile = None

        # redirect stdout, stderr info to websocket server.
        # redirect stdout also to the local screen
        sys.stdout = io_sink("stdout", self.ws_thread, self.ui_queue)
        sys.stderr = io_sink("stderr", self.ws_thread, None)

        if not self.txt:
            print("TXT init failed", file=sys.stderr)
Esempio n. 6
0
    def __init__(self, ws_thread, ui_queue):
        global plugins
        plugins = self.Plugins()

        super(RunThread,self).__init__()

        self.pluginLoader = PluginLoader()

        self.speed = 90  # range 0 .. 100

        self.joystick = None

        self.ws_thread = ws_thread  # websocket server thread
        self.ui_queue = ui_queue    # output queue to the local gui

        # connect to TXT
        try:
            txt_ip = os.environ.get('TXT_IP')
            if not txt_ip: txt_ip = "localhost"
            self.txt = ftrobopy.ftrobopy(txt_ip, 65000)
        except:
            self.txt = None

        if self.txt:
            # all outputs normal mode
            self.M = [ self.txt.C_OUTPUT, self.txt.C_OUTPUT,
                       self.txt.C_OUTPUT, self.txt.C_OUTPUT ]
            self.I = [ (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                       (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                       (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                       (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                       (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                       (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                       (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                       (self.txt.C_SWITCH, self.txt.C_DIGITAL ) ]
            self.txt.setConfig(self.M, self.I)
            self.txt.updateConfig()
                
        self.motor = [ None, None, None, None ]
        self.mobile = None
 
        # redirect stdout, stderr info to websocket server.
        # redirect stdout also to the local screen
        sys.stdout = io_sink("stdout", self.ws_thread, self.ui_queue)
        sys.stderr = io_sink("stderr", self.ws_thread, None)

        if not self.txt:
            print("TXT init failed", file=sys.stderr)
Esempio n. 7
0
def txt_init():
    txt_ip = os.environ.get('TXT_IP')
    if txt_ip == None: txt_ip = "localhost"
    try:
        txt = ftrobopy.ftrobopy(txt_ip, 65000)

        # all outputs normal mode
        M = [txt.C_OUTPUT, txt.C_OUTPUT, txt.C_OUTPUT, txt.C_OUTPUT]
        I = [(txt.C_SWITCH, txt.C_DIGITAL), (txt.C_SWITCH, txt.C_DIGITAL),
             (txt.C_SWITCH, txt.C_DIGITAL), (txt.C_SWITCH, txt.C_DIGITAL),
             (txt.C_SWITCH, txt.C_DIGITAL), (txt.C_SWITCH, txt.C_DIGITAL),
             (txt.C_SWITCH, txt.C_DIGITAL), (txt.C_SWITCH, txt.C_DIGITAL)]
        txt.setConfig(M, I)
        txt.updateConfig()
        return txt
    except:
        return None
Esempio n. 8
0
    def __init__(self, args):
        TouchApplication.__init__(self, args)

        # create the empty main window
        w = TouchWindow("Tut_3_3")

        try:
            self.txt = ftrobopy.ftrobopy("localhost", 65000) # connect to TXT's IO controller
        except:
            self.txt = None                                  # set TXT to "None" of connection failed

        if not self.txt:
	        # display error of TXT could no be connected
            # error messages is centered and may span
            # over several lines
            err_msg = QLabel("Error connecting IO server")   # create the error message label
            err_msg.setWordWrap(True)                        # allow it to wrap over several lines
            err_msg.setAlignment(Qt.AlignCenter)             # center it horizontally
            w.setCentralWidget(err_msg)                      # attach it to the main output area
        else:
            # initialization went fine. So the main gui
            # is being drawn
            button = QPushButton("Toggle O1")                # create a button labeled "Toggle O1"
            button.clicked.connect(self.on_button_clicked)   # connect button to event handler
            w.setCentralWidget(button)                       # attach it to the main output area

	    # configure all TXT outputs to normal mode
            M = [ self.txt.C_OUTPUT, self.txt.C_OUTPUT, self.txt.C_OUTPUT, self.txt.C_OUTPUT ]
            I = [ (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ) ]
            self.txt.setConfig(M, I)
            self.txt.updateConfig()

	        # initially switch light on
            self.light_on = True                             # remember that the light is on
            self.txt.setPwm(0,512)                           # set PWM to 512 (full on)

        w.show()
        self.exec_()
Esempio n. 9
0
 def __init__(self, ifconfig):
     """
     ifconfig Variable-Format:
     Interface-Identifier as key, link to IO-Library as value
     config = {
     "IF1": ftrobopy.ftrobopy('192.168.7.2'),
     "EM1": ftrobopy.ftrobopy('192.168.8.2'),
     …
     "EM8": fttxpy.fttxpy(…),
     }
     """
     self.ifaces = {}
     if type(ifconfig) is dict and len > 1:  # a bit of checking before adding the external io-Wraps to the systems
         for ifconf in ifconfig:
             if ifconf in ["IF1", "EM1", "EM2", "EM3", "EM4", "EM5", "EM6", "EM7", "EM8"]:
                 self.ifaces[ifconf] = ifconfig[ifconf]
     self.ifaces["IF1"] = ftrobopy.ftrobopy("auto")
     time.sleep(0.5)
Esempio n. 10
0
 def __init__(self):
     self.txt = ftrobopy.ftrobopy('auto')
     time.sleep(2)
     self.txt.startCameraOnline()
     time.sleep(3)
     self.asse_y = self.txt.motor(1)
     self.asse_x = self.txt.motor(2)
     self.asse_z = self.txt.motor(3)
     self.ventosa = self.txt.output(7)
     self.lamp = self.txt.output(8)
     self.in_resety = self.txt.input(1)
     self.in_resetx = self.txt.input(4)
     self.in_downz = self.txt.input(5)
     self.in_upz = self.txt.input(6)
     self.in_select = self.txt.input(7)
     self.in_start = self.txt.input(8)
     self.pos_asse_x = 0
     self.pos_asse_y = 0
     self.reset()
    def __init__(self, args):
        TouchApplication.__init__(self, args)
        # create the empty main window
        w = TouchWindow("Tut_3_1")

        try:
            txt = ftrobopy.ftrobopy("localhost", 65000)      # connect to TXT's IO controller
        except:
            txt = None                                       # set TXT to "None" of connection failed

        if not txt:
            # display error if TXT could no be connected
            # error messages is centered and may span
            # over several lines
            err_msg = QLabel("Error connecting IO server")   # create the error message label
            err_msg.setWordWrap(True)                        # allow it to wrap over several lines
            err_msg.setAlignment(Qt.AlignCenter)             # center it horizontally
            w.setCentralWidget(err_msg)                      # attach it to the main output area
            
        w.show()
        self.exec_()        
    def __init__(self, args):
        TouchApplication.__init__(self, args)

    # create the empty main window
        w = TouchWindow("Tut_3_2")

        try:
            txt = ftrobopy.ftrobopy("localhost", 65000)      # connect to TXT's IO controller
        except:
            txt = None                                       # set TXT to "None" of connection failed

        if not txt:
	        # display error of TXT could no be connected
            # error messages is centered and may span
            # over several lines
            err_msg = QLabel("Error connecting IO server")   # create the error message label
            err_msg.setWordWrap(True)                        # allow it to wrap over several lines
            err_msg.setAlignment(Qt.AlignCenter)             # center it horizontally
            w.setCentralWidget(err_msg)                      # attach it to the main output area
        else:
            # initialization went fine. So the main gui
            # is being drawn
            button = QPushButton("Toggle O1")                # create a button labeled "Toggle O1"
            w.setCentralWidget(button)                       # attach it to the main output area

	    # configure all TXT outputs to normal mode
            M = [ txt.C_OUTPUT, txt.C_OUTPUT, txt.C_OUTPUT, txt.C_OUTPUT ]
            I = [ (txt.C_SWITCH, txt.C_DIGITAL ),
                  (txt.C_SWITCH, txt.C_DIGITAL ),
                  (txt.C_SWITCH, txt.C_DIGITAL ),
                  (txt.C_SWITCH, txt.C_DIGITAL ),
                  (txt.C_SWITCH, txt.C_DIGITAL ),
                  (txt.C_SWITCH, txt.C_DIGITAL ),
                  (txt.C_SWITCH, txt.C_DIGITAL ),
                  (txt.C_SWITCH, txt.C_DIGITAL ) ]
            txt.setConfig(M, I)
            txt.updateConfig()

        w.show()
        self.exec_()
Esempio n. 13
0
def init():
    # emette un suono per segnalare l'inizio di questa fase
    # TODO

    import ftrobopy
    txt = ftrobopy.ftrobopy('auto')    # MASTER
    # txt2 = ftrobopy.ftrobopy('auto') EXTENSION
    
    global MOTORS
    MOTORS = {e:txt.motor(e.value) for e in MotorsCodes}

    global LAMPS
    LAMPS = {e:txt.output(e.value) for e in LampsCodes}

    global BUTTONS
    BUTTONS = {e:txt.input(e.value) for e in ButtonsCodes}

    global PHOTOCELLS
    PHOTOCELLS = {e:txt.input(e.value) for e in PhotosCodes}

    global CALAMITA
    CALAMITA = txt.output(calamita_code)

    return

    # all'inizio i motori sono spenti
    for o in MOTORS.items():
        mot_off(o)

    # comprende il posizionamento del braccio ???
    # TODO
    # mow_to_row_col(SCI_POS)

    # accensione e spegnimento lampadina per tot secondi
    for o in LAMPS.items():
        lampeggio_lampadina(o, 10)

    # finita questa fase il programma attende che l'utente inizi una
    # nuova partita...
    init_finita = True
Esempio n. 14
0
    def __init__(self, args):
        global txt
        
        TxtApplication.__init__(self, args)

        txt_ip = os.environ.get('TXT_IP')
        if txt_ip == None: txt_ip = "localhost"
        txt = ftrobopy.ftrobopy(txt_ip, 65000)

        # create the empty main window
        self.w = TxtWindow("Thermo")

        self.vbox = QVBoxLayout()
        
        self.the = Thermometer(self)
        self.the.setValue(0)
        self.vbox.addWidget(self.the)

        self.w.centralWidget.setLayout(self.vbox)

        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update_thermo)
        self.timer.start(250);

        self.w.show()

        # all outputs normal mode
        M = [ txt.C_OUTPUT, txt.C_OUTPUT, txt.C_OUTPUT, txt.C_OUTPUT ]
        I = [ (txt.C_RESISTOR,   txt.C_ANALOG ),
              (txt.C_SWITCH, txt.C_DIGITAL ),
              (txt.C_SWITCH, txt.C_DIGITAL ),
              (txt.C_SWITCH, txt.C_DIGITAL ),
              (txt.C_SWITCH, txt.C_DIGITAL ),
              (txt.C_SWITCH, txt.C_DIGITAL ),
              (txt.C_SWITCH, txt.C_DIGITAL ),
              (txt.C_SWITCH, txt.C_DIGITAL ) ]
        txt.setConfig(M, I)
        txt.updateConfig()

        self.exec_()
Esempio n. 15
0
    def __init__(self, args):
        TouchApplication.__init__(self, args)

        # create the empty main window
        w = TouchWindow("Tut_3_2")

        try:
            txt = ftrobopy.ftrobopy("localhost",
                                    65000)  # connect to TXT's IO controller
        except:
            txt = None  # set TXT to "None" of connection failed

        if not txt:
            # display error of TXT could no be connected
            # error messages is centered and may span
            # over several lines
            err_msg = QLabel(
                "Error connecting IO server")  # create the error message label
            err_msg.setWordWrap(True)  # allow it to wrap over several lines
            err_msg.setAlignment(Qt.AlignCenter)  # center it horizontally
            w.setCentralWidget(err_msg)  # attach it to the main output area
        else:
            # initialization went fine. So the main gui
            # is being drawn
            button = QPushButton(
                "Toggle O1")  # create a button labeled "Toggle O1"
            w.setCentralWidget(button)  # attach it to the main output area

            # configure all TXT outputs to normal mode
            M = [txt.C_OUTPUT, txt.C_OUTPUT, txt.C_OUTPUT, txt.C_OUTPUT]
            I = [(txt.C_SWITCH, txt.C_DIGITAL), (txt.C_SWITCH, txt.C_DIGITAL),
                 (txt.C_SWITCH, txt.C_DIGITAL), (txt.C_SWITCH, txt.C_DIGITAL),
                 (txt.C_SWITCH, txt.C_DIGITAL), (txt.C_SWITCH, txt.C_DIGITAL),
                 (txt.C_SWITCH, txt.C_DIGITAL), (txt.C_SWITCH, txt.C_DIGITAL)]
            txt.setConfig(M, I)
            txt.updateConfig()

        w.show()
        self.exec_()
Esempio n. 16
0
    def __init__(self):
        # initialize controllers
        self.txt = ftrobopy()

        # prepare X-Axis
        self.XAxis = Axis(self.txt, 1, [1, 2])
        self.XAxis.maxPos = 6500

        # prepare Y-Axis
        self.YAxis = Axis(self.txt, 2, [3])  # not built yet...
        self.YAxis.maxPos = 9000

        # initialize X-Axis
        self.XAxis.initialize()
        # self.XAxis.startWatchdog() # watchdogs disabled due some stucks caused by software

        # initialize Y-Axis
        self.YAxis.initialize()
        # self.YAxis.startWatchdog()

        self.__posX = 0
        self.__posY = 0
Esempio n. 17
0
 def __init__(self, ifconfig):
     """
     ifconfig Variable-Format:
     Interface-Identifier as key, link to IO-Library as value
     config = {
     "IF1": ftrobopy.ftrobopy('192.168.7.2'),
     "EM1": ftrobopy.ftrobopy('192.168.8.2'),
     …
     "EM8": fttxpy.fttxpy(…),
     }
     """
     self.ifaces = {}
     if type(
             ifconfig
     ) is dict and len > 1:  # a bit of checking before adding the external io-Wraps to the systems
         for ifconf in ifconfig:
             if ifconf in [
                     "IF1", "EM1", "EM2", "EM3", "EM4", "EM5", "EM6", "EM7",
                     "EM8"
             ]:
                 self.ifaces[ifconf] = ifconfig[ifconf]
     self.ifaces["IF1"] = ftrobopy.ftrobopy("192.168.178.44")
     time.sleep(0.5)
Esempio n. 18
0
    def __init__(self, args):
        TouchApplication.__init__(self, args)
        # create the empty main window
        w = TouchWindow("Tut_3_1")

        try:
            txt = ftrobopy.ftrobopy("localhost",
                                    65000)  # connect to TXT's IO controller
        except:
            txt = None  # set TXT to "None" of connection failed

        if not txt:
            # display error if TXT could no be connected
            # error messages is centered and may span
            # over several lines
            err_msg = QLabel(
                "Error connecting IO server")  # create the error message label
            err_msg.setWordWrap(True)  # allow it to wrap over several lines
            err_msg.setAlignment(Qt.AlignCenter)  # center it horizontally
            w.setCentralWidget(err_msg)  # attach it to the main output area

        w.show()
        self.exec_()
Esempio n. 19
0
    def __init__(self, args):
        TxtApplication.__init__(self, args)

        #init Variables

        self.code = 0
        # create the empty main window
        w = TxtWindow("Fertigung")
        try:
            self.txt = ftrobopy.ftrobopy("localhost", 65000) # connect to TXT's IO controller
        except:
            self.txt = None                                  # set TXT to "None" of connection failed

        vbox = QVBoxLayout()
        if not self.txt:
            # display error of TXT could no be connected
            err_msg = QLabel("Error connecting IO server")   # create the error message label
            err_msg.setWordWrap(True)                        # allow it to wrap over several lines
            err_msg.setAlignment(Qt.AlignCenter)             # center it horizontally
            vbox.addWidget(err_msg)                      # attach it to the main output area
        else:
            # initialization went fine. So the main gui
            # is being drawn
            button = QPushButton("Neue Box")         # create a button labeled "Toggle O1"
            button.clicked.connect(self.new_box_clicked)   # connect button to event handler
            vbox.addWidget(button)                       # attach it to the main output area

            self.cw = CamWidget()

            vbox.addWidget(self.cw)

            self.lbl = QLabel()
            self.lbl.setObjectName("smalllabel")
            self.lbl.setAlignment(Qt.AlignCenter)
            self.lbl.setWordWrap(True)
            vbox.addWidget(self.lbl)

            self.connect( self.cw, SIGNAL("code(QString)"), self.on_code_detected )
            print(self.code)

        # configure all TXT outputs to normal mode
            M = [ self.txt.C_MOTOR, self.txt.C_MOTOR, self.txt.C_MOTOR, self.txt.C_OUTPUT ]
            I = [ (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ),
                  (self.txt.C_SWITCH, self.txt.C_DIGITAL ) ]
            self.txt.setConfig(M, I)
            self.txt.updateConfig()
            #Init Motoren
            self.Motor1 = self.txt.motor(1) #Motor Schieber
            self.Motor2 = self.txt.motor(2) #Motor Arbeitstakte
            self.Motor3 = self.txt.motor(3) #Motor und Ventil 2, je nachdem, wo sich das Werkstück befindet.
            self.Compressor = self.txt.output(7) #Kompressor
            self.Valve1 = self.txt.output(8) #Ventil

            #Init des ersten Schiebers

        w.centralWidget.setLayout(vbox)
        w.show()
        #Modell zurücksetzen
        while not self.txt.input(1).state() == 1:
            self.Motor1.setSpeed(-512)
        self.Motor1.stop()
        while not self.txt.input(3).state() == 1:
            self.Motor2.setSpeed(-512)
        self.Motor2.stop()

        thread = QThread()

        #Timer für die Weitergabe
        self.code = 0
        timer = QTimer(self)
        timer.timeout.connect(self.wait_for_code)
        timer.start(10)
        #Timer Versuch 2
        self.loop_init = 0

        timer_2 = QTimer(self)
        timer.timeout.connect(self.wait_for_loop)
        timer.start(10)

        self.exec_()
        #erste Box ausgeben
        self.new_box_clicked()
Esempio n. 20
0
    def __init__(self, args):
        TouchApplication.__init__(self, args)

        # create the empty main window
        w = TouchWindow("Tut_3_5")

        txt_ip = os.environ.get(
            'TXT_IP')  # try to read TXT_IP environment variable
        if txt_ip == None: txt_ip = "localhost"  # use localhost otherwise
        try:
            self.txt = ftrobopy.ftrobopy(txt_ip,
                                         65000)  # try to connect to IO server
        except:
            self.txt = None

        vbox = QVBoxLayout()

        if not self.txt:
            # display error of TXT could no be connected
            # error messages is centered and may span
            # over several lines
            err_msg = QLabel(
                "Error connecting IO server")  # create the error message label
            err_msg.setWordWrap(True)  # allow it to wrap over several lines
            err_msg.setAlignment(Qt.AlignCenter)  # center it horizontally
            vbox.addWidget(err_msg)  # attach it to the main output area
        else:
            # initialization went fine. So the main gui
            # is being drawn
            button = QPushButton(
                "Toggle O1")  # create a button labeled "Toggle O1"
            button.clicked.connect(
                self.on_button_clicked)  # connect button to event handler
            vbox.addWidget(button)  # attach it to the main output area

            # configure all TXT outputs to normal mode
            M = [
                self.txt.C_OUTPUT, self.txt.C_OUTPUT, self.txt.C_OUTPUT,
                self.txt.C_OUTPUT
            ]
            I = [(self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_SWITCH, self.txt.C_DIGITAL)]
            self.txt.setConfig(M, I)
            self.txt.updateConfig()

            # initially switch light on
            self.light_on = True  # remember that the light is on
            self.txt.setPwm(0, 512)  # set PWm to 512 (full on)

            self.timer = QTimer(self)  # create a timer
            self.timer.timeout.connect(
                self.on_timer)  # connect timer to on_timer slot
            self.timer.start(100)
            # fire timer every 100ms (10 hz)

            self.button_state = False  # assume initually the button is not pressed

        w.centralWidget.setLayout(vbox)
        w.show()
        self.exec_()
Esempio n. 21
0
import ftrobopy
import time
import struct

txt = ftrobopy.ftrobopy('192.168.8.2', 65000)

res = txt.i2c_read(0x18, 0x00)
if res[0] == 250:
    print("Found BMX055 Acceleration Sensor at address 0x18")
    txt.i2c_write(0x18, 0x11, 0x00)  # set normal power mode
    txt.i2c_write(0x18, 0x3e, 0x80)  # set fifo stream mode
    txt.i2c_write(0x18, 0x0f, 0x05)  # set g-range to +-4g
    txt.i2c_write(0x18, 0x10, 0x0a)  # set filter to 15.63 Hz

    for i in range(10000):
        fifo_status = txt.i2c_read(0x18, 0x0e)[0]
        #temperature=txt.i2c_read(0x18, 0x08)[0]
        if fifo_status > 0:  # and fifo_status < 128:
            res = txt.i2c_read(0x18, 0x3f, data_len=6)
            x, y, z = struct.unpack('<hhh', res)
            print(i, fifo_status, x >> 4, y >> 4, z >> 4)
        #elif fifo_status > 128: # fifo overflow
        #  res=txt.i2c_read(0x18, 0x3f, data_len=6)
        #time.sleep(0.01)
else:
    print("no bmx055 acceleration sensor found at address 0x18")
Esempio n. 22
0
import ftrobopy
import time

txt=ftrobopy.ftrobopy('127.0.0.1', 65000)

ml=txt.motor(1)
mr=txt.motor(2)
t1=txt.trailfollower(2)
t2=txt.trailfollower(3)

ml.setSpeed(512)
mr.setSpeed(512)
while True:
  if t1.state() < 1000 and t2.state() > 1000:
    ml.setSpeed(0)
  else:
    ml.setSpeed(512)
  if t2.state() < 1000 and t1.state() > 1000:
    mr.setSpeed(0)
  else:
    mr.setSpeed(512)
  time.sleep(0.02)

Esempio n. 23
0
import time
import ftrobopy

txt = ftrobopy.ftrobopy('auto', use_TransferAreaMode=True)
m1 = txt.motor(1)
m1.setSpeed(300)
time.sleep(3)
m1.setSpeed(0)

print(txt.stopOnline())
time.sleep(2)
Esempio n. 24
0
    def __init__(self, args):
        TouchApplication.__init__(self, args)

        self.w = TouchWindow('WebOfTXT')

        try:
            self.txt = ftrobopy.ftrobopy('localhost', 65000)
        except:
            self.txt = None

        self.outputs = [
            self.txt.C_OUTPUT,
            self.txt.C_OUTPUT,
            self.txt.C_OUTPUT,
            self.txt.C_OUTPUT
        ]
        self.inputs = [
            (self.txt.C_SWITCH, self.txt.C_DIGITAL),
            (self.txt.C_SWITCH, self.txt.C_DIGITAL),
            (self.txt.C_SWITCH, self.txt.C_DIGITAL),
            (self.txt.C_SWITCH, self.txt.C_DIGITAL),
            (self.txt.C_SWITCH, self.txt.C_DIGITAL),
            (self.txt.C_SWITCH, self.txt.C_DIGITAL),
            (self.txt.C_SWITCH, self.txt.C_DIGITAL),
            (self.txt.C_SWITCH, self.txt.C_DIGITAL)
        ]
        self.sensors = [
            'pushbutton',
            'pushbutton',
            'pushbutton',
            'pushbutton',
            'pushbutton',
            'pushbutton',
            'pushbutton',
            'pushbutton'
        ]

        self.inputButtons = []
        self.outputButtons = []
        self.cams = []
        self.caps = {}
        self.last_update = None
        self.temp_dir = None

        if not self.txt:
            err_msg = QLabel('Error connectiong to IO server')
            err_msg.setWordWrap(True)
            err_msg.setAlignment(Qt.AlignCenter)
            self.w.setCentralWidget(err_msg)
        else:
            self.thing = webthing.Thing(
                uuid.getnode(),
                self.txt.getDevicename(),
                ['MultiLevelSwitch'],
                'fischertechnik TXT ' + str(self.txt.getVersionNumber())
            )
            self.thing.set_ui_href('/cfw/')
            self.server = None
            self.thing.txt = self.txt
            self.timer = QTimer(self)
            self.timer.timeout.connect(self.update_level)
            for i in range(0, 4):
                self.addCounter(i)
            self.addResetCounters()

            self.addPlaySound()
            self.addStateProps()

            givenCam = os.environ.get('FTC_CAM')
            cam = None
            if givenCam is None:
                cam = 0
            else:
                cam = int(givenCam)

            camPath = Path('/dev/video' + str(cam))
            if camPath.exists():
                self.addCamera(cam)

            main_page = self.buildMainPage()
            input_page = self.buildInputPage()
            output_page = self.buildOutputPage()

            tabBar = QTabWidget()
            tabBar.addTab(main_page, 'Start')
            tabBar.addTab(input_page, 'Inputs')
            tabBar.addTab(output_page, 'Outputs')
            self.w.setCentralWidget(tabBar)
            self.tabs = tabBar

        self.w.show()
        self.exec_()
Esempio n. 25
0
import sys
import ftrobopy

txt=ftrobopy.ftrobopy('192.168.8.2', 65000)

Motor_rechts = txt.motor(1)
Motor_links  = txt.motor(2)
Ultraschall  = txt.ultrasonic(8)
Motor_rechts.setSpeed(512)
Motor_links.setSpeed(512)
Motor_rechts.setDistance(1000, syncto=Motor_links)
Motor_links.setDistance(1000, syncto=Motor_rechts)

while not Motor_rechts.finished(): 
  d=Ultraschall.distance()
  print d
  if d<10:
    Motor_rechts.stop()
    Motor_links.stop()
    if txt.sound_finished():
      txt.play_sound(3,1)

Esempio n. 26
0
#          video stream to TXT display
#          and autofocus functionality
#          (c) 2016 by Torsten Stuehn
#          version 0.8 from 2016-02-12
######################################

# Python2/3 'print' compatibility
from __future__ import print_function

import ftrobopy
import ftrobopytools
from os import system
import time

txt = ftrobopy.ftrobopy(host                     ='127.0.0.1',
                        port                     = 65000,
                        update_interval          = 0.01,
                        keep_connection_interval = 1.0)

run_ave_contrast   = 8
hist_minlength     = 10
hist_maxlength     = 20
fname_prefix       = 'PICT'
displayLiveStream  = 1 # live video on TXT display, 0=no 1=yes

# definition of TXT outputs and inputs
FocusMotor       = txt.motor(1) # the focus motor is connected to M1
Switch           = txt.input(1) # the switch is connected to I1

if displayLiveStream:
  # make backup copy of TXT display contents
  with open('/dev/fb0', 'rb') as f:
Esempio n. 27
0
 def __ioStart(self):
     self.io = ftrobopy.ftrobopy("127.0.0.1",65000)
     time.sleep(1)
#!/usr/bin/python
# -*- coding: utf-8 -*-

from enum import Enum
import time

__author__= "Tomelin Michele,Luca Manini"

__email__ = "*****@*****.**"

__version__= "1.0"

__status__= "Beta"

__date__= "23/11/2019"

ip="192.168.7.2"
ip2="192.168.7.4"
ip3="192.168.7.5"
idx="3"

 import ftrobopy
 txt = ftrobopy.ftrobopy(host=ip,port=65000) 
 txt.play_sound(idx,1,100)
Esempio n. 29
0
#!/usr/bin/env python3
# -*- encoding UTF-8 -*-
# __author__ = Kry9t0n
########################################################################
#  Main-dataprogram serving all the data to the Web-Gui                #
########################################################################
import os
import ftrobopy, time

#first getting all data

ft = ftrobopy.ftrobopy()  #craeting ftrobopy reference

#TODO getRAM enfernen
'''def getRAM():
    global f
    ram = os.popen("cat /proc/meminfo").read()
    f = open('/home/ftc/www/data/RAM.txt', 'w')
    print(f)
    sleep(2)
    f.write('RAM Auslastung: {} Zeitpunkt: {}'.format(ram[0:83], time))
    f.close()'''


def getTXTConfig():  # returns txt configuration [M] and [I]
    global f
    M, I = ft.getConfig()
    f = open('/home/ftc/www/data/config.txt', 'w')
    print(f)
    f.write('Motoren: {} Inputs: {}'.format(M, I))
    f.close()
Esempio n. 30
0
import sys, time
import ftrobopy

# Einlesen und Abspeichern eines TXT Camera Bildes (jpeg)

txt = ftrobopy.ftrobopy("192.168.7.2", 65000)
txt.startCameraOnline()
time.sleep(2.5)
pic = None
while pic == None:
    pic = txt.getCameraFrame()

f = open("TXTCamPic.jpg", "w")
f.write("".join(pic))
f.close()
Esempio n. 31
0
#          video stream to TXT display
#          and autofocus functionality
#          (c) 2016 by Torsten Stuehn
#          version 0.8 from 2016-02-12
######################################

# Python2/3 'print' compatibility
from __future__ import print_function

import ftrobopy
import ftrobopytools
from os import system
import time

txt = ftrobopy.ftrobopy(host='127.0.0.1',
                        port=65000,
                        update_interval=0.01,
                        keep_connection_interval=1.0)

run_ave_contrast = 8
hist_minlength = 10
hist_maxlength = 20
fname_prefix = 'PICT'
displayLiveStream = 1  # live video on TXT display, 0=no 1=yes

# definition of TXT outputs and inputs
FocusMotor = txt.motor(1)  # the focus motor is connected to M1
Switch = txt.input(1)  # the switch is connected to I1

if displayLiveStream:
    # make backup copy of TXT display contents
    with open('/dev/fb0', 'rb') as f:
Esempio n. 32
0
    def __init__(self, args):
        TouchApplication.__init__(self, args)

        translator = QTranslator()
        path = os.path.dirname(os.path.realpath(__file__))
        translator.load(QLocale.system(), os.path.join(path, "rfid_"))
        self.installTranslator(translator)

        # create the empty main window
        self.w = TouchWindow("RFID")

        self.vbox = QVBoxLayout()
        self.vbox.addStretch()

        try:
            self.MIFAREReader = MFRC522.MFRC522()
            if not self.MIFAREReader.MFRC522_Present():
                self.MIFAREReader = None

        except IOError:
            self.MIFAREReader = None

        if not self.MIFAREReader:
            lbl = QLabel(
                QCoreApplication.translate(
                    "main",
                    "Unable to connect to " + "RC522 RFID reader.\n\n" +
                    "Make sure one is " + "connected via USB or I²C."))
            lbl.setObjectName("smalllabel")
            lbl.setWordWrap(True)
            lbl.setAlignment(Qt.AlignCenter)
            self.vbox.addWidget(lbl)

        else:
            # get access to TXTs IOs if present
            txt_ip = os.environ.get('TXT_IP')
            if txt_ip == None: txt_ip = "localhost"
            try:
                self.txt = ftrobopy.ftrobopy(txt_ip, 65000)
            except:
                self.txt = None

            menu = self.w.addMenu()
            self.menu_cfg = menu.addAction(
                QCoreApplication.translate("menu", "Setup card"))
            self.menu_cfg.triggered.connect(self.setup)

            self.label = QLabel("")
            self.label.setObjectName("smalllabel")
            self.label.setAlignment(Qt.AlignCenter)
            self.vbox.addWidget(self.label)

            self.icon = QLabel("")
            self.icon.setAlignment(Qt.AlignCenter)
            self.vbox.addWidget(self.icon)

            self.name = QLabel("")
            self.name.setObjectName("smalllabel")
            self.name.setAlignment(Qt.AlignCenter)
            self.vbox.addWidget(self.name)

            self.setState("searching")

            # start a qtimer to poll the sensor
            self.timer = QTimer(self)
            self.timer.timeout.connect(self.on_timer)
            self.timer.start(100)

            # and a timer to handle lamps and motors
            self.io_timer = QTimer(self)
            self.io_timer.timeout.connect(self.on_io_event)
            self.io_timer.setSingleShot(True)
            self.io_state = None

        self.vbox.addStretch()
        self.w.centralWidget.setLayout(self.vbox)

        self.w.show()
        self.exec_()
Esempio n. 33
0
 def __ioStart(self):
     self.io = ftrobopy.ftrobopy("127.0.0.1", 65000)
     time.sleep(1)
Esempio n. 34
0
__author__ = "Pietro Dorighi"
__copyright__ = "Copyright 2018 by Pietro Dorighi"
__license__ = "MIT License"
__version__ = "2.0"
__maintainer__ = "Pietro Dorighi"
__email__ = "*****@*****.**"
__status__ = "development"
__date__ = "10/01/2018"


CAM_IMAGE = 'img/TXTCamImg.jpg'

WLAN = '192.168.8.2'
USB = '192.168.7.2'
txt = ftrobopy.ftrobopy('auto')  # Connessione al controller

M = [txt.C_MOTOR, txt.C_MOTOR, txt.C_MOTOR, txt.C_OUTPUT]

I = [(txt.C_SWITCH, txt.C_DIGITAL)] * 8

txt.setConfig(M, I)
txt.updateConfig()

#--------INIZIO DICHIARAZIONE VARIABILI---------------------

# Coordinate X e Y di ogni posizione in ordine numerico
Xpos = [970, 2635, 4211, 1580, 2560, 3690, 2180, 2635,
        3090, 970, 1500, 2180, 3090, 3690, 4211, 2050,
        2635, 3090, 1580, 2635, 3690, 970, 2635, 4211]
Esempio n. 35
0
    def __init__(self, args):
        TouchApplication.__init__(self, args)

        # create the empty main window
        w = TouchWindow("ftcontrol")

        txt_ip = os.environ.get(
            'TXT_IP')  # try to read TXT_IP environment variable
        if txt_ip is None: txt_ip = "localhost"  # use localhost otherwise
        try:
            self.txt = ftrobopy.ftrobopy(txt_ip,
                                         65000)  # try to connect to IO server
        except:
            self.txt = None

        vbox = QVBoxLayout()

        if not self.txt:
            # display error of TXT could no be connected
            # error messages is centered and may span
            # over several lines
            err_msg = QLabel(
                "Error connecting IO server")  # create the error message label
            err_msg.setWordWrap(True)  # allow it to wrap over several lines
            err_msg.setAlignment(Qt.AlignCenter)  # center it horizontally
            vbox.addWidget(err_msg)  # attach it to the main output area
        else:
            # initialization went fine. So the main gui
            # is being drawn
            self.test_button = QPushButton("Test")
            self.test_button.clicked.connect(
                self.on_test_button_clicked)  # connect button to event handler
            # self.grab_button.setEnabled(False)
            vbox.addWidget(
                self.test_button)  # attach it to the main output area

            # configure all TXT outputs to normal mode
            output_config = [
                self.txt.C_OUTPUT, self.txt.C_OUTPUT, self.txt.C_OUTPUT,
                self.txt.C_OUTPUT
            ]
            input_config = [(self.txt.C_SWITCH, self.txt.C_DIGITAL),
                            (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                            (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                            (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                            (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                            (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                            (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                            (self.txt.C_SWITCH, self.txt.C_DIGITAL)]
            self.txt.setConfig(output_config, input_config)
            self.txt.updateConfig()

            self.motor_x = ftcontrol.PositionableMotor("x", self.txt.motor(1),
                                                       self.txt.input(1))
            self.motor_y = ftcontrol.PositionableMotor("y", self.txt.motor(2),
                                                       self.txt.input(2))
            self.motor_z = ftcontrol.PositionableMotor("z", self.txt.motor(3),
                                                       self.txt.input(3))
            self.motor_w = ftcontrol.PositionableMotor("w", self.txt.motor(4),
                                                       self.txt.input(4))

        w.centralWidget.setLayout(vbox)
        w.show()
        self.exec_()
'''
Mask Detector Robot

A Python code for detecting the face masks depending on HSV color system using OpenCV.

The robot will capture an image using the attached camera with TXT controller from fischertechnik.

Done By: Eng. Meqdad Darwish
'''
import cv2 as cv
import ftrobopy
import time
import numpy as np

txt = ftrobopy.ftrobopy('192.168.7.2', 65000)  # USB

ultrasonic_sensor = txt.ultrasonic(6)  # I6
stop_condition = False

M1 = txt.motor(1)  # Create a motor object (M1)
M2 = txt.motor(2)  # Create a motor object (M2)
M1.setSpeed(-280)  # Set speed
M2.setSpeed(268)  # Set speed
txt.updateWait()

while not stop_condition:
    txt.updateWait()
    distance = ultrasonic_sensor.distance()
    s = "Measured distance: {:5f}".format(distance)
    print(s, end='\r')
    if distance <= 22:
Esempio n. 37
0
import sys
import time
import ftrobopy

try:
    txt = ftrobopy.ftrobopy("auto")
except:
    txt = None

M = [ txt.C_OUTPUT, txt.C_OUTPUT, txt.C_OUTPUT, txt.C_OUTPUT ]
I = [ (txt.C_SWITCH, txt.C_DIGITAL ),
      (txt.C_SWITCH, txt.C_DIGITAL ),
      (txt.C_SWITCH, txt.C_DIGITAL ),
      (txt.C_SWITCH, txt.C_DIGITAL ),
      (txt.C_SWITCH, txt.C_DIGITAL ),
      (txt.C_SWITCH, txt.C_DIGITAL ),
      (txt.C_SWITCH, txt.C_DIGITAL ),
      (txt.C_SWITCH, txt.C_DIGITAL ) ]

txt.setConfig(M, I)
txt.updateConfig()

Motor1 = txt.motor(1)
Motor2 = txt.motor(2)
Motor3 = txt.motor(3)
Motor4 = txt.motor(4)

Button1 = txt.input(1)
Button2 = txt.input(2)

i = 4
Esempio n. 38
0
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from bash import bash as BashHandler            # import bash lib
import ftrobopy                                 # import hardware i/o lib for fischertechnik
from _thread import start_new_thread            # import simple thread starter
import random                                   # import random lib
import copy                                     # import lib for copying data structures
# import basic functions of python
import time

txt = ftrobopy.ftrobopy('direct')     # initialize i/o communicaton
# initialize communication constants
analog_threshold = 1500
com_speed = 0.1
com_values = [2, 5, 8, 11, 14, 17, 20]
com_target_diff = 0.1
com_wait_after_send = 5
global com_buffers                              # initialize communication buffer
com_buffers = {}
bash = BashHandler()


class push_button():

    def __init__(self, p):
        self.button = txt.input(p)

    def get_state(self):
        if self.button.state() == 1:
            return(True)
Esempio n. 39
0
import time
import ftrobopy
import threading

txt = ftrobopy.ftrobopy('auto')  # connect to txt

# lets configure our inputs
joystick_l = txt.joystick(0, 1, 1)
joystick_r = txt.joystick(1, 1, 1)

# and these are our outputs
motor_r = txt.motor(1)
motor_l = txt.motor(2)
motor_r.setDistance(0, syncto=None)
motor_l.setDistance(0, syncto=None)
txt.updateWait()
print("Wir sind startklar.")

# steering with your motors instead of using a steering axle allows for turning directly on your heel. I've made it so
# that pressing/depressing the right X-Axis stick will make the vehicle do a big u-turn like with a steering axle
# steering with the left X-Axis stick on the other hand allows for turning completely on your own heel
# it takes a little getting used to but allows for more flexibility while steering.


def infiniteloop1():  # steering via BT Remote
    while True:
        if abs(joystick_r.leftright()) <= 0.1 and abs(
                joystick_l.leftright()) <= 0.4 and abs(
                    joystick_l.updown()) >= 0.1:  # forward and backward
            motor_l.setSpeed(joystick_l.updown() * 508)
            motor_r.setSpeed(joystick_l.updown() * 508)
Esempio n. 40
0
import ftrobopy
import time
import numpy

#Inutile
__author__ = "Stefani, Kuricki Gabriele"
__version__ = "Alpha 0.1"
__status__ = "In development"
__date__ = "10/04/2018"

#Connessione al controller
USB = '192.168.7.2'
txt = ftrobopy.ftrobopy('auto')

#Dichiarazione Motori
Assex = txt.motor(1)
Assey = txt.motor(2)
Assez = txt.motor(3)

#Dichiarazione compressore
compr = txt.output(7)

#Dichiarazione tasti
tastoresetx = txt.input(1)
tastoresety = txt.input(2)
tastoresetz = txt.input(3)

#Posizioni
uno = {"1": [3150, 1350]}
due = {"1": [3500, 1700], "2": [3890, 2075]}
tre = {"1": [2125, 1350], "2": [3890, 1325], "3": [1425, 2075]}
Esempio n. 41
0
    def __init__(self, args):
        TxtApplication.__init__(self, args)

        self.hiscore = self.read_hiscore()

        # connect to TXTs IO board
        txt_ip = os.environ.get('TXT_IP')
        if txt_ip == None: txt_ip = "localhost"
        try:
            self.txt = ftrobopy.ftrobopy(txt_ip, 65000)
        except:
            self.txt = None

        if self.txt:
            # all outputs normal mode
            M = [
                self.txt.C_OUTPUT, self.txt.C_OUTPUT, self.txt.C_OUTPUT,
                self.txt.C_OUTPUT
            ]
            I = [(self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_SWITCH, self.txt.C_DIGITAL),
                 (self.txt.C_VOLTAGE, self.txt.C_ANALOG)]
            self.txt.setConfig(M, I)
            self.txt.updateConfig()

        # create the empty main window
        self.w = TxtWindow("Pinball")

        self.vbox = QVBoxLayout()

        self.led = LEDWidget()
        self.vbox.addWidget(self.led)

        hbox_w = QWidget()
        hbox = QHBoxLayout()
        hbox_w.setLayout(hbox)
        hbox.addStretch(1)
        self.balls = BallWidget()
        hbox.addWidget(self.balls, 4)
        hbox.addStretch(1)
        self.vbox.addWidget(hbox_w)

        self.current_score = 0
        self.lcd = QLCDNumber(5)
        # initially display hi score
        self.lcd.display(str(self.hiscore))
        self.vbox.addWidget(self.lcd)

        # start button an progress bar
        # share the same widget location ...
        self.stack = QStackedWidget(self.w)
        qsp = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
        self.stack.setSizePolicy(qsp)

        self.pbar = QProgressBar()
        self.pbar.setTextVisible(False)
        self.stack.addWidget(self.pbar)

        self.start = QPushButton("Start")
        self.stack.addWidget(self.start)
        self.stack.setCurrentWidget(self.start)
        self.start.clicked.connect(self.on_start)

        self.vbox.addWidget(self.stack)

        self.w.centralWidget.setLayout(self.vbox)

        loop_timer = QTimer(self)
        loop_timer.timeout.connect(self.on_timeout_tick)
        loop_timer.start(TIMEOUT * 1000 / 100)

        self.w.show()
        self.exec_()