async def main(loop): # 初期化 # si = SerialInterface(baudrate=3000000) si = SerialInterface(baudrate=1000000) robotis = RobotisP20(si) sid = 1 # ping = await robotis.ping_async(sid) # print(ping) robotis.set_torque_enable(True, sid=sid) time.sleep(0.5) # print('Current position:', robotis.get_current_position(sid)) # print('Enable Torque?:', robotis.get_torque_enable(sid=sid)) # 0.5秒ごとにサーボを動かす for i in range(11): # print('Current position:', robotis.get_current_position(sid)) angle = i * 20 - 100 print('Angle:', angle, 'deg') robotis.set_target_position(angle, sid=sid) # print('Target position:', robotis.get_target_position(sid)) time.sleep(0.5) # クローズ robotis.close(force=False) si.close()
async def main(loop): try: # Initialize SerialInterface & servo object si = SerialInterface() futaba = Futaba(si) # Get voltage voltage = await futaba.get_voltage_async(sid=1) print('Voltage: %.2f(V)' % voltage) # Close SerialInterface & servo object futaba.close() si.close() except Exception as e: print('Error', e)
async def main(loop): try: # 初期化 si = SerialInterface(device='/dev/tty.usbserial-A601X0TE') futaba = Futaba(si) # futaba.reset_memory(sid=1) futaba.set_torque_enable(False, sid=1) # futaba.set_baud_rate(Futaba.BAUD_RATE_INDEX_115200, sid=1) # futaba.set_servo_id(1, sid=2) # futaba.set_limit_cw_position(150, sid=1) # futaba.set_limit_ccw_position(-10, sid=1) # futaba.write_flash_rom(sid=1) # futaba.set_pid_coefficient(255, sid=1) # futaba.set_speed(0, sid=1) futaba.set_torque_enable(True, sid=1) futaba.set_target_position(120, sid=1) await asyncio.sleep(3) # futaba.set_target_position(-120, sid=1) futaba.set_burst_target_positions({1: -120}) # v = futaba.get_pid_coefficient(sid=1) # await asyncio.sleep(0.1) # data = futaba.get_limit_ccw_position(sid=1) # data = futaba.get_limit_cw_position(sid=1) # data = futaba.get_limit_temperature(sid=1) # data = futaba.get_servo_id(sid=1) # data = futaba.get_target_position(sid=2) # v = await futaba.get_pid_coefficient_async(sid=1, loop=loop) # print('######', data) # クローズ futaba.close(force=False) si.close() except Exception as e: print('Error', e)
futaba = Futaba(si) # 電圧をreadで取得 response_data = futaba.read(1, Futaba.ADDR_VOLTAGE_L, 2) voltage = int.from_bytes(response_data, 'little', signed=True) voltage /= 100 print('Voltage: {}(V)'.format(voltage)) # トルクON futaba.write(1, Futaba.ADDR_TORQUE_ENABLE, [1]) # ポジション設定 for position_degree in [0, 50, 0, -50, 0]: # ADDR_GOAL_POSITION_L 30 (0x1E), ADDR_GOAL_POSITION_H 31 (0x1F) なので # AddressにはADDR_GOAL_POSITION_Lを指定してDataを2バイト書き込む position_hex = format(int(position_degree * 10) & 0xffff, '04x') position_hex_h = int(position_hex[0:2], 16) position_hex_l = int(position_hex[2:4], 16) futaba.write(1, Futaba.ADDR_GOAL_POSITION_L, [position_hex_l, position_hex_h]) # 1秒待機 time.sleep(1.0) # クローズ futaba.close() si.close() except Exception as e: print('Error', e)