Skip to content

Servoの制御

PWMサーボの制御

初期化

# coding: utf-8
import Fabo_PCA9685
import time
import pkg_resources
import smbus

# init
BUSNUM=1
SERVO_HZ=60
INITIAL_VALUE=300
bus = smbus.SMBus(BUSNUM)
PCA9685 = Fabo_PCA9685.PCA9685(bus,INITIAL_VALUE,address=0x60)
PCA9685.set_hz(SERVO_HZ)

値を設定

while True:
    # Move servo on channel O between extremes.
    PCA9685.set_channel_value(0,150)
    time.sleep(1)
    PCA9685.set_channel_value(0,300)
    time.sleep(1)

ハンドルの制御

初期化

# coding: utf-8
import Fabo_PCA9685
import time
import pkg_resources
import smbus

# Param
CENTER = 200
RIGHT=150
LEFT = 250

# init
BUSNUM=1
SERVO_HZ=60
INITIAL_VALUE=300
bus = smbus.SMBus(BUSNUM)
PCA9685 = Fabo_PCA9685.PCA9685(bus,INITIAL_VALUE,address=0x60)
while True:
    # Move servo on channel O between extremes.
    PCA9685.set_channel_value(0,RIGHT)
    time.sleep(1)
    PCA9685.set_channel_value(0,CENTER)
    time.sleep(1)
    PCA9685.set_channel_value(0,LEFT)
    time.sleep(1)

ESCの制御

ECSは電源ON時の値でESCキャリブレーションが実施されます。

# coding: utf-8
import Fabo_PCA9685
import time
import pkg_resources
import smbus

# Param
INIT = 300

# init
BUSNUM=1
SERVO_HZ=60
INITIAL_VALUE=300
bus = smbus.SMBus(BUSNUM)
PCA9685 = Fabo_PCA9685.PCA9685(bus,INITIAL_VALUE,address=0x40) # JetRacer Mini Board
#PCA9685 = Fabo_PCA9685.PCA9685(bus,INITIAL_VALUE,address=0x60) # Edge AI Board


# Move servo on channel O between extremes.
PCA9685.set_channel_value(1,INIT)

上記プログラムを実行しESCをOnにします。ピピと2回音がなればキャリブレーション成功です。

# Param
FORWARD = 400
BACK = 250

while True:
    # Forward
    PCA9685.set_channel_value(1,FORWARD)
    time.sleep(5)

    # Stop
    PCA9685.set_channel_value(1,INIT + 1)
    time.sleep(0.1)
    PCA9685.set_channel_value(1,INIT)
    time.sleep(0.1)
    PCA9685.set_channel_value(1,INIT + 1)
    time.sleep(0.1)
    PCA9685.set_channel_value(1,INIT)
    time.sleep(0.1)

    # Back
    PCA9685.set_channel_value(1,BACK)
    time.sleep(5)

    # Stop
    PCA9685.set_channel_value(1,INIT + 1)
    time.sleep(0.1)
    PCA9685.set_channel_value(1,INIT)
    time.sleep(0.1)
    PCA9685.set_channel_value(1,INIT + 1)
    time.sleep(0.1)
    PCA9685.set_channel_value(1,INIT)
    time.sleep(0.1)