While SpaceX has not published anything specific on the flight control logic, the underlying process is by no means magic.
The basic control mode for a system is generate a control signal that moves towards the set point. The most basic being the classic thermostat that turns off when too hot and on when too cold and oscillates either side. More precise control can be done with proportional control, where if far from setpoint you drive harder towards it. This has a tendency to drive hard and overshoot, so you also factor in rate of approach to set point and damp the drive rate down as it approaches.
This system is referred to as proportional-integeral-derivative (PID) control and are a well established technology. Where the magic happens is tuning the three values to achieve fast control without overshoot and/or oscillation. This is complicated for spacecraft descent in that the control effects change with speed and air density, so ideally you do a combination of modelling and testing to find ideal values for all possible speed/altitude/mass combinations.
This answers the question as written, but possibly not the question as intended in terms of how to actually determine the intended flight path. The SpaceX method does not appear to have been made public, but published work by others seem to use a combination of pre computed path switching to a live terminal descent mode that predicts impact point without control inputs and iterates towards a sequence of control inputs that will achieve touchdown. The involved maths is complex for a human but solvable even with Apollo era hardware, though faster processing allows more optimal solutions to be found without impacting during number crunching or by exceeding stability limits. In particular Apollo Lunar descent had a rather simpler inverted pendulum to deal with than SpaceX.
Powered descent has even been achieved by a hobbist on a solid rocket motor which while working only at a single atmospheric pressure and without aerodynamic surfaces is of interest in showing the mechanical and PID tuning process involved.