jsk-ros-pkg / jsk_robot

jsk-ros-pkg/jsk_robot
https://github.com/jsk-ros-pkg/jsk_robot
73 stars 97 forks source link

[fetch] can not use bluetooth #725

Open k-okada opened 7 years ago

k-okada commented 7 years ago
[    5.800334] init: bluetooth main process (890) killed by KILL signal
[    5.800340] init: bluetooth main process ended, respawning
[    5.808658] init: Failed to spawn bluetooth main process: unable to execute: Permission denied
[    5.817046] Bluetooth: HIDP (Human Interface Emulation) ver 1.2
[    5.817053] Bluetooth: HIDP socket layer initialized
k-okada commented 7 years ago

need to set executable bit sudo chmod u+x /usr/sbin/bluetoothd http://askubuntu.com/questions/427730/failed-to-spawn-bluetooth-main-process-unable-to-execute-permission-denied

k-okada commented 7 years ago

need to update /etc/init/bluetooth.conf

exec /usr/sbin/bluetoothd

pre-start exec chmod u+x /usr/sbin/bluetoothd # added by k-okada

post-start script
k-okada commented 7 years ago
        $ hcitool scan
        でスキャン
        $ sudo hcitool cc FC:58:FA:84:01:20
        で接続
        $ bt-device -l
        Added devices:
        Taotronics TT-SK09 (FC:58:FA:84:01:20)
        で確認
        これだけだとダメ.なにか必要.手動でつなげる

        $ pactl list
        でCard #3が出てこないとだめ.
        これで、
        $ pactl set-card-profile 3 a2dp
        $ paplay /usr/share/sounds/alsa/Front_Center.wav
        ができる.

        スピーカを切ってからリブートしないとa2dpが使えないかも
        (https://forum.kde.org/viewtopic.php?f=66&t=120982#p309785)

        http://askubuntu.com/questions/414258/successfully-connected-to-a-bluetooth-speaker-but-how-do-i-direct-sound-there
        みて、pavucontrolでUSB AudioをDisableしたら動いた気がする.

        gst-launch-1.0 filesrc  location=/usr/share/sounds/alsa/Front_Center.wav ! decodebin !  audioconvert ! alsasink
        でBluetoothスピーカから音が出るとOKっぽい
        sudo service soundplay stopして
        fetchユーザでrosrun soundplay soundplay_node.pyする必要あり

        rosユーザも使えるように→使えない
        sudo adduser ros bluetooth

とりあえず、動く方法を一つ見つけた.ちゃんと動くようにするには色々考える必要あり.

k-okada commented 7 years ago
        /etc/bluetooth/audio.confで
        [General]
        Disable=Headset # Add this
        https://sandalov.org/blog/2146/

とすると、スピーカをつなげるとa2dsになる.あとは、

        /etc/init/soundplay.conf
        で
        exec su ros -c ". /opt....
        を
        exec su fetch -c ". /opt....
        に

とする必要がある.これで、ロボットを立ち上げて、スピーカをONするとつかえるようになる.

        $ cat enable-speaker.sh
        #!/bin/bash

        if [ -e /tmp/enable-speaker.dat ]; then ## speaker is on
            if ! pactl list cards short | grep bluez; then
                echo "Bluetooth speaker is dis-connected!"
                rm -f /tmp/enable-speaker.dat
            fi
        else
            if pactl list cards short | grep bluez; then
                echo "Bluetooth speaker is connected!"
                echo "Connected" > /tmp/enable-speaker.dat
                XDG_RUNTIME_DIR=/srun/user/`id -u` paplay /usr/share/sounds/ubuntu/stereo/system-ready.ogg
                /opt/ros/indigo/setup.bash && rosrun sound_play say.py "Hello `hostname`. My IP addess is `gethostip -d $(domainname -A)`"
            fi
        fi
        として、
        crontabに
        * * * * * /home/fetch/enable-speaker.sh
        とした.

これで、スピーカをつなげるとubutnuの接続音がBlueToothスピーカからなる.