Control Motor Speeds without ESC's using MPU6050

Hello, I hope you can help me with this problem.

I am looking at making a purpose build programmed robot which can fly. So like a Quadcopter but without the need to control it by a remote. It would be pre-programmed, or updated via Bluetooth/Wifi.

I have some code which allows me to see the Yaw, Pitch, and Roll, of the robot. But I need it to be stable while in the air. So using PMW pins on a nano I want to control each motor to keep the robot level.

I am guessing this would be achieved by some logic based on the Pitch/Roll combined, and it would adjust the speed of each motor. I am not sure how to go about this.

The second issue is even if I have the code required to keep it in the air level, I need to adjust the altitude using HM-04 sonic sensor, which would need to adjust all motors the correct speed to keep it at a constant/ish level.

I have looked at many examples for quadcopter codes dating back to 2011. But they all consist controllers which I am not really looking to do. So cannot replicate the math.

So, using PWM of pins 2,4,5,6 of the motors, and the constant data from the MPU how do I control the speed of each.

Here is the example of the data:

YAW: 74.2 Pitch: 8.2 Roll: 0.5 -- Flat

YAW: 74.2 Pitch: 29 Roll: -28 -- \ <--->Pointing Down

YAW: 74.2 Pitch: -17 Roll: -32 -- / <--->Pointing Down

YAW: 74.2 Pitch: 22 Roll: 30 -- \ <--->Pointing Up

YAW: 74.2 Pitch: -23 Roll: 26 -- / <--->Pointing Up

These figures change each time I move the angle of the base of the robot.

1 2
\ / <---- Motor 1 to 4
/
3 4

So to keep this level the speed of each motor would need to keep the Pitch / Roll as close to 0 all the time.

I will need the robot to move, but at this point, I just want to make it so it will hover level at a height specified.

Is this possible using PWM as I have read ?

So using PMW pins on a nano I want to control each motor to keep the robot level.

PMW? I'm not aware of any Arduino that can do PMW. Nor would I buy one that could. Shudder.

I am not sure how to go about this.

Why do you even think that you need to? Stop guessing, and learn how other people control attitude using an MPU6050.

What kind of motors are you using?

which would need to adjust all motors the correct speed to keep it at a constant/ish level.

Changing the speed of the motors causes the device to ascend or descend. Changing speed does NOT directly change the elevation. That is, you do not have a linear relationship between motor speed and elevation. So, if you are low, you can't just crank up the speed and expect to go to the right elevation.

Hi, I have heard Arduino can do pulse which enables the switch to turn off and on really quickly, or slowly. I thought that was PWM? Perhaps I mess typed the letters.

Using the HM-04 I can see the difference in hight, and using the pulses, as above, I can, in theory, see the math but to do this while also tying to make it stable I cannot get my head around the math.

The motors and propellors I am using from an old Syma X5C drone.

So, using the D3,4,5,6 and switching them on and off, but at different times to maintain hight, and level, would require math. Simply put I again, I cant seem to get my head around it.

Also, I have to guess, because as I stated above all the info such like MultiWii, or other projects, they all use controllers, which this is not something I require. Trying to untangle code which has been made minimal, from controller operation and flight operation I have found to be unworkable.

Using the same diagram as above:

1 2
\ /

/
3 4

Perhaps I should use two L298N controllers. One on 1 and 4, and the other 2 and 3.

So it turns the pins on and off to ensure the MPU is close to 0 on Pitch and Roll.

Then increase the pulse width to increase the hight, or shorten the pulse width to lower it.

Would this work in practice? I see issues with it moving around and not hovering in one small space ?

Would this work in practice?

No, none of it. There are lots and lots of web pages describing DIY copter projects, but to summarize briefly:

  1. Use logic level MOSFETs to control the motor speed, using PWM from the Arduino.

  2. Use PID loops to control pitch and roll -- advanced topic.

  3. Use another PID loop to control elevation, along with a sensor that can sense elevation (e.g. air/barometric pressure sensor) -- another advanced topic.

Expect months to years of learning as you go along.

Expect months to years of learning and crashing as you go along.

You forgot something...

The quadcopters with manual control are much more automatic than manual. The copter is analyzing the angles and adjusting power settings hundreds of times per second, just to stay in one place.

Get the manual version working first, then add the navigation layer on top of that.

I have found a working example of the MOSFET idea: PWM DC Motor Control

Which will seem to work, but if I can find the math / logic to ensure the motors do what they need to do to keep the MPU level is a head scratching moment. But thank you all for your help thus far.

I shall experiment with the example and see if, in practice, it will control the motors.

The L298 does not use MOSFETs. It is an older technology. The voltage drop can exceed 3.2V, which is not good if you're using a 3.7V LiPo battery.

Start the project with an Ardupilot or similar.

Addy:
Which will seem to work, but if I can find the math / logic to ensure the motors do what they need to do to keep the MPU level is a head scratching moment.

Go back and re-read response #4.

Hi @MorganS,

If you look a little further down the page, it gives an example of the MOSTFET, without the L298N.

Just need to scroll down a little bit.

MorganS:
The L298 does not use MOSFETs. It is an older technology. The voltage drop can exceed 3.2V, which is not good if you're using a 3.7V LiPo battery.

Start the project with an Ardupilot or similar.

I would love to use ArduPilot, but I am a Mac user, and it's not available for OSX :frowning: