``` from robot import Robot from dynamixel import Dynamixel import numpy as np import time import mujoco.viewer from simulation.interface import SimulatedRobot import threading def read_leader_position(): global target_pos while True: target_pos = np.array(leader.read_position()) target_pos = (target_pos / 2048 - 1) * 3.14 target_pos[1] = -target_pos[1] target_pos[3] = -target_pos[3] target_pos[4] = -target_pos[4] leader_dynamixel = Dynamixel.Config(baudrate=1_000_000, device_name='/dev/tty.usbmodem57380045631').instantiate() leader = Robot(leader_dynamixel, servo_ids=[1, 2, 3, 6, 7]) leader.set_trigger_torque() m = mujoco.MjModel.from_xml_path('simulation/low_cost_robot/scene.xml') d = mujoco.MjData(m) r = SimulatedRobot(m, d) target_pos = np.zeros(5) # Start the thread for reading leader position leader_thread = threading.Thread(target=read_leader_position) leader_thread.daemon = True leader_thread.start() with mujoco.viewer.launch_passive(m, d) as viewer: start = time.time() while viewer.is_running(): # Use the latest target_pos step_start = time.time() target_pos_local = target_pos.copy() # print(f'target pos copy {time.time() - step_start}') r.set_target_pos(target_pos_local) # print(f'set targtee pos copy {time.time() - step_start}') mujoco.mj_step(m, d) # print(f'mjstep {time.time() - step_start}') viewer.sync() # print(f'viewer sync {time.time() - step_start}') # Rudimentary time keeping, will drift relative to wall clock. time_until_next_step = m.opt.timestep - (time.time() - step_start) # print(f'time until next step {time_until_next_step}') if time_until_next_step > 0: time.sleep(time_until_next_step) ``` error: No such file or directory: '/dev/tty.usbmodem57380045631'

2024-04-12by@tim&@ChatGPT.Model: GPT-4
tim
from robot import Robot
from dynamixel import Dynamixel
import numpy as np
import time
import mujoco.viewer
from simulation.interface import SimulatedRobot
import threading

def read_leader_position():
    global target_pos
    while True:
        target_pos = np.array(leader.read_position())
        target_pos = (target_pos / 2048 - 1) * 3.14
        target_pos[1] = -target_pos[1]
        target_pos[3] = -target_pos[3]
        target_pos[4] = -target_pos[4]

leader_dynamixel = Dynamixel.Config(baudrate=1_000_000, device_name='/dev/tty.usbmodem57380045631').instantiate()
leader = Robot(leader_dynamixel, servo_ids=[1, 2, 3, 6, 7])
leader.set_trigger_torque()

m = mujoco.MjModel.from_xml_path('simulation/low_cost_robot/scene.xml')
d = mujoco.MjData(m)

r = SimulatedRobot(m, d)

target_pos = np.zeros(5)

# Start the thread for reading leader position
leader_thread = threading.Thread(target=read_leader_position)
leader_thread.daemon = True
leader_thread.start()

with mujoco.viewer.launch_passive(m, d) as viewer:
    start = time.time()
    while viewer.is_running():
        # Use the latest target_pos
        step_start = time.time()
        target_pos_local = target_pos.copy()
        # print(f'target pos copy {time.time() - step_start}')
        r.set_target_pos(target_pos_local)
        # print(f'set targtee pos copy {time.time() - step_start}')
        mujoco.mj_step(m, d)
        # print(f'mjstep {time.time() - step_start}')
        viewer.sync()
        # print(f'viewer sync {time.time() - step_start}')

        # Rudimentary time keeping, will drift relative to wall clock.
        time_until_next_step = m.opt.timestep - (time.time() - step_start)
        # print(f'time until next step {time_until_next_step}')
        if time_until_next_step > 0:
            time.sleep(time_until_next_step)

error: No such file or directory: '/dev/tty.usbmodem57380045631'

Avatar
Avatar

The error message you encountered indicates that the system cannot find the device specified by the path /dev/tty.usbmodem57380045631. This issue typically arises when the device is not connected, the device name has changed, or the device is not recognized correctly by the system. Here are some steps to troubleshoot and resolve the issue:

  1. Check Device Connection:

    • Ensure the Dynamixel or other USB device is properly connected to the computer. Sometimes, simply unplugging and replugging the device can help.
  2. Verify Device Name:

    • The name of the device in /dev/ can change based on the order of connection or if other devices are connected/disconnected. You can list the devices in the /dev/ directory before and after connecting your device to see which new device appears. Use the ls /dev/tty.* command in the terminal to list serial devices. Look for something that resembles your device, which might not exactly match the initial name you used.
  3. Permissions:

    • Sometimes, the issue might be due to insufficient permissions to access the device. You can try accessing it with elevated permissions using sudo (be cautious with its use, and ensure you understand the commands you're running as root). If this solves the issue, you might want to set up proper udev rules to grant non-root users access to the device.
  4. Device Drivers:

    • Ensure that the correct drivers for your device are installed. Some devices might require specific drivers or configurations to be recognized and used by your system.
  5. Alternative Approach:

    • If you're unable to get the device name to work, consider using a more generic approach to identify your device, such as by its product ID and vendor ID. This can be more reliable but requires additional setup.
  6. Test with a Simpler Script:

    • Before running your full script, try accessing the device with a simpler script or terminal command to ensure the basic connectivity and permissions are correct. For instance, you can try using a terminal program like screen or minicom to open the device path and check if you can communicate with it.
  7. Update Your Script:

    • Once you find the correct device name, update the device_name parameter in your script accordingly. Double-check that there are no typos and that the name matches exactly what your system recognizes.

If, after following these steps, you're still facing issues, it might be helpful to provide more details about your setup, such as the operating system you're using, any specific configurations you've done related to serial devices, and the exact model of the device you're trying to connect to. This information could offer more clues as to why the device is not being recognized.