简体   繁体   English

Python2.7 和 Python3 模块之间的 ROS 消息

[英]ROS messages between Python2.7 and Python3 modules

I am currently working on a reinforcement learning module required to receive and send state, action and reward information from ROS in Python 2.7.我目前正在研究一个强化学习模块,需要在 Python 2.7 中从 ROS 接收和发送状态、动作和奖励信息。 This is a hard constraint, due to the rest of the system.由于系统的其余部分,这是一个硬约束。

I'd like to use the OpenAI gym environment and baselines for my reinforcement learning agent but these come with Python 3.5+.我想将OpenAI 健身房环境和基线用于我的强化学习代理,但这些都随 Python 3.5+ 一起提供。

My question as a novel robotics fellow, is it possible to receive ROS messages from Py2.7 to Py3.5+ and send them back to Py2.7?我作为一个新奇的机器人研究员的问题是,是否可以从 Py2.7 到 Py3.5+ 接收 ROS 消息并将它们发送回 Py2.7? I was given the advice to use UDPROS for that purpose but I lack the experience on how this would look like.我得到了为此目的使用UDPROS的建议,但我缺乏这方面的经验。 Is this the right way, are there better ways?这是正确的方法,还有更好的方法吗?

Is this not a common problem for larger systems that depend on legacy code in Python2.7?对于依赖 Python2.7 中遗留代码的大型系统来说,这不是一个常见问题吗?

I've been confused by exactly the same problem for a couple of days.几天来,我一直被完全相同的问题弄糊涂了。 I'm not sure which distro of ROS you are using but I supposed it's Kinetic since you mentioned that it only supports python2.我不确定您使用的是哪个 ROS 发行版,但我认为它是 Kinetic,因为您提到它仅支持 python2。

I've solved the problem on my laptop(ubuntu 16.0.4, ROS Kinetic)by creating a virtual environment of python3, and run both ros and baselines in that virtual environment.我已经通过创建 python3 的虚拟环境解决了我的笔记本电脑(ubuntu 16.0.4,ROS Kinetic)上的问题,并在该虚拟环境中运行 ros 和基线。 It seems like when there is no python2 in the environment the ROS Kinetic can still work well with those basic functions(such as publish and subscribe to a topic...).看起来当环境中没有 python2 时,ROS Kinetic 仍然可以很好地处理那些基本功能(例如发布和订阅主题......)。

Besides, I have solved the problem on my PC(ubuntu 18, ROS Melodic).此外,我已经在我的 PC(ubuntu 18,ROS Melodic)上解决了这个问题。 Melodic supports python3 so that you can run baselines and ROS both on python3 in this way. Melodic 支持 python3,因此您可以通过这种方式在 python3 上运行基线和 ROS。

Hope this would help you.希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM