Go Down

Topic: Quad Copter Project attacked me.... TWICE... HELP ME PLEASE...  (Read 71 times) previous topic - next topic

Raphaelrjohnson

Sooooooooooooooo

I have finally designed and built my horrible monster version of a quad copter.

Programming took me weeks as I have NEVER done any programming before and even bought a "C++ for dummies" book to get into it.

So far below is the coding I have come up with... Don't laugh, this is my first attempt. LOL.

I bought an Arduino Mega2560, a DJI bundle with ESC, Motors and props. I bought a generic GYRO and a 6 channel remote control complete with receiver. Powering it is a 3 cell Lipo.

I am having issues with power spiking at the motors. I can get all of the outputs to settle at zero, but for some reason, with or without the GYRO I get random power spikes at the motors. Yes, it has attacked me twice. Once it flew up at me and the second time one prop started to spin when I was near it. Just small scratches. LOL. So yeah, can someone look over my code and let me know if I'm missing something?

When I am looking at the outputs on the screen everything settles at zero. Every once in a while I get a random number pop up. -1, 3, 1, -4 and so on. It happens like ever 10th or so line and sometimes even sooner or later. with a delay(1000) it is not really noticeable, but with no delay, they seem to be causing me a problem. I can manually move the quad around by hand and I can feel the quad wanting to right itself because of the Gyro and I can feel the force it exerts when I try to control it with the controller. I know that my inputs and outputs are working, I just can seem to get it to stabilize itself when it is sitting still.

I understand about PID's and all that suff... well for the most basic part... but I can't really do that step until I get the random bugs to go away at a basic none flight level.


#include <Servo.h>

Servo Front;
Servo Left;
Servo Right;
Servo Back;

int FrontMotor;
int RightMotor;
int LeftMotor;
int BackMotor;

int rightx;
int righty;
int leftx;
int lefty;
int leftknob;
int rightknob;
int gyrox;
int gyroy;
int gyroz;

void setup() {
Serial.begin(9600);

Front.attach(9);
Right.attach(8);
Left.attach(10);
Back.attach(11);
}

void loop() {
rightx = (pulseIn(23, HIGH)/100-14);
lefty = (pulseIn(25, HIGH)/100-14);
righty = (pulseIn(27, HIGH)/100-10);
leftx = (pulseIn(29, HIGH)/100-14);
rightknob = (pulseIn(31, HIGH)/100-14);
leftknob = (pulseIn(33, HIGH)/100-14);
gyrox = (analogRead(0)/10-34.5) + (leftx*5);
gyroy = (analogRead(1)/10-34.5) + (lefty)*5;
gyroz = (analogRead(2)/10-41.5);

FrontMotor = 40 + (righty*7) + (-gyroy) + (-rightx*2);
LeftMotor = 40 + (righty*7) + (gyrox) + (rightx*2);
RightMotor = 40 + (righty*7) + (-gyrox) + (rightx*2);
BackMotor = 40 + (righty*7) + (gyroy) + (-rightx*2);

Front.write(FrontMotor);
Left.write(LeftMotor);
Right.write(RightMotor);
Back.write(BackMotor);

Serial.print("RightX");
Serial.print("\t");
Serial.println(rightx);
Serial.print("LeftY");
Serial.print("\t");
Serial.println(lefty);
Serial.print("RightY");
Serial.print("\t");
Serial.println(righty);
Serial.print("LeftX");
Serial.print("\t");
Serial.println(leftx);
Serial.print("RightKnob");
Serial.print("\t");
Serial.println(rightknob);
Serial.print("LeftKnob");
Serial.print("\t");
Serial.println(leftknob);
Serial.print("GyroX");
Serial.print("\t");
Serial.println(gyrox);
Serial.print("GyroY");
Serial.print("\t");
Serial.println(gyroy);
Serial.print("GyroZ");
Serial.print("\t");
Serial.println(gyroz);
Serial.println();
Serial.print("front");
Serial.print("\t");
Serial.print("right");
Serial.print("\t");
Serial.print("left");
Serial.print("\t");
Serial.println("back");
Serial.print(FrontMotor);
Serial.print("\t");
Serial.print(RightMotor);
Serial.print("\t");
Serial.print(LeftMotor);
Serial.print("\t");
Serial.println(BackMotor);
Serial.println();
}

jremington

Sorry, but you are basically missing everything. For example, it is obvious that you have no clue what a gyro does.

A clear case of trying to run before you have even learned to crawl.

We strongly recommend that beginners understand the basics of programming before tackling an advanced project like this. Plus, you do have to understand what the equipment does and what it is capable of doing, before you can program it.


Bearonic

I have NEVER done any programming before
And you have NEVER read the "How to use this forum" thread before. Do it.

knut_ny

I',m afraid it wont be able to fly with a gyro as the only reference   U will meeg an additional sensor to help tell orientation of the copter.

Googlr for the arducopter project..
Ny

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy