def init_movehub(): mh = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI) mh.start() mh.subscribe_all() mh.listen_hubtilt(MODE_HUBTILT_BASIC) mh.listen_colordist_sensor(PORT_D) mh.listen_angle_sensor(PORT_C) if mh.is_connected(): print(('Is connected: ', mh.is_connected())) return mh
#!/usr/bin/env python3 from pyb00st.movehub import MoveHub from pyb00st.constants import * from time import sleep import os MY_MOVEHUB_ADD = os.environ.get('MYMOVEHUB') MY_BTCTRLR_HCI = 'hci0' mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI) try: mymovehub.start() mymovehub.subscribe_all() mymovehub.listen_angle_sensor(PORT_D) mymovehub.listen_colordist_sensor(PORT_C) while True: sleep(0.2) print('Motor D: {} Color: {}'.format(mymovehub.last_angle_D, mymovehub.last_color_C)) finally: mymovehub.stop()
from utopia2output import * from time import sleep from pyb00st.movehub import MoveHub from pyb00st.constants import * mymovehub = MoveHub('00:16:53:a5:6f:8a', 'Auto', 'hci0') try: mymovehub.start() mymovehub.subscribe_all() mymovehub.listen_angle_sensor(PORT_C) mymovehub.listen_angle_sensor(PORT_A) mymovehub.listen_angle_sensor(PORT_B) except: print('Cannot connect to Boost.') # define our action functions def head(objID): start_angle_c = mymovehub.last_angle_C print('move head') try: mymovehub.run_motor_for_angle(MOTOR_C, 90, -20) sleep(1) mymovehub.run_motor_for_angle(MOTOR_C, 270, 20) sleep(2) mymovehub.run_motor_for_angle(MOTOR_C, 180, -50) sleep(2) mymovehub.run_motor_for_angle(MOTOR_C, 100, 10) sleep(2)