I'm currently working on a project on quadcopter with obstacles avoidance capability, I am using a KK2.0 flight controller, Arduino Uno board and sharp infrared sensor (Kingduino GP2D12).
The IR sensor measures the distance between the sensor itself and the object and sends it to the arduino in the form of analog signal (value range: 0 to 1023). We should make a setpoint say 30cm from the IR sensor so if the setpoint reaches below 30cm the PID algorithm in the arduino will start its work by sending out the correction value to the stabilization board (kk2.0).
I came across a similar project done by cyril.anthony777 online but have some queries on the codes he shared. The following is the code,
int setpoint=60,Kp=3; // Kp is (present error) Tuning Parameter
left = analogRead(A0);
right = analogRead(A1);
front = analogRead(A2);
back = analogRead(A3);
Question1: How is the Setpoint value of 60 and its Min of 20 and Max of 150 obtained?
Question2: Is Kp refering to the present error (Tuning Parameter) and how is it derived?
Question3: What is this op1=e1*Kp? why must the e1 value (difference between setpoint and actual distance) by multiplied by Kp?
Question4: And lastly opx=1500-op1+op2, what is is about? I understand that the aileron (Roll) control is affected by the left and right pairs of motors and elevator (pitch) control is affected by the front and rear pairs of motors. Is the 1500 refering to the 1500us which is the center or neutral value for roll pitch and yaw?
It would be great if any guru out there can help me with this, thanks in advance! Peace