Let the robot measure the torque/force at one or more joints of each leg.
Perhaps measure torque directly using a discrete strain gage or other force/torque sensor.
Or perhaps you can get an adequate approximation by using "sensorless" measurements of the back-EMF of that leg's motor, or the amount of power going into that leg's motor.
Say the robot is using some gait that is efficient for tarmac: the robot puts the foot down in front until it touches the tarmac, then it stays at that vertical position and pushes the foot straight straight back, then lifts the leg up a little and pulls it forward, then puts the foot back down and repeats.
If you really are moving over tarmac, you expect the robot to measure a high torque/force when it is pushing the leg back, and close to zero when it is pulling the leg through the air forwards.
If the torque in one leg feels low when the robot pushes it back, then perhaps that leg (not necessarily any other leg) is slipping across the surface of some sand.
So the robot should push that leg down a little deeper into the sand, and perhaps move the leg back a little faster, until that leg gives the robot the forward thrust you want.
If the torque in one leg feels high when the robot pulls it forward, perhaps it is rubbing against grass.
Or perhaps the other legs have dug in deeply into sand, and that leg is brushing the top layer of sand.
So the robot should lift that leg up a little higher to avoid that obstacle.
(And perhaps lift all the legs up a little higher on the return stroke for the next few steps, so other legs can avoid that obstacle or similar nearby obstacles).
I'm assuming your goal is to get the robot to adaptively change its gait, because different gaits are more efficient on different substrates. If your real goal is to get the robot to stay on a tarmac track, rather than wandering off over grass and sand, you'll need some other approach.