LoginSignup
1
3

More than 5 years have passed since last update.

RaspberryPi3にROSとRoomba用ROSモジュールをインストールして動かしてみる

Last updated at Posted at 2016-12-22

はじめに

Raspberry Pi 3 に Ubuntu-16.04, ROS Kinetic をインストールして、サンプルを動かしてみました。

概要

  • Ubuntu-16.04のインストール
  • OSの初期設定
  • ROS kineticのインストール
  • roomba_500_seriesのインストール
  • パッケージ作成
  • 動かしてみる

手順

Ubuntu-16.04のインストール

ダウンロード&解凍

参考:Raspberry Pi 2でUbuntu14.04を使う
参考:Mac OS X で Raspberry PiのOSイメージを焼く - @ledsun blog

下記よりUbuntu-16.04のイメージ(ubuntu-16.04-preinstalled-server-armhf+raspi3.img.xz)をダウンロード
ARM/RaspberryPi - Ubuntu Wiki

下記で解凍。

$ xz -dv ubuntu-16.04-preinstalled-server-armhf+raspi3.img.xz

SDカードの特定、焼き込み

diskutil listなどにより、SDカードを特定。今回は/dev/disk2

SDカードへ焼き込み。

$ diskutil unmountDisk /dev/disk2
$ sudo dd if=ubuntu-16.04-preinstalled-server-armhf+raspi3.img of=/dev/rdisk2 bs=1m

SSHで接続、初期設定

無線LAN設定

Roomba用RPiのIPアドレスは192.168.0.1に固定する想定。

$ sudo apt-get install -y wpasupplicant wireless-tools linunx-firmware
$ sudo vi /etc/network/interfaces.d/wlan.cfg
$ sudo vi /etc/wpa_supplicant/wpa_supplicant.conf
$ sudo vi /etc/default/networking
$ sudo ifup wlan0
/etc/network/interfaces.d/wlan.cfg
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
    address 192.168.0.1
    netmask 255.255.255.0  # 各自の環境に
    gateway 192.168.0.254  # 合わせて設定する
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
/etc/wpa_supplicant/wpa_supplicant.conf
update_config=1
network={
    proto=WPA2
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    ssid="your_ssid"
    psk=**************** # 下記参照
}
/etc/default/networking
CONFIGURTE_INTERFACES=no

参考 パスフレーズの生成は下記の通り

$ sudo sh -c "wpa_passphrase your_ssid > /etc/wpa_supplicant/wpa_supplicant.conf"
# reading passphrase from stdin
pass_phrase
network={
    ssid="your_ssid"
    #psk="pass_phrase"
    psk=****************
}

ROSのインストール

参考:RaspberryPi3のUbuntu16.04LTSにROSのkineticをインストールする | GarretCafe

仮想マシン上で手軽にROSのサンプルを動かしてみるとほぼ同じ。

時刻設定

$ sudo apt-get update
$ sudo apt-get install -y chrony ntpdate
$ sudo ntpdate ntp.nict.jp

ROSリポジトリと公開鍵を追加

$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
$ wget http://packages.ros.org/ros.key -O - | sudo apt-key add -

ROSインストール

$ sudo apt-get update
$ sudo apt-get install -y ros-kinetic-ros-base # No GUI tools
$ sudo rosdep init
$ rosdep update
$ echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
$ source ~/.bashrc
$ sudo apt-get install -y python-rosinstall

ワークスペースの設定

$ source /opt/ros/kinetic/setup.bash
$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ catkin_init_workspace
$ cd ~/catkin_ws/
$ catkin_make
$ source ~/catkin_ws/devel/setup.bash

ROS環境設定

$ vi ~/.bashrc
$ source ~/.bashrc
.bashrc
source /opt/ros/kinetic/setup.bash
source ~/catkin_ws/devel/setup.bash

export ROS_IP=192.168.0.1
export ROS_MASTER_URI=http://${ROS_IP}:11311
export DISPLAY=:0

alias cw='cd ~/catkin_ws'
alias cs='cd ~/catkin_ws/src'
alias cm='cd ~/catkin_ws && catkin_make'

roomba_500_seriesのインストール

参考:ROSでRoombaを動かす(catkin対応) - cryborgのRoboticsブログ
参考:catkin超入門(その3)・rosbuildパッケージを使う: 花岡ちゃんに花束を

リポジトリ:https://github.com/NetBUG/roomba_500_series

1回だとcatkin_makeとかcatkin_make installがfailedするけど、何度か繰り返し実行すると最終的に成功する。

$ cd ~/catkin_ws/src
$ git clone https://github.com/NetBUG/cereal_port
$ git clone https://github.com/NetBUG/roomba_500_series
$ rosdep install cerial_port
$ rosdep install roomba_500_series
$ cd ~/catkin_ws
$ catkin_make
$ catkin_make install

パッケージの作成

パッケージ作成

$ cd ~/catkin_ws/src
$ catkin_create_pkg roomba rospy std_msgs

roslaunchファイルと操作プログラムの作成

roscoreは記載しなくても勝手に起動する。

$ roscd roomba
$ mkdir launch
$ mkdir scripts
$ vi launch/roomba.launch
$ vi scripts/sample.py
roomba.launch
<launch>
    <node pkg="roomba_500_series" name="roomba560_node" type="roomba560_node" />
</launch>
sample.py
#!/usr/bin/env python

import rospy
from geometry_msgs.msg import Twist

rospy.init_node("sample")

pub = rospy.Publisher("cmd_vel", Twist, queue_size=10)

while not rospy.is_shutdown():
    vel  = Twist()

    direction = raw_input("f: forward, b: backward, l: left, r: right, s: stop,  q: quit > ")

    if "f" in direction:
        vel.linear.x = +0.1

    if "b" in direction:
        vel.linear.x = -0.1

    if "l" in direction:
        vel.angular.z = +1.0

    if "r" in direction:
        vel.angular.z = -1.0

    if "s" in direction:
        vel.linear.x = 0.0
        vel.angular.z = 0.0

    if "q" in direction:
        break

    print vel

    pub.publish(vel)

実行権限をつける

$ roscd roomba_ctl/scripts
$ chmod 755 sample.py

catkin_make

$ cd ~/catkin_ws
$ catkin_make
$ source ~/catkin_ws/devel/setup.bash

動かしてみる

roslaunch

$ roslaunch roomba roomba.launch

rostopicの直接送信

$ export ROS_IP=<自分のIPアドレス> # ifconfigで確認しておく
$ rostopic pub -1 cmd_vel geometry_msgs/Twist "[0, 0, 0]" "[0, 0, 0.1]" && rostopic pub -1 cmd_vel geometry_msgs/Twist "[0, 0, 0]" "[0, 0, 0]"

または下記(sample.pyから操作)

$ export ROS_IP=<自分のIPアドレス> # ifconfigで確認しておく
$ roscd roomba
$ ./sample.py
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3