ROS Webcam demo on Macbook running Ubuntu

  1. Instructions to install Ubuntu on an external SSD (takes about an hour).
  2. Run this shell script to (takes about 10-15 min):
    • Install ROS (and a few other things)
    • Set up your Macbook’s built in webcam (more detail)
  3. Demo rostopic pub / echo:
    $ roscore # starts roscore
    $ rostopic pub test std_msgs/String 'this is a test' # publishes a message to a topic
    $ rostopic list # lists all active topics
    $ rostopic echo /test # live feed of data on topic
  4. Demo multiple machines: note both machines must have full connectivity (ssh)
    • On master:
      $ ifconfig # take note of your master’s ip address
      $ export ROS_IP=master.ip.address # can put in ~/.bashrc to make persistent
      $ echo $ROS_IP # check to see what that environmental variable is set to
      $ roscore # start roscore
    • On client:
      $ ifconfig # take note of the client’s ip address
      $ export ROS_IP=client.ip.address
      $ export ROS_MASTER_URI=http://master.ip.address:11311
    • Accessing a remote machine:
      $ ssh username@ip.address # must have openssh-server installed on remote machine
  5. Follow these instructions to set up a catkin_workspace
  6. The catkin instructions above do not mention to do this, but for most simple purposes, I suggest editing your .bashrc file:
    • The .bashrc file is a shell script that is run every time you open a new terminal window. Use a text editor (like gedit, nano, vim) to edit the ~/.bashrc file (gedit ~/.bashrc).
    • Add this line to the bottom (replace USERNAME):
      source /home/USERNAME/catkin_ws/devel/setup.bash
    • Reload your .bashrc by opening a new terminal window, or typing
      $ . ~/.bashrc
  7. Get ROS access to the webcam with usb_cam:
    • Check that camera is working
      $ guvcviewer
    • Install usb_cam
      $ cd ~/catkin_ws/src
      $ git clone https://github.com/ros-drivers/usb_cam.git
      $ cd ~/catkin
      $ catkin_make
    • Run usb_cam:
      $ cd ~/catkin_ws/src/usb_cam/launch
      $ roslaunch usb_cam-test.launch
    • Explore ROS environment:
      $ rosnode list
      $ rqt_graph
      $ rostopic list
      $ rostopic echo imagetopic
      $ roshz imagetopic
  8. Live image processing
    • Download optic flow example
      $ cd ~/catkin_ws/src
      $ git clone https://github.com/florisvb/optic_flow_example
      $ cd ~/catkin
      $ catkin_make
    • Explore directory structure (more detail)
    • Explore mono conversion node
    • Run mono conversion node
      $ rosrun optic_flow_example color_to_mono.py
      $ rostopic list
      $ rosrun image_view image_view image:=/imagetopic
    • Explore optic flow node
    • Run optic flow node
    • Edit optic flow node to also publish a single average value
  9. Remotely control a motor with live image data
  10. Real-time multi-target blob tracking
  11. Rosbag record, rosbag play, load data as hdf5
    • $ python ./bag2hdf5.py ~/2018-05-01-16-43-29.bag --out=~/2018-05-01-16-43-29.hdf5 --topic=/optic_flow_mean_vx
    • Analyze example
  12. Highlight modularity

Accessing Mac webcam in ROS (running Ubuntu on the Mac)

Here I show how to get access to the built in webcam on a MacBook in ROS (Robot Operating System).

This post assumes you have followed these two previous posts:
1. Install Ubuntu on an external USB drive so that you can run it from your MacBook
2. Installing ROS

Update

In the terminal, run the following two commands:

$ sudo apt-get update
$ sudo apt-get upgrade

Give Ubuntu access to your Mac’s webcam

From the terminal, run these commands:

$ cd /etc/local/src
$ git clone https://github.com/patjak/bcwc_pcie.git
$ cd bcwc_pcie/firmware
$ sudo make
$ sudo make install
$ cd ..
$ sudo make
$ sudo install
$ sudo depmod
$ sudo modprobe -r bdc_pci
$ sudo modprobe facetimehd

These instructions come from medium and askubuntu. Note: I received an error on the second install command, but it still works fine.

Test that the camera is working

Install guvcview:

$ sudo apt-get install guvcview

Then run it (by typing gucview into the terminal). If all goes well, a live view feed will pop up!

Install the usb_cam ROS driver:

To get access we will use the usb_cam driver. These steps assume that you have already built a catkin workspace, called catkin_ws.

$ cd ~/catkin_ws/src
$ git clone https://github.com/ros-drivers/usb_cam.git
$ cd ~/catkin
$ catkin_make

Launch the camera driver / viewer

$ cd ~/catkin_ws/src/usb_cam/launch
$ roslaunch usb_cam-test.launch

If all is good, a live video feed will now pop up. Note that the launch file spins up two nodes: usb_cam and image_view.

Explore the ROS topics

Type “rostopic list” into the terminal window to see a list of the ros topics that are available to you in the ROS ecosystem.

Install ROS on Ubuntu (on an external drive on your MacBook)

This post picks up from: how to install Ubuntu on an external USB drive so that you can run it from your MacBook.

  1. Follow these instructions to install ROS Kinetic on Ubuntu.
  2. Follow these instructions to set up a catkin_workspace
  3. The catkin instructions above do not mention to do this, but for most simple purposes, I suggest editing your .bashrc file:
    • The .bashrc file is a shell script that is run every time you open a new terminal window. Use a text editor (like gedit, nano, vim) to edit the ~/.bashrc file (gedit ~/.bashrc).
    • Add this line to the bottom (replace USERNAME): source /home/USERNAME/catkin_ws/devel/setup.bash
    • Reload your .bashrc by opening a new terminal window, or typing “. ~/.bashrc”

Basler GigE cameras, aravis, ROS

These are some basic instructions for setting up the Basler Ace GigE cameras (A640) to work with ROS Kinetic on Ubuntu 16.04. We use the driver Aravis. Aravis changed the API at some points, and the available ROS nodes have not been well maintained. Thus, we will use older code sets to get things working.

1. Install some necessary packages:
sudo apt-get install intltool gobject-introspection gtk-doc-tools

2. Download an older version of aravis (0.3.7) here:
ftp://ftp.acc.umu.se/pub/GNOME/sources/aravis/0.3

3. From inside the aravis_0.3.7 directory, run the following commands:
./configure
make
sudo make install

4. Now you will need to set up your ethernet interface.
4a. Install a dhcp server: sudo apt-get install isc-dhcp-server
4b. Check your interfaces by running ifconfig. Note the interfaces (e.g. eth1, enp3s0f1, etc.) that correspond to the port where you intend to plug in your camera.
4c. Edit the following files, using the linked github files as templates. The …93… in the ip addresses can be whatever you like, so long as it does not collide with other ip’s on the local network.
i. /etc/network/interfaces
ii. /etc/default/isc-dhcp-server
iii. /etc/dhcp/dhcpd.conf  (note, all punctation including ‘;’ is important!)
4d. Restart the computer. If you have trouble connecting to the internet, try removing any mention of the interface you use to connect to the internet from the /etc/network/interfaces file.

5. Download the ROS node (git clone into your catkin workspace):
https://github.com/florisvb/camera_aravis
Note: this is forked from a no longer existing github repo, which was forked from ssafarik. I keep a copy just so I can make sure I know where to find a compatible version.

6. In ROS kinetic and newer, the driver_base stack is no longer supported, but it is necessary for the camera_aravis node. You can resolve this by manually installing the following (git clone into your catkin workspace):
https://github.com/florisvb/driver_common
Note: this is forked from ros-drivers, just so I can make sure I know where to find a compatible version.

7. From inside the catkin workspace base directory run:
catkin_make

8. If all goes well, you can now run:
roscore
rosrun camera_aravis camnode
rosrun image_view image_view image:=/camera/image_raw

Tips for debugging

1. Check that the camera works.

On another computer (e.g. a laptop), plug the camera into your ethernet port and run pylon view app: https://www.baslerweb.com/en/support/downloads/software-downloads/

2. Double check that your dhcp config is correct.

sudo systemctl status isc-dhcp-server

Will tell you if there is an error in the dhcpd.config.

More tips: https://killtacknine.com/building-an-ubuntu-16-04-router-part-2-dhcp/

3. If the encoding is strange.

Launch the pylon viewer app and switch to mono 8: https://www.baslerweb.com/en/support/downloads/software-downloads/

Replaying rosbag movies

Suppose we have a rosbag video: ‘/home/caveman/Downloads/20140108134157.bag’

Play the video:

rosbag play ‘/home/caveman/Downloads/20140108134157.bag’

suppose the image topic is: /camera/image_rect/compressed

To republish uncompressed video:

rosrun image_transport republish compressed in:=/camera/image_rect raw out:=/camera/image_rect

Now view the image with:

rosrun image_view image_view image:=/camera/image_rect

To extract the images:

rosrun image_view extract_images image:=/camera/image_mono

Then save to a movie:

mencoder mf://*.jpg -mf type=jpg:fps=30 -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o animation.avi