Creating a QuadCopter Controller and Code. roadblock, Need Help.

MartinL:
My apologies for starting from the pilot input, but it's better than working on the motors only to find that the issue actually occurs somewhere further upstream.

its all good, i appreciate the help.

MartinL:
Hi vortix2950,

Starting with the Pilot Input:

You mention that your using an Arduino Uno for your controller, I presume this is the transmitter?

What control signals is your Nano flight controller receiving for throttle, roll, pitch and yaw channels?

How are you mapping these inputs into values that can be used as your PID control loops' "setpoints".

For example using an RC transmitter/receiver you'll get roughly a 1ms to 2ms pulse on each of the receiver's channels. The flight controller needs to determine the pulse width of each of these channels without the program blocking (waiting) for each pulse to occur.

Here's how I mapped the airelon (roll) pulse to ±180°/s with using the Arduino "map" macro:

rxRoll = map(airelonPulsewidth, 1076, 1872, -180, 180);

The 1076 and 1872 are receivers microsecond minimum and maximum values, as I mentioned the received pulse widths are only roughly 1000us to 2000us.

Once this is established it's possible to move on the the Gyroscope Output.

the controller only sends potentiometer reading from 0 to 180. once that is received, i multiply it by a thousand For the throttle.
The Yaw,pitch, and roll are set to 0.0 automatically for now. No controller involvement for that. The reason for that is because i wanted to wait for it to be able to take off the ground first before trying to move it front an back and so on.I think that taking off vertically takes priority since i assume the rest off the controls wont work even if implemented correctly.

here is the Code lines:

 MotorPower=RecievedData; // this is the quad getting the Data from the controller.

  accelgyro.getRotation(&gx, &gy, &gz);
    gx=((gx/131)* 180/M_PI)*1000000;
    gy=((gy/131)* 180/M_PI)*1000000;
    gz=((gz/131)* 180/M_PI)*1000000;

if(gx<minInput){gx=minInput*1000000;}
if(gy<minInput){gy=minInput*1000000;}
if(gz<minInput){gz=minInput*1000000;}


if(gx>maxInput){gx=maxInput*1000000;}
if(gy>maxInput){gy=maxInput*1000000;}
if(gz>maxInput){gz=maxInput*1000000;}


   PidTime=micros();
    TimeError=(PidTime-LastPidTime);

    
    //
    Desired_Roll=0.0;
    Desired_Pitch=0.0;
    Desired_Yaw=0.0;

//Do same PID loop// Look Code in comment Above

//Here we use the data from controller which is pot reading 0-180 then multiply by 1000 and add adjustment to that.
    Motor_1_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor)+Input_Roll+Input_Pitch+Input_Yaw;
    Motor_3_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor)-Input_Roll+Input_Pitch-Input_Yaw;
    Motor_2_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor)-Input_Roll-Input_Pitch+Input_Yaw;
    Motor_4_Speed=((MotorPower*MotorPower_Scaler)+MinMicroSeconds_Motor) +Input_Roll-Input_Pitch-Input_Yaw;




    Motor_1_Speed=map(Motor_1_Speed,1000000,2000000,0,255);
    Motor_2_Speed=map(Motor_2_Speed,1000000,2000000,0,255);
    Motor_3_Speed=map(Motor_3_Speed,1000000,2000000,0,255);
    Motor_4_Speed=map(Motor_4_Speed,1000000,2000000,0,255);


    analogWrite(Motor1Analog_1,Motor_1_Speed);
    analogWrite(Motor1Analog_2,Motor_2_Speed);
    analogWrite(Motor1Analog_3,Motor_3_Speed);
    analogWrite(Motor1Analog_4,Motor_4_Speed);