Shop OBEX P1 Docs P2 Docs Learn Events
Propeller Autonomous UAV Quadcopter — Parallax Forums

Propeller Autonomous UAV Quadcopter

th3jesterth3jester Posts: 81
edited 2011-04-11 07:19 in Propeller 1
The code is not finished yet I would like some constructive criticism on my programming and structure. I know this may be hard as it's very application specific but I've tried to comment on most methods.

Is anyone curious in picking apart my code in order to help? I would like to improve the efficiency, cog usage, memory usage, speed of PID loops (there is 5), Kalman Filter, PWM outputs, and just overall structure. Eventually there will be communication with a Spinneret, ADC 3204 chips, Linescan Image Sensor, and a Geiger counter.

I have to warn those interested that the code is not finished, there is still a lot to integrate and develop, yet if I can optimize what I have then I know how to do it when I add more functions.

Thank you. I will give more specifics and code if there is interest.

Comments

  • Dr_AculaDr_Acula Posts: 5,484
    edited 2011-04-10 17:42
    This sounds very interesting. Please post all the code. I've been amazed on this forum at the way the collective group can take some code and shrink it and make it faster. Are you running out of code space yet? And do you need it to run faster?
  • th3jesterth3jester Posts: 81
    edited 2011-04-10 17:58
    I've already been able to reduce to 1/2 of what I originally had. I would like the PID and Kalman to run faster. I believe the bottleneck is the floating point math. Also I think how I pass variables could be improved.

    UAV.spin is the top object file. Again this is still in the testing phases. At the moment I am going through the different autonomous routines that are needed to perform different operations. i.e.- rotate to a certain degree.

    If this seems to complicated to understand or get through then I can wait till I get closer to finishing. Just let me know. Thanks for helping.
  • Cats92Cats92 Posts: 149
    edited 2011-04-11 05:55
    Very interesting .
    As I am rather a beginner in this area , is a bit hard to follow your code:

    In + config where are front, rear, right and left motors : M_A ,M_B, M_C, M_D ?
    Which pout0, 1, 2, 3 is comming from radio commands : throttle, pitch, roll, yaw ?
    Perhaps try more clear names

    How do you mix this radio commands to get ESC commands ?
  • th3jesterth3jester Posts: 81
    edited 2011-04-11 07:19
    For a "+" configuration, the front motor is M_A, left motor is M_B, rear motor is M_C, and right motor is M_D. For a "X" configuration, which is what the code is doing, the front motors are A and B and the rear motors are C and D. The left motors are B and C and the right motors are A and D.

    X:
    C______D

    B______A

    +:
    ___C___
    B_____D
    ___A___

    There is no radio commands, this is a completely autonomous UAV, which means no user input is needed for it to preform functions/flight. It is a completely closed loop system. The Pout[0], Pout[1], Pout[2], and Pout[3] are the results of the PID loop.

    Pout[0] corresponds to the Gyro X axis ( which is in deg/sec). Pout[1] is the Gyro Y axis. Pout[2] is the Gyro Z axis. Those three PID outputs keep the UAV stable and correct for outside influences, drift, ect... The PID loop tries to keep those sensor values at 0, if any change in the sensor readings then the PID controller will compensate and correct for the error.

    I am still adding the following:
    The PID controller will have 2 more loops. One for the UAV pitch and the other for the UAV roll. You can consider these to be equivalent to a person hold a remote controller and moving the joystick. The difference is that the Prop is the one telling the UAV where to go and if it needs to pitch or roll. These is done by using a decision engine, which can simply be a set of IF...THEN statements or a CASE:SELECT.

    i.e.- let's say the UAV is programmed to perform an explore routine. In which the UAV will navigate throughout an area (with avoiding obstacles) and simply explore. If the UAV reaches a wall then it rotate and then pitch to go in another direction. If there is an obstacle (filing cabinet) then the UAV may roll, pitch, or rotate and pitch to avoid it.

    To determine how to add the PID controller outputs to get a reasonable PWM signal to the ESC, it's easiest to draw a picture...... So draw a picture of the configuration you want, identify the motors ( I used A,B,C,D) it doesn't matter which motor is which. Once the motors are identified do not change their names. Determine which directions and the sign of the gyro sensor readings. Now start with Gyro X (pitch). Let's assume you decided to use a + configuration and you labeled the motors per my little diagram above. So, to pitch in the negative direction (motor A tilts down) then Motor_A gets +Pout[0] and Motor_B gets -Pout[0], Motors C and D don't get an output for pitch because they do not change. If a bird lands on the UAV and cause it to pitch down then the PID controller will cause motor A's output to increase while motor B's output decreases which will level out the UAV and hopefully get the bird off. You have to go through each motor and consider what needs to happen to keep it level.

    The nice thing about this is that if the UAV doesn't fly in the right orientation then all that is need is to change a few + or - signs in the programming......if the UAV didn't crash and burn that bad.

    This may all be confusing, it was for me at first until I spent a good amount of time programming it. No other forum or community for quadcopters really had any good manuals/material to accurately and easily explain the inner workings of it. I will draw a simple diagram to help explain the above a little later, as I have a test to study for.....
Sign In or Register to comment.