To drive on its own, the rover has to see its surroundings. In post #1 I was still thinking of a 2D lidar; later I experimented with a simple USB camera (ORB-SLAM2) and an old Kinect. I ended up with an Intel RealSense D435i. This post covers mounting, drivers on the Jetson Nano and calibration. The calibration turned out to matter more than I expected.
Why the D435i?
The D435i is a stereo depth camera with a colour camera and a built-in inertial sensor (acceleration and turn rate). For the rover that brings three things at once:
- Depth image: the distance for every pixel, so the rover detects obstacles and builds a 3D map.
- Colour image: for watching along over Wi-Fi and for recognising places while mapping.
- Gyro: measures the rover’s turn rate much more accurately than the wheels. More on that below.
Unlike a 2D lidar the camera also sees table tops, chair legs and steps, and unlike the Kinect it works outdoors too.
Mounting
My camera sits on a plate on the mast, centred above the rover and looking forward. A few things I’d pay attention to right away next time:
- Height: my lens centre is just under 47 cm above the floor. With a ±21 degree vertical field of view the camera only sees the floor from about 1.2 m in front of the rover. Anything closer is known only from the map. If you want to detect flat obstacles right in front of the rover, mount the camera lower or tilt it down slightly.
- Measure precisely: the camera’s position relative to the rover centre goes into the 3D model (URDF). Every error there shifts the whole map. On my rover the camera actually sat 5.7 cm further left than in the model. Result: every obstacle was 5.7 cm off, and the rover passed just beside the centre of the door. So measure with a tape: lateral offset, height of the lens centre above the floor, distance to the rover centre.
- USB 3: the camera needs a USB 3 port and a decent USB 3 cable. Over USB 2 only reduced resolutions work.
[Image: camera mount on the mast]
Drivers on the Jetson Nano
This was the most laborious part. Two building blocks are needed:
- librealsense, Intel’s library. On the Jetson it’s best built from source with the so-called RSUSB backend, which needs no kernel patches. The ready-made scripts from JetsonHacks do the work: https://github.com/JetsonHacks/installRealSenseSDK (script
buildLibrealsense.sh). I run librealsense 2.56.5. The build takes a good hour on the Nano. - realsense-ros, the ROS driver. For ROS 1 it only exists in the
ros1-legacybranch, last version 2.3.2: https://github.com/IntelRealSense/realsense-ros/tree/ros1-legacy. Clone therealsense2_camerafolder into the workspace and build withcatkin build. It also needsddynamic_reconfigure.
The OpenCV trap
I lost a lot of time here. JetPack ships OpenCV 4.1, but the ROS Melodic packages (e.g. cv_bridge and image compression) are built against OpenCV 3.2. If you build the RealSense driver against OpenCV 4, two OpenCV versions end up in the same process. That works until someone subscribes to the compressed camera image, exactly what you need for Wi-Fi.
My solution was to use only OpenCV 3.2 on the Jetson:
sudo apt install libopencv-dev=3.2.0+dfsg-4ubuntu0.1
apt removes NVIDIA’s OpenCV 4.1 in the process. Then rebuild the RealSense driver. You can check with ldd on the built library: only libopencv_*.so.3.2 may appear. NVIDIA’s VisionWorks and VPI samples go away with it; the rover doesn’t need them.
Launch parameters
The Nano is no powerhouse. I start the camera with reduced settings:
<include file="$(find realsense2_camera)/launch/rs_camera.launch">
<arg name="align_depth" value="true"/> <!-- depth matched to colour image -->
<arg name="enable_gyro" value="true"/>
<arg name="enable_accel" value="true"/>
<arg name="unite_imu_method" value="copy"/>
<arg name="depth_width" value="640"/> <arg name="depth_height" value="480"/>
<arg name="color_width" value="640"/> <arg name="color_height" value="480"/>
<arg name="depth_fps" value="15"/> <arg name="color_fps" value="15"/>
<arg name="enable_pointcloud" value="false"/> <!-- costs a lot of CPU -->
<arg name="enable_infra1" value="false"/> <arg name="enable_infra2" value="false"/>
<arg name="tf_publish_rate" value="0.0"/> <!-- internal TFs static -->
</include>
I don’t compute the point cloud in the camera driver but later, thinned out, only for obstacle detection.
Images over Wi-Fi
The raw colour image at 15 frames per second is almost 15 MB/s, too much for Wi-Fi. Compressed as JPEG it is only 0.8 MB/s. The depth image, on the other hand, can hardly be transmitted sensibly: the Nano manages lossless PNG compression at only 0.8 frames per second. That’s why the Jetson processes depth itself (obstacle detection), and only throttled image pairs at 2 Hz go to the map on the server. More in post #7.
Calibration
1. Depth scale (tare)
My camera measured every distance 4 % too short. That sounds small, but it makes the floor appear to rise towards the front and suddenly count as an obstacle further away. I noticed it with a printed chessboard: the distance to the board can be computed very accurately from the colour image (to 1 mm of my tape measure), and the depth camera was off.
Intel offers tare calibration for this: put a flat target at a known distance square in front of the camera, enter the distance, and the camera corrects itself. You can do it with Intel’s Depth Quality Tool or, as on my Jetson, with a small program using the librealsense API. Back up the old calibration first! Afterwards the error was below 1 %.
2. Mounting angle
Small camera tilts matter too: 3 degrees sideways, and the floor counts as an obstacle on one side. I determine the tilt from the depth image: the camera looks at free, flat floor, a plane is fitted through the floor points, and its position gives the camera’s height and tilt. I enter the values into the URDF (joint camera_joint). Afterwards the measured lens height was only 2 mm off the tape measure.
3. Gyro
On my rover the turn rate comes only from the camera’s gyro; wheel odometry only contributes the forward speed. The wheels slip when steering and turning, the gyro doesn’t. Both are fused in a Kalman filter (robot_localization).
Two pitfalls:
- The gyro has a small zero offset (about 3.4 degrees per minute on mine). A small node in my version estimates it while the rover stands still and subtracts it.
robot_localizationexpects the selection of measurements (imu0_config) in the sensor’s coordinate frame. For the camera, z points forward and y points down there, so rotation about the vertical axis is rotation about y, not z. With the wrong selection the filter simply ignores the gyro.
What’s next?
The rover now sees its surroundings and knows fairly precisely how it moves. In the next post this becomes a map, and the rover drives on its own to a goal clicked in the browser.
[Image: colour and depth image side by side]