A method, performed by a controller unit , for controlling motion of a watercraft with a hydrofoil , wherein the method comprises: obtaining (A010) information indicating shape of water surface in front of the hydrofoil , predicting (A040) wave acceleration of the watercraft using a neural network, wherein the neural network is trained to output the wave acceleration using training data for the neural network, wherein the training data is derived from information indicating shape of water surface in front of the hydrofoil , speed of the watercraft , angle of attack of the hydrofoil , "AoA", and measured acceleration, determining (A050) a target route and corresponding total acceleration of the watercraft under a set of constraints, wherein the total acceleration is minimized when the watercraft travels according to the target route, wherein the set of constraints includes: a first constraint that the hydrofoil stays within an interval relative to the water surface, and a second constraint relating to magnitude of acceleration of the watercraft derived from maximum AoA and the predicted wave acceleration, and calculating (A060) an AoA for the target route based on a difference between the total acceleration as given by the target route and the predicted wave acceleration, and sending (A070) a signal for adjusting the hydrofoil according to the AoA, thereby controlling the motion of the watercraft . obtaining (A010) information indicating shape of water surface in front of the hydrofoil , predicting (A040) wave acceleration of the watercraft using a neural network, wherein the neural network is trained to output the wave acceleration using training data for the neural network, wherein the training data is derived from information indicating shape of water surface in front of the hydrofoil , speed of the watercraft , angle of attack of the hydrofoil , "AoA", and measured acceleration, determining (A050) a target route and corresponding total acceleration of the watercraft under a set of constraints, wherein the total acceleration is minimized when the watercraft travels according to the target route, wherein the set of constraints includes: a first constraint that the hydrofoil stays within an interval relative to the water surface, and a second constraint relating to magnitude of acceleration of the watercraft derived from maximum AoA and the predicted wave acceleration, and calculating (A060) an AoA for the target route based on a difference between the total acceleration as given by the target route and the predicted wave acceleration, and sending (A070) a signal for adjusting the hydrofoil according to the AoA, thereby controlling the motion of the watercraft . a first constraint that the hydrofoil stays within an interval relative to the water surface, and a second constraint relating to magnitude of acceleration of the watercraft derived from maximum AoA and the predicted wave acceleration, and calculating (A060) an AoA for the target route based on a difference between the total acceleration as given by the target route and the predicted wave acceleration, and sending (A070) a signal for adjusting the hydrofoil according to the AoA, thereby controlling the motion of the watercraft . <EOS>