I'm currently working on a project to generate a stable altitude and automatic control for a quadcopter I'm using arduino as the flight controller Ultrasonic sensor HC-SR04 MPU-6050 However my project expected outcome is to set the quadcopter to fly( altitude hold) to 50 Cm above the ground. My problem is I don't know which one of the sensors I have to use for PID set point can anyone help me with the code or the functions the I need to use ?
Typically quadrotor have a nested control approach. That means one P(I)D loop controls the orientation (using IMU readings) and another one the position (using position sensors, e.g. ultrasound for altitude).
The attitude loop is executed faster than the position one and is assumed to ensure that the desired orientation is tracked reasonably well.
The position loop is around the orientation one and provides desired orientation to be tracked based on the desired position.
This is necessary as lateral displacement of the quadrotor can only be achieved by changing the orientation so that total thrust is pointing in the direction of motion.
In your case, you might escape that as you describe only altitude (z-position) control, so you want to control the 3 orientation angle and and the altitude, which mean you can directly do as the quadrotor as 4 inputs. The only drawback is that you might see you quadrotor drifting around if you do not cits position in the horizontal plan.