We give new instances where Chabauty-Kim sets can be proved to be finite, by developing a notion of "generalised height functions" on Selmer varieties. We also explain how to compute these generalised heights in terms of iterated integrals and give the first explicit nonabelian Chabauty result for a curve X/Q whose Jacobian has Mordell-Weil rank larger than its genus.