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)
def __init__(self): super().__init__('gs2d_ros2_driver') self.get_logger().info('Yes! initializing...') # self.pub_current_position = self.create_publisher(Float32, '/gs2d_ros2_driver/current_position', 10) self.sub_target_position = self.create_subscription( TargetPosition, '/gs2d_ros2_driver/target_position', self.target_position_callback, 10) self.sub_torque_enable = self.create_subscription( TorqueEnable, '/gs2d_ros2_driver/torque_enable', self.torque_enable_callback, 10) self.si = SerialInterface(baudrate=1000000) self.robotis = RobotisP20(self.si)
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)
# encoding: utf-8 import sys import time import logging sys.path.insert(0, '../..') from gs2d import SerialInterface, Futaba # ログ設定 logging.basicConfig() logging.getLogger('gs2d').setLevel(level=logging.DEBUG) try: # 初期化 si = SerialInterface() 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バイト書き込む
#! /usr/bin/env python3 # encoding: utf-8 import sys import logging sys.path.insert(0, '../..') from gs2d import SerialInterface, RobotisP20 # ログ設定 logging.basicConfig() logging.getLogger('gs2d').setLevel(level=logging.DEBUG) try: # 初期化 si = SerialInterface(baudrate=3000000) robotis = RobotisP20(si) sid = 1 # 電圧取得 temperature = robotis.get_temperature(sid=sid) print('Temperature: %.2f(degC)' % temperature) # クローズ robotis.close() si.close() except Exception as e: print('Error', e)