Guided Policy Search Ubuntu 18.04 + ROS melodic安装过程

2024-03-19 06:38

本文主要是介绍Guided Policy Search Ubuntu 18.04 + ROS melodic安装过程,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Guided Policy Search Ubuntu 18.04 + ROS melodic安装过程

  • 一 安装依赖
  • 二 下载以及预编译源码
  • 三 ROS Setup
  • 四 安装神经网络库
  • 五 测试GPS示例PR2-example
  • 六 总结

前提已安装 ROS-melodic+gazebo

一 安装依赖

python 使用Python 2.7版本。

pip install numpy
pip install matplotlib
pip install scipy
sudo apt-get install libprotobuf-dev protobuf-compiler libboost-all-dev
pip install protobuf

二 下载以及预编译源码

git clone https://github.com/cbfinn/gps.git
cd gps
./compile_proto.sh

三 ROS Setup

1、Ubuntu 18.04 安装 ROS melodic,可以参照官网Ubuntu install of ROS Melodic .
2、ROS melodic 安装PR2功能包,参照教程ROS Melodic 安装PR2 .
3、将路径添加到~/.bashrc 终端启动文件中:

gedit ~/.bashrc 

在打开的文件最后添加export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/path/to/gps:/path/to/gps/src/gps_agent_pkg,例如:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; thenif [ -f /usr/share/bash-completion/bash_completion ]; then. /usr/share/bash-completion/bash_completionelif [ -f /etc/bash_completion ]; then. /etc/bash_completionfi
fi
source /opt/ros/melodic/setup.bashexport ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/home/eric/gps:/home/eric/gps/src/gps_agent_pkg 

保存之后,source一下:

source ~/.bashrc 

到目前位置,必要的文件已经安装完毕,下面是编译gps包,也是需要填坑的部分。

4、编译 gps

cd ~/gps/src/gps_agent_pkg/
cmake .
make -j

在make -j 这个阶段会出现错误提示 ResourceNotFound: convex_decomposition:

...
ResourceNotFound: convex_decomposition
ROS path [0]=/opt/ros/melodic/share/ros
ROS path [1]=/opt/ros/melodic/share
ROS path [2]=/home/eric/gps
ROS path [3]=/home/eric/gps/src/gps_agent_pkg
...

这是系统缺少convex_decomposition模块导致的,需要先安装:

sudo apt-get install ros-melodic-convex-decomposition

安装完毕之后,再次执行 make -j 又会出现一个错误 ResourceNotFound: ivcon:

ResourceNotFound: ivcon
ROS path [0]=/opt/ros/melodic/share/ros
ROS path [1]=/opt/ros/melodic/share
ROS path [2]=/home/eric/gps
ROS path [3]=/home/eric/gps/src/gps_agent_pkg
ERROR: ivcon
ROS path [0]=/opt/ros/melodic/share/ros
ROS path [1]=/opt/ros/melodic/share
ROS path [2]=/home/eric/gps
ROS path [3]=/home/eric/gps/src/gps_agent_pkg
Traceback (most recent call last):

安装 ivcon:

sudo apt-get install ros-melodic-ivcon

再次执行 make -j ,会出现代码上的错误error: expected constructor, destructor, or type conversion before ‘(’ token PLUGINLIB_DECLARE_CLASS(gps_agent_pkg, GPSPR2Plugin

/home/eric/gps/src/gps_agent_pkg/src/pr2plugin.cpp:235:24: error: expected constructor, destructor, or type conversion before ‘(’ tokenPLUGINLIB_DECLARE_CLASS(gps_agent_pkg, GPSPR2Plugin,^
CMakeFiles/gps_agent_lib.dir/build.make:242: recipe for target 'CMakeFiles/gps_agent_lib.dir/src/pr2plugin.cpp.o' failed
make[2]: *** [CMakeFiles/gps_agent_lib.dir/src/pr2plugin.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
/home/eric/gps/src/gps_agent_pkg/src/robotplugin.cpp: In member function ‘virtual gps_control::Sensor* gps_control::RobotPlugin::get_sensor(gps_control::SensorType, gps::ActuatorType)’:
/home/eric/gps/src/gps_agent_pkg/src/robotplugin.cpp:543:1: warning: control reaches end of non-void function [-Wreturn-type]}^
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/gps_agent_lib.dir/all' failed
make[1]: *** [CMakeFiles/gps_agent_lib.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

出现这个错误的原因是ROS melodic对PLUGINLIB_DECLARE_CLASS改写了,需要我们改写源码,改成PLUGINLIB_EXPORT_CLASS,具体操作如下:

gedit ~/gps/src/gps_agent_pkg/src/pr2plugin.cpp

打开文件pr2plugin.cpp文件之后,最后一个语句需要改写成如下形式:

// Register controller to pluginlib
//PLUGINLIB_DECLARE_CLASS(gps_agent_pkg, GPSPR2Plugin,
//						gps_control::GPSPR2Plugin,
//						pr2_controller_interface::Controller)PLUGINLIB_EXPORT_CLASS(gps_control::GPSPR2Plugin, pr2_controller_interface::Controller)

修改完之后,再次执行 make -j :

make -j
[ 73%] Linking CXX shared library lib/libgps_agent_lib.so
[100%] Built target gps_agent_lib

编译gps_agent_pkg成功!

四 安装神经网络库

官方指导是caffe和tensorflow二选一,这里选用tensorflow 1.14.0

pip install tensorflow

测试一下:

$ python
Python 2.7.17 (default, Jul 20 2020, 15:37:01) 
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> 

没有报错说明安装成功!

五 测试GPS示例PR2-example

1、启动gazeo环境下的pr2

roslaunch gps_agent_pkg pr2_gazebo.launch

会出现如下错误Resource not found: gazebo_worlds:

Resource not found: gazebo_worlds
ROS path [0]=/opt/ros/melodic/share/ros
ROS path [1]=/opt/ros/melodic/share
ROS path [2]=/home/eric/gps
ROS path [3]=/home/eric/gps/src/gps_agent_pkg
The traceback for the exception was written to the log file

这是因为现在的gazebo的功能包名字更改了,需要对pr2_gazebo.launch文件进行更改:

gedit ~/gps/src/gps_agent_pkg/launch/pr2_gazebo_no_controller.launch

具体内容如下:

<launch><!-- Use the following for ROS hydro or later: <include file="$(find gazebo_ros)/launch/empty_world.launch"> --><include file="$(find gazebo_ros)/launch/empty_world.launch"></include><include file="$(find pr2_gazebo)/launch/pr2_no_controllers.launch" /></launch>

2、修改完毕之后,再次运行

roslaunch gps_agent_pkg pr2_gazebo.launch

便可以打开gazebo环境:
在这里插入图片描述
3、运行示例pr2_example

python ~/gps/python/gps/gps_main.py pr2_example

这时会出现错误:AttributeError: ‘AxesSubplot’ object has no attribute ‘set_axis_bgcolor’,

python/gps/agent/ros/ros_utils.py:106: SyntaxWarning: The publisher should be created with an explicit keyword argument 'queue_size'. Please see http://wiki.ros.org/rospy/Overview/Publishers%20and%20Subscribers for more information.self._pub = rospy.Publisher(pub_topic, pub_type)
Traceback (most recent call last):File "python/gps/gps_main.py", line 414, in <module>main()File "python/gps/gps_main.py", line 399, in maingps = GPSMain(hyperparams.config, args.quit)File "python/gps/gps_main.py", line 49, in __init__self.gui = GPSTrainingGUI(config['common']) if config['gui_on'] else NoneFile "python/gps/gui/gps_training_gui.py", line 98, in __init__self._action_output = Textbox(self._fig, self._gs_action_output, border_on=True)File "python/gps/gui/textbox.py", line 41, in __init__self.set_bgcolor(bgcolor, bgalpha)  # this must come after fig.canvas.draw()File "python/gps/gui/textbox.py", line 64, in set_bgcolorself._ax.set_axis_bgcolor(ColorConverter().to_rgba(color, alpha))
AttributeError: 'AxesSubplot' object has no attribute 'set_axis_bgcolor'

这是因为matplotlib库更新的缘故,需要打开对应的函数进行修改:
‘set_axis_bgcolor’ -->set_facecolor’
‘get_axis_bgcolor’ -->get_facecolor’

gedit ~/gps/python/gps/gui/textbox.py
"""
TextboxA Textbox represents the standard textbox. It has basic capabilities for
setting the text, appending text, or changing the background color.
If a log filename is given, all text displayed by the Textbox is also placed
within the log file.
"""
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from matplotlib.colors import ColorConverterclass Textbox:def __init__(self, fig, gs, log_filename=None, max_display_size=10,border_on=False, bgcolor=mpl.rcParams['figure.facecolor'], bgalpha=1.0,fontsize=12, font_family='sans-serif'):self._fig = figself._gs = gridspec.GridSpecFromSubplotSpec(1, 1, subplot_spec=gs)self._ax = plt.subplot(self._gs[0])self._log_filename = log_filenameself._text_box = self._ax.text(0.01, 0.95, '', color='black',va='top', ha='left', transform=self._ax.transAxes,fontsize=fontsize, family=font_family)self._text_arr = []self._max_display_size = max_display_sizeself._ax.set_xticks([])self._ax.set_yticks([])if not border_on:self._ax.spines['top'].set_visible(False)self._ax.spines['right'].set_visible(False)self._ax.spines['bottom'].set_visible(False)self._ax.spines['left'].set_visible(False)self._fig.canvas.draw()self._fig.canvas.flush_events()     # Fixes bug with Qt4Agg backendself.set_bgcolor(bgcolor, bgalpha)  # this must come after fig.canvas.draw()#TODO: Add docstrings here.def set_text(self, text):self._text_arr = [text]self._text_box.set_text('\n'.join(self._text_arr))self.log_text(text)self.draw()def append_text(self, text):self._text_arr.append(text)if len(self._text_arr) > self._max_display_size:self._text_arr = self._text_arr[-self._max_display_size:]self._text_box.set_text('\n'.join(self._text_arr))self.log_text(text)self.draw()def log_text(self, text):if self._log_filename is not None:with open(self._log_filename, 'a') as f:f.write(text + '\n')def set_bgcolor(self, color, alpha=1.0):self._ax.set_facecolor(ColorConverter().to_rgba(color, alpha))self.draw()def draw(self):color, alpha = self._ax.get_facecolor(), self._ax.get_alpha()self._ax.set_facecolor(mpl.rcParams['figure.facecolor'])self._ax.draw_artist(self._ax.patch)self._ax.set_facecolor(ColorConverter().to_rgba(color, alpha))self._ax.draw_artist(self._ax.patch)self._ax.draw_artist(self._text_box)self._fig.canvas.update()self._fig.canvas.flush_events()   # Fixes bug with Qt4Agg backend

再次运行示例:

python ~/gps/python/gps/gps_main.py pr2_example

成功运行!!!
等待一会儿,训练结果就会在gui界面上显示出来。
在这里插入图片描述

六 总结

刚开始接触guided policy search 算法,第一步就有这么多坑,任重而道远!加油。

这篇关于Guided Policy Search Ubuntu 18.04 + ROS melodic安装过程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/825110

相关文章

HTML5 搜索框Search Box详解

《HTML5搜索框SearchBox详解》HTML5的搜索框是一个强大的工具,能够有效提升用户体验,通过结合自动补全功能和适当的样式,可以创建出既美观又实用的搜索界面,这篇文章给大家介绍HTML5... html5 搜索框(Search Box)详解搜索框是一个用于输入查询内容的控件,通常用于网站或应用程

canal实现mysql数据同步的详细过程

《canal实现mysql数据同步的详细过程》:本文主要介绍canal实现mysql数据同步的详细过程,本文通过实例图文相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的... 目录1、canal下载2、mysql同步用户创建和授权3、canal admin安装和启动4、canal

Nexus安装和启动的实现教程

《Nexus安装和启动的实现教程》:本文主要介绍Nexus安装和启动的实现教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Nexus下载二、Nexus安装和启动三、关闭Nexus总结一、Nexus下载官方下载链接:DownloadWindows系统根

MySQL存储过程之循环遍历查询的结果集详解

《MySQL存储过程之循环遍历查询的结果集详解》:本文主要介绍MySQL存储过程之循环遍历查询的结果集,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录前言1. 表结构2. 存储过程3. 关于存储过程的SQL补充总结前言近来碰到这样一个问题:在生产上导入的数据发现

SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程

《SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程》LiteFlow是一款专注于逻辑驱动流程编排的轻量级框架,它以组件化方式快速构建和执行业务流程,有效解耦复杂业务逻辑,下面给大... 目录一、基础概念1.1 组件(Component)1.2 规则(Rule)1.3 上下文(Conte

Java SWT库详解与安装指南(最新推荐)

《JavaSWT库详解与安装指南(最新推荐)》:本文主要介绍JavaSWT库详解与安装指南,在本章中,我们介绍了如何下载、安装SWTJAR包,并详述了在Eclipse以及命令行环境中配置Java... 目录1. Java SWT类库概述2. SWT与AWT和Swing的区别2.1 历史背景与设计理念2.1.

安装centos8设置基础软件仓库时出错的解决方案

《安装centos8设置基础软件仓库时出错的解决方案》:本文主要介绍安装centos8设置基础软件仓库时出错的解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录安装Centos8设置基础软件仓库时出错版本 8版本 8.2.200android4版本 javas

Ubuntu设置程序开机自启动的操作步骤

《Ubuntu设置程序开机自启动的操作步骤》在部署程序到边缘端时,我们总希望可以通电即启动我们写好的程序,本篇博客用以记录如何在ubuntu开机执行某条命令或者某个可执行程序,需要的朋友可以参考下... 目录1、概述2、图形界面设置3、设置为Systemd服务1、概述测试环境:Ubuntu22.04 带图

Spring Boot 整合 Apache Flink 的详细过程

《SpringBoot整合ApacheFlink的详细过程》ApacheFlink是一个高性能的分布式流处理框架,而SpringBoot提供了快速构建企业级应用的能力,下面给大家介绍Spri... 目录Spring Boot 整合 Apache Flink 教程一、背景与目标二、环境准备三、创建项目 & 添

pytest+allure环境搭建+自动化实践过程

《pytest+allure环境搭建+自动化实践过程》:本文主要介绍pytest+allure环境搭建+自动化实践过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、pytest下载安装1.1、安装pytest1.2、检测是否安装成功二、allure下载安装2.