1

I have these information: x, y from gyroscope.

  1, 2, 3, 4: motors
  If the quadcopter is slant to front y is a positive number.
  If the quadcopter is slant to back y is a negative number.
  If the quadcopter is slant to right x is a positive number.
  If the quadcopter is slant to left x is a nevative number.

      1    front    2
        \         /
          \  -  /
  left     |   |    right
          /  -  \
        /         \
      3    back     4

I try to add the value from gyroscope to motors speed, like:

updateSpeed(m1 + y * -1, motor1)
updateSpeed(m2 + y * -1, motor2)

m1, m2 are actually speed of a motor and motor1, motor2 are the pins number that RPi send servo semnals.

How can I balance my quadcopter using python 2.7?

Thanks in advance.

Pablo Iuly
  • 13
  • 4
  • This is a really, really complicated question and the answers will depend greatly based on the quadcopter in question. How is it balanced? How strong are the motors? how quickly does the RPi react to the sensors you're using? – Jacobm001 Jul 26 '17 at 04:51
  • I find the RPi a slightly odd choice for this project. I think a microcontroller might be a better fit for what you're doing. – Jacobm001 Jul 26 '17 at 04:51
  • i don't know very sure. – Pablo Iuly Jul 26 '17 at 19:10

2 Answers2

1

I'm not sure what you're expecting from an answer here because I have done a similar project for my dissertation at university and that was 6 months work.

What you need to look into is a motor controller algorithm (such as PID control) which creates a feedback loop based on the current speed of the motor and the difference between the gyroscopes current positioning and its desired one.

It can be done in python but like I said, it is a lengthy project and getting a well tuned controller to keep your quad copter level is no easy task, even for an experienced programmer.

I would suggest trying to find similar projects people have done on the internet and see if you can follow or learn from them.

pfl
  • 341
  • 1
  • 6
  • I saw some projects like multiwii (or something like that), but these are for arduino and are writes in c or c++ or c#, i don't know. And I don't know c or c++ or c#. – Pablo Iuly Jul 21 '17 at 08:44
  • I need an example that balance my quadcopter. that's all – Pablo Iuly Jul 21 '17 at 08:45
  • Is it hard to write a PID-controller in Python? Why? – Bex Jul 24 '17 at 13:08
  • @PabloIuly Might be a good time to learn C or C++ if you want to do this type of project. You might be ok in Python all the way through, but you'll be dependent on finding the low-level code that you need pre-wrapped in Python by someone else. Your success on finding that may vary. Some basic C/C++ won't be hard to learn and wouldn't be a waste of time. – Brick Jul 25 '17 at 09:19
1

This is a common automation problem with a range of solutions from the last century or so - essentially, what you are working with is the inverted pendulum.

What you probably want to do to make this project a lot easier is to transform your axis so that you try to solve this problem instead:

       1/front
         |
         |
         |
 2/------+------ 3/
right    |      left
         |
         |
       4/back

This way, you will have two "separate" feedback loops: tilting front/back will only affect the power distribution of the motors 1 & 4, and tilting left/right will only affect the power distribution between motors 2 & 3. The easiest way to do this, of course, is to turn your sensor 90°. If that is not possible, you'll have to do some vector transformation before you feed the data into your loop.

A common way to solve this is with a PID controller - where P stands for proportional, I for integrating and D for differentiating.

There are several ways of implementing PID controllers programmatically. It's not that hard, and there seems to be several python implementations available.

Good luck!

Bex
  • 2,929
  • 3
  • 25
  • 34