Control of motional states of trapped ions with quantum invariants