Go Down

Topic: Have someone implemented a tricopter with arduino nano??? (Read 811 times) previous topic - next topic

rossi86m

I am a little bit frustrated building a bicopter with arduino nano so i am thinking of trying a tricopter to see if i can make it fly 

Does anyone have some code to share to see how to control the 3 motors.

Just in case here is my bicopter code if anyone want to see it

Thnakss!!!!
Marco

MartinL

Hi Marco,

The tricopter is in priciple the same as the bicopter, you just need to change your motor/servo mixing.

Traditionally, the tricopter has 3 motors with the rear motor on a servo operated platform to control the aircraft's yaw. The arms are configured to form a "Y" and are usually spaced 120 degrees from one another, or thereabouts.

The motor mixing for a tricopter is as follows:

Motor 1 (front left): Throttle 100%, Airelon: 87%, Elevator 50%, Rudder 0%
Motor 2 (front right): Throttle 100%, Airelon -87%, Elevator 50%, Rudder -1%
Motor 3 (rear): Thottle 100%, Airelon 0%, Elevator -100%, Rudder 0%
Servo (rear): Throttle, 0%, Airelon 0%, Elevator 0%, Rudder 100%, Offset 50%

The Arduino Nano however is not the best option to obtain high resolution PWM on all four outputs (3 motor + servo), as it only has two 16-bit timer outputs. A better option would be the Arduino Micro, as this has four, 16-bit outputs: three channels on timer 1 for the motors (at 490Hz) and one on timer 3 for the servo (at 50Hz).

On the Arduino Micro though, you have to be quite careful about pin selection if you're using an RC receiver, as unlike the Arduino Nano not all pins are capable of receiving interrupts.

rossi86m

MartinL Thanksgiving a Lot for the response.

I am dealing with the bicopter but y i am not able to make it fly stable enogh .

Can You explain me a little bit about motor mixing becuase Is something i think i am not taking into account

If You can Review my code that would be great!!!

Thanks again!
Marco

MartinL

Hi Marco,

Have you got the bicopter flying OK in rate mode, using only the gyroscope for flight stabilisation?

Have you tried flying the bicopter with only the proportional (P) part of the PID loop, (with I and D turned off)?

Most multi-rotor aircraft work on the same principle, the main difference just being how the raw throttle plus roll, pitch and yaw PID outputs are divided amongst the motors and servos. The percentage that each motor receives is calculated using simple trigonometry, for example sin(60 degrees) = .866 = 87%).


rossi86m

I am using just a mpu6050 with two pid loops per axis. But i am not able to make it take off stable enough. The back AND forward Is What i am not able to control

Did You have Time to check my code. That would help me a Lot.

I Will try using just the p of the pid

Thanks in Advance!!!!

Marco

MartinL

Hi Marco,

I had a look at your code.

The first thing I noticed is that you're using different centre points for your servos:

Code: [Select]
#define OCR1A_CENTER 1150
#define OCR1B_CENTER 1500

Is that correct?

The reason why I mentioned turning off the PID I and D terms in the rate PID control loops, is to see if these terms are causing the problem. Brett Beauregard's PID library expects a constant interval in milliseconds. I see that you've set the PID sample time to 3ms, which is probably similar or slightly faster than your flight controller's loop() time. However, as the PID library is measuring the sample time intervals of 1ms, this means that your interval time measurements are not very accurate or precise. This in turn might possibly have an impact on your I and D term calculations?

It might be better to calculate the loop() time as floating point number in seconds (using the micros() function) and use this to calculate the PID integral and derivative terms instead.

rossi86m

The Center points are ok.

Regarding What You mention on the last paragraph i Will measure how long takes the LOOP section

How do You suggest to calculate the I AND D of the PID?

This Is really usefull thanks!

Marco

MartinL

Hi Marco,

Quote
How do You suggest to calculate the I AND D of the PID?
I'm currently in the process of posting my PID library code on to my Github repository...I'll get back to you shortly with a link to it.

rossi86m

Awesome. pls let me know and i will try your library on my project!!!!

In the meantime i have to review if the delay time match the loop time and i will try to fly with just the P part

Thanks a lot!

MartinL

Hi Marco,

The "PID2" library can be found here: https://github.com/MartinL1.

To call the PID2 class constructor:

Code: [Select]
PID myPID;
To initialise the PID controller's gains plus integral and output limits, (all arguments are float data types):

Code: [Select]
myPID.begin(kp, ki, kd, iMinLimit, iMaxLimit, pidMinLimit, pidMaxLimit);
To compute the PID output:

Code: [Select]
float pidOutput = myPID.pidCalculate(setpoint, input, dt);
where "dt" is the sample time in seconds.

The sample time "dt" is calculated as follows:

Code: [Select]
uint32_t timeMicros = micros();
dt = (timeMicros - lastTime) / 1.0e6f;
lastTime = timeMicros;

where "lastTime" is a uint32_t data type and "dt" is a float.

On the Arduino Nano this gives you a sample time accurate to 4 microseconds.

rossi86m

MartiL thanks you a lot for that.

I will try your library on my project!!!

Once i have the code ready i will post the code so you can review it

Thanks again!
Marco

rossi86m

MartinL,

Thanks alot fpr the library  i had some time today to check how it works and now my configs makes more sense.the bicopter is not respondig like crazy.

Attached you will find my code.

I would appreciate if ypu can check it and let me know if i am using the library in the right way. Something that i am not sure how to set is the min and mx i onthe constructor

Thanks again!
Marco

Go Up