下記のプログラムにて、'def write'以降のif文からindentエラーが発生し実行できません。プログラムはこちらのサイトからコピペしたものです。
エラー内容は把握してますが始めたばかりで無知な部分が多いのでどこを直すといいか教えていただけるとうれしいです。よろしくお願いします。
Python
1import webiopi 2 3webiopi.setDebug() 4 5GPIO = webiopi.GPIO 6 7class DCMotor: 8 _pin1 = 0 9 _pin2 = 0 10 11 def __init__(self, pin1, pin2): 12 self._pin1 = pin1 13 self._pin2 = pin2 14 GPIO.setFunction( self._pin1, GPIO.PWM ) 15 GPIO.setFunction( self._pin2, GPIO.PWM ) 16 17 def __del__(self): 18 self.write(0.0) # stop 19 20 def write(self, ratio): 21 if 1.0 < ratio: # saturation 22 ratio = 1.0 23 if -1.0 > ratio: # saturation 24 ratio = -1.0 25 if 0.01 > ratio and -0.01 < ratio: # stop 26 GPIO.pwmWrite(self._pin1, 0.0) 27 GPIO.pwmWrite(self._pin2, 0.0) 28 elif 0 < ratio: # Normal rotation 29 GPIO.pwmWrite(self._pin1, ratio) 30 GPIO.pwmWrite(self._pin2, 0.0) 31 else: # Reverse rotation 32 GPIO.pwmWrite(self._pin1, 0.0) 33 GPIO.pwmWrite(self._pin2, -ratio) 34 35g_motorL = DCMotor( 5, 6 ) # Left motor 36g_motorR = DCMotor( 13, 19 ) # Right motor 37 38g_strMode = "0" # Drive mode. GUI default mode = "0"(stop) 39g_fRatio = int("5") * 0.05 # PWM Ratio. GUI default level = "5" 40 41@webiopi.macro 42def ChangeDriveMode( strMode ): 43 webiopi.debug("ChangeDriveMode( %s )" % (strMode)) 44 global g_strMode 45 g_strMode = strMode 46 iMode = int(strMode) 47 if 0 == iMode: 48 webiopi.debug("Mode : Stop") 49 g_motorL.write(0.0) 50 g_motorR.write(0.0) 51 elif 1 == iMode: 52 webiopi.debug("Mode : Forward") 53 g_motorL.write(g_fRatio) 54 g_motorR.write(g_fRatio) 55 elif 2 == iMode: 56 webiopi.debug("Mode : Backward") 57 g_motorL.write(-g_fRatio) 58 g_motorR.write(-g_fRatio) 59 elif 3 == iMode: 60 webiopi.debug("Mode : CW") 61 g_motorL.write( g_fRatio) 62 g_motorR.write(-g_fRatio) 63 elif 4 == iMode: 64 webiopi.debug("Mode : CCW") 65 g_motorL.write(-g_fRatio) 66 g_motorR.write( g_fRatio) 67 68@webiopi.macro 69def ChangeVoltageLevel( strLevel ): 70 webiopi.debug("ChangeVoltageLevel( %s )" % (strLevel)) 71 global g_fRatio 72 g_fRatio = int(strLevel) * 0.05 73 # ratio = level * 0.05 : level=10 -> ratio=0.5 -> InputVoltage=2.5[V](When VM=5[V]). 74 webiopi.debug("Ratio : %f" % (g_fRatio)) 75 ChangeDriveMode( g_strMode )
回答4件
あなたの回答
tips
プレビュー