So I have multi-rotor with a basic PID controller, that keeps its axis stable through the gyroscope. However, the multi rotor, does not keep its height or position. So I would like to use an accelerometer for keeping its rough position (auto level). I want to use both the gyro and accelerometer, but how would the accelerometer values be used, is it implemented through the PID the same ways the gyro values are (degrees per second, which is the rate I used to calculate PID)? And then adjusting the esc through that?? I am confused at that part (the basic logic for using the accelerometer values)
A gyro gives angular velocity in degrees or radians per second.
An accelerometer gives acceleration in feet or meters per second squared.
The key to keeping a reference position is getting from an acceleration to a position. This is done with by integrating the acceleration twice. The first integration gets from acceleration to velocity, then the second integration gets from velocity to distance.
So, if you were interested in implementing these integrations on a digital device, then you would use numerical integration in a manner as follows:
velocity = 0; % Set initial velocity position = 0; % Set initial position startTime = <get timer data>; <main loop> endTime = <get timer data>; sampleTime = endTime - startTime; startTime = endTime; acceleration = <get accelerometer data>; velocity = velocity + acceleration*sampleTime; position = position + velocity*sampleTime; positionProportionalError = positionReference - position; <loop>
Once you have the positionProportionalError, you can integrate/derive the other two errors for PID and use that for your PID control.