ROS Getting Started Tutorial

This tutorial explains how to connect a USB camera and Pixhawk and ensure that the basic installation is operational.

Make sure that you followed the installation instructions: ROS Onboard Setup (Odroid U3)

Next step after getting a stable ROS and Ubuntu setup on the Odroid would be to get a PX4-Odroid bridge up : companion_link

For now, you can simply connect via USB to test the Odroid-PX4 connection : serial_connection

We will be using mavlink for passing data between the Odroid and the FC, so we need to manually start the mavlink stream from NSH like this:

nsh> sh /etc/init.d/rc.usb 

Mavros, the ROS-PX4 mavlink bridge also has a feature to start mavlink automatically, which you can specify in the launchfile. If you are using the TELEM2 port as recommended, you don't need to do this. You won't gett NuttShell, but directly a mavlink stream (you'll see gibberish in terminal)

To ensure safety in flight, the USB interface on Pixhawk is disabled if no computer connected via USB for 30 seconds.

If you've done all this, you should be able to simply copy the below contents into a launchfile called “test_rig.launch”, put it in your home directory and launch it. This will test you connection to the Pixhawk and USB camera.

<launch>
 
	<arg name="fcu_url" default="serial:///dev/ttyACM0:921600" />
	<arg name="gcs_url" default="udp://:14556@192.168.150.2:14550" />
	<arg name="tgt_system" default="1" />
	<arg name="tgt_component" default="50" />
 
	<node name="mavros" pkg="mavros" type="mavros_node" output="screen">
		<param name="fcu_url" value="$(arg fcu_url)" />
		<param name="gcs_url" value="$(arg gcs_url)" />
		<param name="target_system_id" value="$(arg tgt_system)" />
		<param name="target_component_id" value="$(arg tgt_component)" />
 
		<rosparam command="load" file="$(find mavros)/launch/px4_blacklist.yaml" />
 
		<!-- enable heartbeat send and reduce timeout -->
		<param name="conn_heartbeat" value="5.0" />
		<param name="conn_timeout" value="5.0" />
                <!-- automatically start mavlink on USB -->
		<param name="startup_px4_usb_quirk" value="true" />
 
	</node>
 
	<node name="camera" pkg="usb_cam" type="usb_cam_node">
		<param name="video_device" value="/dev/video0" />
		<param name="image_width" value="800" />
		<param name="image_height" value="600" />
		<param name="pixel_format" value="mjpeg" />
		<param name="framerate" value="30" />
		<param name="camera_frame_id" value="webcam" />
	</node>
 
	<node name="viewer" pkg="image_view" type="image_view">
		<remap from="image" to="/camera/image_raw" />
    </node>
 
 
</launch>

Run the launchfile:

roslaunch test_rig.launch

You should see Mavros connecting to the Pixhawk. A new image_view window should open, displaying the image from the camera.

Move this to a separate page

Test the framerate :

With the usb_cam node running, open a new terminal and execute:

rostopic hz --window=1000 /camera/image_raw

You should see output like the following:

subscribed to [/camera/image_raw]
average rate: 30.026
	min: 0.027s max: 0.037s std dev: 0.00237s window: 28
average rate: 30.016
	min: 0.027s max: 0.041s std dev: 0.00250s window: 58
average rate: 30.057
	min: 0.027s max: 0.041s std dev: 0.00243s window: 88
average rate: 30.045
	min: 0.026s max: 0.042s std dev: 0.00263s window: 118

The output above indicates that the video is being published at approximately 30Hz.

The framerate that you request may not match with the framerate that the camera is actually providing, as you can test above.

Actual framerate depends on the shutter speed, which depends on the ambient light available and various camera parameters like gain(ISO). If you are getting low framerates of ~15 fps try in stronger lighting or outdoors. Lighting is crucial to preventing motion blur when we move to more complicated setups. You can also disable auto-exposure on your camera and fix the shutter speed and brightness/gain params(recommended) to force 30 fps. The picture will become darker. depending on ambient light available. Optimally adjust shutter to get the required 30fps so that the image is not over-exposed in your target flight environment. Even for indoor testing, set the shutter speed as high as you can and use strong lighting to prevent blurring. Setting a fixed gain (ISO) and shutter also helps prevent flickering due to automatic exposure compensation by the camera, which is important for feature trackers described later.

For v4l2 compatible webcams, you can use the following terminal commands to set camera parameterss, after installing the v4l2-utils package using apt-get. For other cameras please refer to your camera driver documentation on how to do this :

To list all available parameters and ranges :

v4l2-ctl --list-ctrls

To set parameters (disable auto exposure, fix shutter speed):

v4l2-ctl -c exposure_auto_priority=0
v4l2-ctl -c exposure_auto=1
v4l2-ctl -c exposure_absolute=190 #change this as required

Note that you will have to do this after every reboot. The settings don't 'stick'. Later you can script this in rc.local to automatically do this on boot.

Translations of this page:


Quick Links

QR Code: URL of current page