转载:在 Ubuntu16.04 中使用ROS与PostgreSQL配置 household_objects_database

版权声明:本文转自博主CVBoy2010原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文原链接: https://blog.csdn.net/oDaHaiTaoTao/article/details/85062444

英文原档请查看: http://wiki.ros.org/household_objects_database

household_objects_database简介

Class definitions and a few convenience functions for interfacing with a specific SQL database, containing 3D models of a set of common household objects.
ROS WiKi: http://wiki.ros.org/household_objects_database

1 在本地安装数据库

1.1 安装 PostgreSQL Server
sudo apt-get install postgresql

   
   
  • 1
1.2 修改 pg_hba.conf 文件
$ sudo gedit /etc/postgresql/9.4/main/pg_hba.conf
// 修改为如下形式
# Database administrative login by UNIX sockets
local   all         postgres                          ident sameuser
// 重启 postgresql 服务
$ sudo service postgresql reload

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
1.3 为数据库添加用户
// 登录数据库控制台
$ sudo -u postgres psql
// 创建新用户名,willow用户用于测试示例代码
CREATE ROLE willow LOGIN CREATEDB CREATEROLE PASSWORD 'willow';

   
   
  • 1
  • 2
  • 3
  • 4
1.4 安装 PGAdmin3
$ sudo apt-get install pgadmin3

   
   
  • 1

2. 安装 the household_objects_database

2.1 Database Creation
1. 启动 pgadmin3, 新建数据库连接,连接到 PostgreSQL server.
2. 在服务器下拉列表中, 右击 数据库,选择 新建数据库 ...
3. 创建数据名称 (如 household_objects-0.2) 并 点击 确认 按钮.

   
   
  • 1
  • 2
  • 3
2.2 从备份文件中恢复数据库信息
// Download the desired version of the database backup file from Willow Garage. 
git clone https://github.com/ros-interactive-manipulation/household_objects_database_backups.git
// Note that if a backup file is called *-schema.backup it will only 
// contain the schema of the database, but no data.

   
   
  • 1
  • 2
  • 3
  • 4

After downloading the backup file, go back to pgadmin3. Right-click your newly created database, and click Restore… Point the dialog to the backup file you downloaded and click OK. Wait for the restoration to finish, then close the dialog.

2.3 使用数据库
  1. 创建ROS的工作空间
$ mkdir -p catkin_kris/src
$ cd catkin_kris/src
src$ catkin_init_space
catkin_kris$ cd ..
catkin_kris$ catkin_make
catkin_kris$ source devel/setup.bash

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  1. git源码文件
catkin_kris$ cd src/
git clone https://github.com/ros-interactive-manipulation/household_objects_database_msgs.git
git clone https://github.com/ros-interactive-manipulation/sql_database.git
git clone https://github.com/ros-interactive-manipulation/household_objects_database.git

   
   
  • 1
  • 2
  • 3
  • 4

Note:
修改 sql_database 包中CMakeLists.txt 文件,如下:
include_directories(include ${catkin_INCLUDE_DIRS} database_interface/include)

  1. 创建 参数文件(my_server.yaml), 文件路径为 household_objects_database/config/my_server.yaml,参数文件内容如下:
household_objects_database:
  database_host: 127.0.0.1
  database_port: 5432
  database_user: willow
  database_pass: willow
  database_name: household_objects-0.2

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  1. 创建 launch 文件 mylocal_server.launch, 文件路径为 household_objects_database/launch/mylocal_server.launch
<launch>
 <!-- load database connection parameters -->
 <rosparam command="load" 
           file="$(find household_objects_database)/config/my_server.yaml"/>
 <!-- start the database wrapper node -->
 <node pkg="household_objects_database" name="objects_database_node" 
       type="objects_database_node" respawn="true" output="screen"/>
</launch>

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  1. 编译工作空间
catkin_kris$ catkin_make
catkin_kris$ source devel/setup.bash

   
   
  • 1
  • 2
  1. 运行ros master
  2. 新开一个终端
$ roscore

   
   
  • 1
  1. 新开终端运行
$ roslaunch household_objects_database mylocal_server.launch

   
   
  • 1
  1. 新开终端运行
$ rosservice list
$ rosservice call /objects_database_node/get_model_list REDUCED_MODEL_SET 

   
   
  • 1
  • 2

输出:
return_code:
code: -1
model_ids: [18665, 18685, 18691, 18693, 18699, 18744, 18746, 18765, 18766, 18783, 18791, 18798,
18799, 18800, 18802, 18807, 18808]

  1. 创建 自己的模型集合
  • Open up pgadmin3, then log into your PostgreSQL server
  • Select your database and select Tools, Query tool (or press Ctrl+E)
    输入 以下代码 ,单击 工具栏 中的 Play 按钮 或 按 F5 快捷键
INSERT INTO model_set (original_model_id, model_set_name)
SELECT original_model_id, 'MY_MODEL_SET'
FROM original_model
WHERE original_model_id IN (
SELECT original_model_id FROM scaled_model
WHERE scaled_model_id IN (18671,18659,18638)
)

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

终端运行:

rosservice call /objects_database_node/get_model_list MY_MODEL_SET 

   
   
  • 1

输出:
return_code:
code: -1
model_ids: [18638, 18659, 18671]

从数据库中删除自己的model set , 可运行下列query语句:

DELETE FROM model_set
WHERE model_set_name='MY_MODEL_SET'

   
   
  • 1
  • 2
                                </div>
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-e44c3c0e64.css" rel="stylesheet">
                </div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值