目前在研究mobile aloha的训练算法部分,运行文件为imitate_episodes.py,对应指令:
# To train ACT: python3 imitate_episodes.py --task_name mobile_imu --ckpt_dir /home/song/hjx/aloha/mobile-aloha_multi-sensor/ckpt/mobile_imu --policy_class ACT --kl_weight 80 --chunk_size 100 --hidden_dim 512 --batch_size 8 --dim_feedforward 3200 --num_epochs 8000 --lr 1e-5 --seed 0
在运行代码时遇到了报错,使用的是pycharm编辑器。报错如下:
Traceback (most recent call last):
File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/act/imitate_episodes.py", line 437, in <module>
main(vars(parser.parse_args()))
File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/act/imitate_episodes.py", line 42, in main
from aloha_scripts.constants import TASK_CONFIGS
File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/__init__.py", line 1, in <module>
from aloha_scripts.robot_utils import *
File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/robot_utils.py", line 4, in <module>
from interbotix_xs_msgs.msg import JointSingleCommand
ModuleNotFoundError: No module named 'interbotix_xs_msgs'
原因是pycharm编辑器找不到interbotix_xs_msgs这个模块。
解决方案为添加如下路径:
添加完成后的路径为:
重新run, 该报错便可解决!
另外,在运行imitate_episodes.py文件时,还遇到如下报错:
Traceback (most recent call last):
File "imitate_episodes.py", line 437, in <module>
main(vars(parser.parse_args()))
File "imitate_episodes.py", line 45, in main
num_episodes = task_config['num_episodes']
KeyError: 'num_episodes'
这个报错的原因是num_episodes没有定义出来,在如下代码段处跳入constants.py:
在对应的训练任务参数中添加:
"num_episodes": 50
重新run,该报错便可解决!
注意:act的软件训练代码与aloha_scripts硬件代码要放在同一文件夹中
下面是eval环节:
在首次运行时遇到报错:
Traceback (most recent call last): File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/act/imitate_episodes.py", line 437, in <module> main(vars(parser.parse_args())) File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/act/imitate_episodes.py", line 95, in main success_rate, avg_return = eval_bc(config, ckpt_name, save_episode=True) File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/act/imitate_episodes.py", line 183, in eval_bc from aloha_scripts.real_env import make_real_env # requires aloha File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/real_env.py", line 16, in <module> import pyagxrobots File "/home/song/anaconda3/envs/aloha/lib/python3.8/site-packages/pyagxrobots/__init__.py", line 5, in <module> from pyagxrobots import pysdkugv File "/home/song/anaconda3/envs/aloha/lib/python3.8/site-packages/pyagxrobots/pysdkugv.py", line 6, in <module> from wrapt.wrappers import transient_function_wrapper ImportError: cannot import name 'transient_function_wrapper' from 'wrapt.wrappers' (/home/song/anaconda3/envs/aloha/lib/python3.8/site-packages/wrapt/wrappers.py)
解决方案:
修改导入语句:如果wrapt
库是最新的,那么你需要修改导入语句。在pyagxrobots/pysdkugv.py
文件中,将导入语句从:
from wrapt.wrappers import transient_function_wrapper
修改为:
from wrapt import transient_function_wrapper
即可解决
后续又遇到这个报错:
Traceback (most recent call last): File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/act/imitate_episodes.py", line 437, in <module> main(vars(parser.parse_args())) File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/act/imitate_episodes.py", line 95, in main success_rate, avg_return = eval_bc(config, ckpt_name, save_episode=True) File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/act/imitate_episodes.py", line 183, in eval_bc from aloha_scripts.real_env import make_real_env # requires aloha File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/real_env.py", line 17, in <module> from dynamixel_client import DynamixelClient ModuleNotFoundError: No module named 'dynamixel_client'
错误信息表明你的Python环境中缺少名为dynamixel_client
的模块。这个模块可能是用于控制Dynamixel系列伺服电机的自定义Python包。
解决方案:
sudo apt-get install ros-$ROS_DISTRO-dynamixel-sdk
但发现:ros-noetic-dynamixel-sdk 已经是最新版 (3.7.51-4focal.20230620.184449)。
说明dynamixel是已经安装好的
后来才发现,应该将这段代码:
from dynamixel_client import DynamixelClient
修改为:
from aloha_scripts.dynamixel_client import DynamixelClient
即可解决
最后又遇到了这个报错提示:
<All keys matched successfully>
Loaded: /home/song/hjx/aloha/mobile-aloha_multi-sensor/act/ckpt/mobile_imu/policy_best.ckpt
Unable to register with master node [http://localhost:11311]: master may not be running yet. Will keep trying.
这个错误通常意味着你的脚本尝试连接到ROS Master(roscore
),但是没有成功。
以下是一些可能的解决步骤:
- 确保
roscore
正在运行:在一个新的终端中运行roscore
来启动ROS Master。 - 检查网络连接:确保你的机器可以访问运行
roscore
的机器。如果你在本地机器上运行,确保ROS_MASTER_URI
环境变量设置为http://localhost:11311
。 - 检查防火墙设置:确保没有防火墙规则阻止了与
roscore
的通信。
🍀了,这个时候直接放弃pycharm编辑器运行,改用终端运行!
可能会遇到该报错:
ModuleNotFoundError: No module named 'serial' Exception ignored in: <function DynamixelClient.__del__ at 0x7fefae64faf0> Traceback (most recent call last): File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/dynamixel_client.py", line 346, in __del__ self.disconnect() File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/dynamixel_client.py", line 169, in disconnect if not self.is_connected: File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/dynamixel_client.py", line 140, in is_connected return self.port_handler.is_open AttributeError: 'DynamixelClient' object has no attribute 'port_handler'
解决方案:
pip install pyserial
还有一个非常关键的报错,双臂能启动了目前,但终端报错:
Traceback (most recent call last):
File "/home/song/anaconda3/envs/aloha/lib/python3.8/site-packages/serial/serialposix.py", line 322, in open
self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
FileNotFoundError: [Errno 2] No such file or directory: '/dev/ttyDXL_wheels'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "imitate_episodes.py", line 437, in <module>
main(vars(parser.parse_args()))
File "imitate_episodes.py", line 95, in main
success_rate, avg_return = eval_bc(config, ckpt_name, save_episode=True)
File "imitate_episodes.py", line 209, in eval_bc
ts = env.reset()
File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/real_env.py", line 185, in reset
observation=self.get_observation())
File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/real_env.py", line 166, in get_observation
obs['base_vel'] = self.get_base_vel()
File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/real_env.py", line 129, in get_base_vel
left_vel, right_vel = self.dxl_client.read_pos_vel_cur()[1]
File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/dynamixel_client.py", line 212, in read_pos_vel_cur
return self._pos_vel_cur_reader.read()
File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/dynamixel_client.py", line 376, in read
self.client.check_connected()
File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/dynamixel_client.py", line 302, in check_connected
self.connect()
File "/home/song/hjx/aloha/mobile-aloha_multi-sensor/aloha_scripts/dynamixel_client.py", line 150, in connect
if self.port_handler.openPort():
File "/opt/ros/noetic/lib/python3/dist-packages/dynamixel_sdk/port_handler.py", line 44, in openPort
return self.setBaudRate(self.baudrate)
File "/opt/ros/noetic/lib/python3/dist-packages/dynamixel_sdk/port_handler.py", line 68, in setBaudRate
return self.setupPort(baud)
File "/opt/ros/noetic/lib/python3/dist-packages/dynamixel_sdk/port_handler.py", line 114, in setupPort
self.ser = serial.Serial(
File "/home/song/anaconda3/envs/aloha/lib/python3.8/site-packages/serial/serialutil.py", line 244, in __init__
self.open()
File "/home/song/anaconda3/envs/aloha/lib/python3.8/site-packages/serial/serialposix.py", line 325, in open
raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyDXL_wheels: [Errno 2] No such file or directory: '/dev/ttyDXL_wheels'
这个错误信息表明你的程序试图打开一个串行端口/dev/ttyDXL_wheels
,但是在系统中找不到这个端口。这通常发生在尝试与串行设备(如Dynamixel伺服电机)通信时,设备的端口路径不正确或设备未正确连接。
解决步骤:
-
检查设备连接:确保你的Dynamixel设备已经正确连接到计算机,并且连接线没有问题。
-
检查端口名称:端口名称
/dev/ttyDXL_wheels
可能不正确或不符合你的系统。通常,Linux系统中的串行端口名称类似于/dev/ttyUSB0
、/dev/ttyACM0
等。你可以使用以下命令来列出所有可用的串行设备:
ls /dev/tty*
或者,使用dmesg
命令来查看设备的内核日志,以确定正确的端口名称:
dmesg | grep tty
3.检查设备管理器:在Linux系统中,你可以使用lsusb
命令来检查USB设备列表,以确保你的设备被正确识别。
lsusb
关键报错信息:
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyDXL_wheels: [Errno 2] No such file or directory: '/dev/ttyDXL_wheels'
后来发现:这个错误表明你的程序试图连接到一个不存在的串行端口/dev/ttyDXL_wheels
。
/dev/ttyDXL_wheels这个串行端口确实不存在!因为我们用的不是斯坦福他们用的松灵底盘。