You already created a thread for this topic:http://forum.arduino.cc/index.php?topic=462312why start a new one? Even if there is a good reason you should still post a link to the other thread so people can see that you have already been provided some information on the subject.
Hi Marco,In your code you're only using the gyroscope X and Y axis for roll and pitch, you'll also need to read the Z axis for yaw.
For the motors use the analogWrite() function rather than the servo library. To use analogWrite() at 490Hz on the Nano use digtal pins 3, 11, 9 or 10. (Pins 5 and 6 operate at a higher frequency, too high for the ESCs). The servo library operates at 50Hz and this frequency is not enough to allow the motor ESCs to stabilise the dualcopter.
Finally, I'd comment out the accelerometer and complementary filter code for now. Before you can implement auto-level you'll need to set-up the dualcopter using only the gyroscope, with the input from the pilot converted to degrees/s. This is variously called aero/rate/gyro mode and will ensure that you have your inner gyroscope roll, pitch and yaw rate PIDs tuned correctly. This is necessary before moving on to auto-level. For the PIDs, initially tune using the P term only. You'll be able to fly using the P term alone. Add the I and D terms after you get airborne.
I made a switch i put the servos on 5 and 6 and the esc on 9 and 10. Can you give me an example on how to use the analovwrite? Thanks!
Do you mean using the raw values from the gyro??
The analogWrite() function has two parameters: pin number and value. The value is a number between 0 and 255, so it's necessary to map/convert from your 0us - 2000us ESC values to 0 - 255.
I used the wrong terminology, I meant just using the gyroscope's values coverted to degrees per second.Another thing, the MPU6050 has an in built low pass (anti-aliasing) filter. For multi-rotor applications this has to be set at around 20Hz to 40Hz. Using Jeff Rowberg's I2CDev library, you can set it with the following line in your setup() code:
Finally, I'd also strongly recommend adding to your code an ARM/DISARM interlock for your motors. This can take the form of a button, stick movement or arm switch to allow you to remotely enable and disable your motors before and after flight. It just ensures that your motors won't burst into life if you accidentally knock the throttle stick (or whatever you're using to control the throttle), while connecting or disconnecting the battery.
I thought that analogWrite would also need some delay in order to generate the same signal than writemiliseconds.
Using AnalogWrite() there's minimal delay, as it will output the new value on the next PWM timer cycle. At 490Hz the selected pin will automatically produce a new pulse every 2.04ms (1/490Hz).
Hi Marco,I had a look at your code.AnalogWrite() is not a member function of the servo library, but a function in it's own right, so you can just call it without the "motor1" and "motor3" prefix:Code: [Select]analogWrite(9, 127);You're assigning the accelerometer Z-axis rather than the gyroscope Z-axis, as an input of your yaw rate PID.
You're assigning the accelerometer Z-axis rather than the gyroscope Z-axis, as an input of your yaw rate PID.
I have read that i would need a compass to get that value is that right? or is there a way to get z-axis gyro from mpu6050?
Wire.requestFrom(MPU, 6, true);GyZ = Wire.read() << 8 | Wire.read();
mpu.getMotion6(& AcX, & AcY, & AcZ, &GyX, &GyY, &GyZ);