コード例 #1
0
def connection(id):
    global dev_list
    print("{} connecting...".format(id))
    if id not in dev_list:
        return
    if dev_list[id] != None:
        return
    device_info = devices[id]
    dev = blecontroller.BLEController(device_info["mac"])
    dev.enable_action()
    dev.enable_continual_imu_measurement()
    dev.stop_motor()
    dev.set_speed(device_info["speed"])
    return dev
コード例 #2
0
    sys.stdout.write(prompt)
    sys.stdout.flush()
    (ready, _, _) = select.select([sys.stdin], [], [], timeout)
    if ready:
        return sys.stdin.readline().rstrip('\n')
    else:
        return 0

current_dir = pathlib.Path(__file__).resolve().parent
sys.path.insert(0, str(current_dir) + '/../') # give 1st priority to the directory where pykeigan exists

from time import sleep
from pykeigan import blecontroller
from pykeigan import utils

dev=blecontroller.BLEController("fe:e1:8c:0a:7d:a0")#下モータ
dev2=blecontroller.BLEController("ef:23:f5:42:8f:be")#上モータ

speed = utils.rpm2rad_per_sec(10)

dev.enable_action()
dev.set_led(1, 0, 200, 0)
dev.set_speed(speed)
dev.move_to_pos(0.3)
sleep(3)

dev2.enable_action()
dev2.set_led(1, 0, 200, 0)
dev2.set_speed(speed)
dev2.set_max_torque(100)
dev2.move_to_pos(-2.9)
コード例 #3
0
            print('status {} '.format(dev.read_status()), end="", flush=True)

            print("\033[8;2H\033[2K", end="", flush=True)
            print('measurement {} '.format(dev.read_motor_measurement()),
                  end="",
                  flush=True)

            print("\033[12;2H\033[2K", end="", flush=True)
            print('imu_measurement {} '.format(dev.read_imu_measurement()),
                  end="",
                  flush=True)
        sleep(0.5)


#接続
dev = blecontroller.BLEController(
    "FB:78:30:D3:7C:2F")  #モーターのMACアドレス 参照 ble-simple-connection.py
dev.set_led(2, 255, 255, 0)
dev.enable_continual_imu_measurement()  #IMUは通知をOnにする必要がある
sleep(0.5)

#一定間隔で取得
executor = ThreadPoolExecutor(max_workers=2)
res = executor.submit(get_motor_informations)
"""
Exit with key input
"""
os.system('clear')
for i in range(20):
    print("       ")
print("\033[17;2H", end="")
print("---------------------------------------")
コード例 #4
0
from pykeigan import blecontroller
from pykeigan import utils
"""
----------------------
モーターへの接続
----------------------
    モーターのMACアドレスについて
        MACアドレスは"nRF Connect"を使用して調べる事が可能です。 
        https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp
        
        Bluetoohでモーターが検出されない場合は、モーターの"インターフェイスのリセット"を実行して下さい。
        https://document.keigan-motor.com/basic/reset
"""

dev = blecontroller.BLEController("C1:C5:89:AE:3F:CD")  #モーターのMACアドレス
dev.set_led(
    2, 255, 255, 0
)  # (LEDflash:2,R:255,G:255,B:0) https://document.keigan-motor.com/software_dev/lowapis/led
dev.enable_action()  #安全装置。初めてモーターを動作させる場合に必ず必要。
dev.set_speed(utils.rpm2rad_per_sec(5))  #rpm -> radian/sec
dev.run_forward()
"""
Exit with key input
"""
while True:
    print("---------------------------------------")
    inp = input('Exit:[key input] >>')
    if inp != None:
        dev.set_led(1, 100, 100, 100)
        dev.disable_action()
コード例 #5
0
current_dir = pathlib.Path(__file__).resolve().parent
sys.path.insert(0, str(current_dir) + '/../') # give 1st priority to the directory where pykeigan exists

from time import sleep
from pykeigan import blecontroller
from pykeigan import utils

"""
----------------------
モーターを5rpmで 正転(10秒) -> 逆転(10秒) -> 停止(トルクあり) -> 停止(トルク無し)
----------------------

"""

dev=blecontroller.BLEController("d1:5a:fa:a7:d9:5d")#モーターのMACアドレス 参照 ble-simple-connection.py
dev.enable_action()#安全装置。初めてモーターを動作させる場合に必ず必要。
dev.set_speed(utils.rpm2rad_per_sec(5))#rpm -> radian/sec

dev.set_led(1, 0, 200, 0)
dev.run_forward()

sleep(10)

dev.set_led(1, 0, 0, 200)
dev.run_reverse()

sleep(10)

dev.set_led(1, 200, 0, 0)
dev.stop_motor()
コード例 #6
0
def connection(dev,macdress):
    target_dev = blecontroller.BLEController(macdress)
    target_dev.set_led(2,255,255,0)# (LEDflash:2,R:255,G:255,B:0) https://document.keigan-motor.com/software_dev/lowapis/led
コード例 #7
0
            print("\033[8;2H\033[2K", end="", flush=True)
            print('measurement {} '.format(dev.read_motor_measurement()),
                  end="",
                  flush=True)

            print("\033[12;2H\033[2K", end="", flush=True)
            print('imu_measurement {} '.format(dev.read_imu_measurement()),
                  end="",
                  flush=True)
        sleep(0.5)


#接続
#dev=blecontroller.BLEController("fe:e1:8c:0a:7d:a0")#下モータ
dev = blecontroller.BLEController("ef:23:f5:42:8f:be")  #上モータ
dev.set_led(2, 255, 255, 0)
dev.enable_continual_imu_measurement()  #IMUは通知をOnにする必要がある
sleep(0.5)

#一定間隔で取得
executor = ThreadPoolExecutor(max_workers=2)
res = executor.submit(get_motor_informations)
"""
Exit with key input
"""
os.system('clear')
for i in range(20):
    print("       ")
print("\033[17;2H", end="")
print("---------------------------------------")
コード例 #8
0
sys.path.insert(
    0,
    str(current_dir) +
    '/../')  # give 1st priority to the directory where pykeigan exists

from time import sleep
from pykeigan import blecontroller
from pykeigan import utils
"""
----------------------
モーターを5rpmで 正転(10秒) -> 逆転(10秒) -> 停止(トルクあり) -> 停止(トルク無し)
----------------------

"""

dev = blecontroller.BLEController(
    "fe:e1:8c:0a:7d:a0")  #モーターのMACアドレス 参照 ble-simple-connection.py
dev.enable_action()  #安全装置。初めてモーターを動作させる場合に必ず必要。
dev.set_speed(utils.rpm2rad_per_sec(1))  #rpm -> radian/sec

dev.set_led(1, 0, 200, 0)
dev.run_forward()

sleep(10)

dev.set_led(1, 0, 0, 200)
dev.run_reverse()

sleep(10)

dev.set_led(1, 200, 0, 0)
dev.stop_motor()
コード例 #9
0
from pykeigan import blecontroller
from pykeigan import utils

"""
----------------------
モーターへの接続
----------------------
    モーターのMACアドレスについて
        MACアドレスは"nRF Connect"を使用して調べる事が可能です。 
        https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp
        
        Bluetoohでモーターが検出されない場合は、モーターの"インターフェイスのリセット"を実行して下さい。
        https://document.keigan-motor.com/basic/reset
"""

dev=blecontroller.BLEController("d1:5a:fa:a7:d9:5d")#モーターのMACアドレス
dev.set_led(2,255,255,0)# (LEDflash:2,R:255,G:255,B:0) https://document.keigan-motor.com/software_dev/lowapis/led
dev.enable_action()#安全装置。初めてモーターを動作させる場合に必ず必要。
dev.set_speed(utils.rpm2rad_per_sec(5))#rpm -> radian/sec
dev.run_forward()

"""
Exit with key input
"""
while True:
    print("---------------------------------------")
    inp = input('Exit:[key input] >>')
    if inp !=None:
        dev.set_led(1, 100, 100, 100)
        dev.disable_action()
        dev.disconnect()