Up Servo Kit : テスト 作成: 2021-04-01
更新: 2021-04-03


    $ python >>> import gopigo3 >>> GPG = gopigo3.GoPiGo3() 本機は,サーボのケーブルをコネクタ「Servo2」に挿している。 GPG.set_servo(GPG.SERVO_2, n) で distance sensor が正面を向く n を探すと,本機の場合は n = 1400 だった。 >>> GPG.set_servo(GPG.SERVO_2, 1400) >>> GPG.set_servo(GPG.SERVO_2, 1400 - 500) >>> GPG.set_servo(GPG.SERVO_2, 1400 + 500) >>> GPG.reset_all() >>> quit()

  • ~/Dexter/GoPiGo3/Software/Python/Examples/Servo.py
      $ cd ~/Dexter/GoPiGo3/Software/Python $ sudo chown -R pi Examples $ sudo chgrp -R pi Examples $ cd Examples $ ./Servo.py $ vi Servo.py 本機はサーボのケーブルをコネクタ「Servo2」に挿しているので,
      GPG.set_servo(GPG.SERVO_1, ‥‥) の行をコメントアウト
      #!/usr/bin/env python # import the time library for the sleep function import time # import the GoPiGo3 drivers import gopigo3 # Create an instance of the GoPiGo3 class. GPG will be the GoPiGo3 object. GPG = gopigo3.GoPiGo3() try: while True: # count from 1000 to 2000 for i in range(1000, 2001): # GPG.set_servo(GPG.SERVO_1, i) GPG.set_servo(GPG.SERVO_2, 3000-i) time.sleep(0.001) # count from 1000 to 2000 for i in range(1000, 2001): GPG.set_servo(GPG.SERVO_2, i) # GPG.set_servo(GPG.SERVO_1, 3000-i) time.sleep(0.001) # except the program gets interrupted by Ctrl+C on the keyboard. except KeyboardInterrupt: # Unconfigure the sensors, disable the motors, # and restore the LED to the control of the GoPiGo3 firmware. GPG.reset_all()



    備考:つぎのファイルは,機能しない
       ──実際,SERVO_1, SERVO_2 を想定していない
      https://github.com/DexterInd/GoPiGo/blob/master/Software/Python/Examples/Basic_Servo/basic_servo.py
      #!/usr/bin/env python from gopigo import * servo_pos=90 print "CONTROLS" print "a: move servo left" print "d: move servo right" print "s: move servo home" print "Press ENTER to send the commands" while True: #Get the input from the user and change the servo angles # Get keyboard input. inp=raw_input() # Now decide what to do with that keyboard input. if inp=='a': # If input is 'a' move the servo forward 10 degrees. servo_pos=servo_pos+10 elif inp=='d': # If the input is 'd' move the servo backward by 10 degrees. servo_pos=servo_pos-10 elif inp=='s': servo_pos=90 #Get the servo angles back to the normal 0 to 180 degree range if servo_pos>180: servo_pos=180 if servo_pos<0: servo_pos=0 # This function updates the servo with the latest positon. Move the servo. servo(servo_pos) # Take a break in between operations. time.sleep(.1)