There are different solutions to work with uneven grounds while performing SLAM.
For example there is ROS package from ANYbotics for elevation mapping:
https://github.com/ANYbotics/elevatio...
The software is designed for (local)
navigation tasks with robots which are
equipped with a pose estimation (e.g.
IMU & odometry) and a distance sensor
(e.g. structured light (Kinect,
RealSense), laser range sensor, stereo
camera). The provided elevation map is
limited around the robot and reflects
the pose uncertainty that is
aggregated through the motion of the
robot (robot-centric mapping).
Another solution is to use 3D octomap to capture elevation information as well:
https://octomap.github.io/
The OctoMap library implements a 3D
occupancy grid mapping approach,
providing data structures and mapping
algorithms
You may also look at another ROS package Cartographer.
Cartographer is a system that provides
real-time simultaneous localization
and mapping (SLAM) in 2D and 3D across
multiple platforms and sensor
configurations.