Stability, optimization and motion planning for control-affine systems