2017-12-07 16 views
0

USB経由でデバイスを制御しているGUIがあります。 私はそれを設定する方法は、基本的に2つのボタン、前と後、ボタンが押されている間、その機能がモーターに送信されている間、ボタンが離されると、オフ信号が一度トリガーされます。私は最近、現時点でボタンを(私の場合は私はGDBを使用していたし、ブレークポイントにヒットし、ブレークポイントをリリースし、その後、ボタンを離す)USB接続が一時停止されている場合は、興味深い故障モードが発生しましたボタンが押されていないときに検出するPyQt

def on_release(): 
     print('Off') 
     self.off() 

    def on_click(): 
     print('forward') 
     self.forward() 
    button = QPushButton('Cut', self) 
    button.move(100,70) 
    button.pressed.connect(on_click) 
    button.released.connect(on_release) 

    def on_click(): 
     print('back') 
     self.back() 
    button = QPushButton('back', self) 
    button.move(200,70) 
    button.pressed.connect(on_click) 
    button.released.connect(on_release) 

キル信号は送信されず、モーターは永久に前進または後進する。

私はすでに、USBをオフにするための保護機能(スレッド化されたハートビート信号)を持っています。接続が切断されていますが、1つの特定のUSBオフ送信が失敗した場合に、これをもう少し安全に失敗させたいと考えています。

ボタンを押さないとチェックできないのですか?オフ信号をトリガするために?

+0

チェック[https://stackoverflow.com/questions/19508450/programmatically-toggle-a-python-pyqt- qpushbutton]またはおそらくtrduamic 2120 +ステッパードライバーでarduinoを使用します。信号低下==モータ停止モード、過負荷など。 [http://www.watterott.com/de/SilentStepStick] – ZF007

+0

ボタンを押すと、ボタンがUSBまたはステッパードライバを介して与えるステップを定義できます。たとえば、button1 =押されたイベントごとに100ステップ。 Button2 = 10ステップ、ボタン3 = 1ステップ...後者の場合、進行を続けるためには、それを継続的に押す必要があります。リリースされた場合... 1つの追加ステップが実行され、停止信号が自動的に送信されます(ステッパードライバまたはお客様のスクリプト内)。 – ZF007

+0

もう一つの非常に役に立つリンクは、[http://zapmaker.org/projects/grbl-controller-3-0/]で、3Dプリンタを制御するarduinoボード用のqt GUIを作成する方法を示しています。ここでは、[http://zapmaker.org/wp-content/uploads/2012/12/mac.png]は左または右に移動するための1ステップサイズを示しています。 – ZF007

答えて

0

教材をhttps://github.com/tjmarkham/python-stepper] [におけるtjmarkham stepper.pyスクリプトからラズベリーPiのCAのnはあなたのボタンの後ろに置くこと:

#CURRENT APPLICATION INFO 
#200 steps/rev 
#12V, 350mA 
#Big Easy driver = 1/16 microstep mode 
#Turn a 200 step motor left one full revolution: 3200 

from time import sleep 
import RPi.GPIO as gpio #https://pypi.python.org/pypi/RPi.GPIO 
#import exitHandler #uncomment this and line 58 if using exitHandler 

class stepper: 
    #instantiate stepper 
    #pins = [stepPin, directionPin, enablePin] 
    def __init__(self, pins): 
     #setup pins 
     self.pins = pins 
     self.stepPin = self.pins[0] 
     self.directionPin = self.pins[1] 
     self.enablePin = self.pins[2] 

     #use the broadcom layout for the gpio 
     gpio.setmode(gpio.BCM) 

     #set gpio pins 
     gpio.setup(self.stepPin, gpio.OUT) 
     gpio.setup(self.directionPin, gpio.OUT) 
     gpio.setup(self.enablePin, gpio.OUT) 

     #set enable to high (i.e. power is NOT going to the motor) 
     gpio.output(self.enablePin, True) 

     print("Stepper initialized (step=" + self.stepPin + ", direction=" + self.directionPin + ", enable=" + self.enablePin + ")") 

    #clears GPIO settings 
    def cleanGPIO(self): 
     gpio.cleanup() 

    #step the motor 
    # steps = number of steps to take 
    # dir = direction stepper will move 
    # speed = defines the denominator in the waitTime equation: waitTime = 0.000001/speed. As "speed" is increased, the waitTime between steps is lowered 
# stayOn = defines whether or not stepper should stay "on" or not. If stepper will need to receive a new step command immediately, this should be set to "True." Otherwise, it should remain at "False." 

    def step(self, steps, dir, speed=1, stayOn=False): 
     #set enable to low (i.e. power IS going to the motor) 
     gpio.output(self.enablePin, False) 

     #set the output to true for left and false for right 
     turnLeft = True 
     if (dir == 'right'): 
      turnLeft = False; 
     elif (dir != 'left'): 
      print("STEPPER ERROR: no direction supplied") 
      return False 
     gpio.output(self.directionPin, turnLeft) 

     stepCounter = 0 

     waitTime = 0.000001/speed #waitTime controls speed 

     while stepCounter < steps: 
      #gracefully exit if ctr-c is pressed 
      #exitHandler.exitPoint(True) #exitHandler.exitPoint(True, cleanGPIO) 

      #turning the gpio on and off tells the easy driver to take one step 
      gpio.output(self.stepPin, True) 
      gpio.output(self.stepPin, False) 
      stepCounter += 1 

      #wait before taking the next step thus controlling rotation speed 
      sleep(waitTime) 

     if (stayOn == False): 
      #set enable to high (i.e. power is NOT going to the motor) 
      gpio.output(self.enablePin, True) 

print("stepperDriver complete (turned " + dir + " " + str(steps) + " steps)") 

teststepper.py

from Stepper import Stepper 

#stepper variables 
#[stepPin, directionPin, enablePin] 
testStepper = Stepper([22, 17, 23]) 

#test stepper 
testStepper.step(3200, "right"); #steps, dir, speed, stayOn 
関連する問題