1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Raspberry Pi3 でカメラ映像をgscam経由でros publishする

Posted at

背景

最終的にはROSのgscamノード経由でカメラ映像をpublishしたい。
raspicam_nodeを試したが、数十秒でpublishが止まってしまう(mmalのcallbackが止まっちゃう)。
あまり深堀りしたくないので、gstreamerに手を出してみる。
https://github.com/UbiquityRobotics/raspicam_node/issues/65
他にも報告があがっているので、そのうち解決されるとは思う。。

試してみる

環境

Raspberry Pi3 model B
Raspbian Stretch (2018-11-13)
事前にraspi-configでカメラを有効にしておくこと

カメラモジュールのv4l2有効

/etc/modulesに以下を追記

bcm2835-v4l2

gstreamerの動作確認

インストール

sudo apt-get install gstreamer1.0-tools gstreamer1.0-plugins-good

/dev/video*へのアクセス権の設定

sudo usermod -a -G video $USER

試してみる。
コマンドを実行して、いいところでCtrl-Cで止める。

pi@raspberrypi:~ $ gst-launch-1.0 -e v4l2src device=/dev/video0  ! jpegenc ! avimux ! filesink location=test_.avi
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
^Chandling interrupt.
Interrupt: Stopping pipeline ...
EOS on shutdown enabled -- Forcing EOS on the pipeline
Waiting for EOS...
Got EOS from element "pipeline0".
EOS received - stopping pipeline...
Execution ended after 0:00:04.880463524
Setting pipeline to PAUSED ...
Setting pipeline to READY ...
Setting pipeline to NULL ...
Freeing pipeline ...

SCPなんかでPCに転送して、再生してみる。
ちゃんと撮れていればOK

gscamで試す

ビルド

githubからcatkin_ws/srcにコードをcloneしてビルドする。

$ cd catkin_ws/src
$ git clone https://github.com/ros-drivers/gscam
$ cd catkin_ws
$ sudo rosdep install --from-paths src --rosdistro=melodic --ignore-src -y
$ catkin build

launchファイル

v4l_rpi.launch
<launch>
  <!-- This launchfile should bring up a node that broadcasts a ros image
       transport on /webcam/image_raw -->

  <arg name="DEVICE" default="/dev/video0"/>
  <!-- The GStreamer framerate needs to be an integral fraction -->
  <arg name="FPS" default="10/1"/>

  <node ns="v4l" name="gscam_driver_v4l" pkg="gscam" type="gscam" output="screen">
    <param name="camera_name" value="default"/>
    <param name="camera_info_url" value="package://gscam/examples/uncalibrated_parameters.ini"/>
    <param name="gscam_config" value="v4l2src device=$(arg DEVICE) ! video/x-raw,width=640,height=480,framerate=10/1 ! videoconvert"/>
    <param name="frame_id" value="/v4l_frame"/>
    <param name="sync_sink" value="true"/>
  </node>

</launch>

ノードを立ち上げる

$ roslaunch gscam v4l_rpi.launch

ROSの入ったPCから確認

$ rostopic list

番外編:Camera Module v2壊れてる?

v1は接続できたが、v2を接続するとエラーが出る

pi@raspberrypi:~ $ raspistill -o image.jpg
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
mmal: camera component couldn't be enabled
mmal: main: Failed to create camera component
mmal: Failed to run camera app. Please check for firmware updates

アップデートしてみる。

pi@raspberrypi:~ $ sudo rpi-update
pi@raspberrypi:~ $ sudo reboot

が、ダメ。
試しに他のRaspberry Pi3に接続してみたが駄目だった。

ちなみに私が買ったv2カメラはこれ
https://www.amazon.co.jp/gp/product/B01ER2SKFS/ref=ppx_yo_dt_b_asin_title_o00__o00_s00?ie=UTF8&psc=1
壊れていたのか、壊したのかは謎です。。

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?