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'
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:
Check Device Connection:
Verify Device Name:
/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.Permissions:
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.Device Drivers:
Alternative Approach:
Test with a Simpler Script:
screen
or minicom
to open the device path and check if you can communicate with it.Update Your Script:
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.