The quadcopter : control the orientation

We will use use these axes as reference

Quadcopter principle

The quadcopter orientation can be defined by three angles : Pitch, Roll, and Yaw. These angles determine orientation and therefore the direction the quadcopter will take. Basically, changing the pitch will make the quadcopter go forward/backward, the roll  bend to the left/right, and finally the yaw will make it rotate around its vertical axis.

So, to fully control a quadcopter- i.e make it go where you want over your neighbors' garden to spy on them- you just need to control these 3 angles. Do you? Almost ;). You need a 4th parameter, the throttle of the rotors. Obviously, if the propellers are not spinning, it would be hard to take off, wouldn't it? ūüėČ But let's forget about that and assume that the throttle is sufficient enough so the drone takes off.

Control individually pitch, roll and yaw angles

In order to change the pitch and roll angles , the main idea is to change each motors speed so the quadcopter starts bending in the desired direction. Let's formalize things a bit and define the motors "power"  in  C++ language style :

int motor1Power, motor3Power; // Motors on the X axis

//=>; changing their speeds will affect the pitch

int motor2Power, motor4Power; // Motors on the Y axis

//=>; changing their speeds will affect the roll

As I said in the previous paragraph, the motors power depends on the throttle you can give them with a remote control for example. A simple implementation of this in an Arduino-like sketch would look like this


void loop(){

motor1Power = throttle;

motor2Power = throttle;

motor3Power = throttle;

motor4Power = throttle;

}

What is done here is just simply redirecting the throttle input (coming from a remote control for example) to the motors, which will just concretely change the altitude/ vertical speed of the drone.

Now, let's think a bit about how to make the quadcopter move forward/ backward . This motion corresponds to the pitch angle. In order to change the pitch, we only need to change the speed of the two motors on the X axis. Indeed, affecting the speed of the motors 2 and 4 (on the Y axis) would just start a rotation around the X axis (therefore changing the roll angle).

But how to change the first and third motors speeds?

If you try adding the same value offset to the motors speed, it won't change anything because what you need in order to incline the aircraft is a difference in the motors speed. Imagine you attach two weights of one kg to the two opposite motors, what happens to the pitch? Nothing, you would need to attach different weights to incline the quadcopter. It's very intuitive and works exactly the same with the motors speed!

The best way to get different motors speed is to add the offset value one one motor output, and to subtract it on the other, so the "overall throttle " of the axis remains constant and therefore changing the pitch won't affect the quadcopter's "vertical speed"

 Throttle_{13} = \frac {(throttle + offset)+(throttle-offset)} 2 =throttle

By the same method, you can change the roll angle by changing motors speeds on the Y axis (in our example motors 2 and 4) and therefore control separately pitch and roll! Let's look at the updated pseudo-code introducing two new inputs pitchOffset and rollOffset

void loop(){

motor1Power = throttle + pitchOffset;

motor2Power = throttle + rollOffset;

motor3Power = throttle - pitchOffset;

motor4Power = throttle - rollOffset;

}

And that's it! This is how the pitch and roll are controlled.

 The yaw..

Why is the yaw different? Because it's not a matter of inclination here, so changing two motors speed won't make it. But i forgot ¬†to tell you a little detail about quadcopters ūüėČ Two propellers turn clockwise, the two others turn counterclockwise. And how does it help you? The answer is the torque . When an object rotates around an axis, it creates a torque, creating a rotation movement of the body holding the propeller, and that's why traditional helicopters have an anti torque rotor on their tail, keeping the rotorcraft from spinning until the pilot pukes (it is more likely he dies in an awful crash). With opposite rotations, the quadcopter doesn't need and anti-torque tail, one axis compensating the torque of the other.

Changing the torque and therefore the yaw seems now really simple,doesn't it? Just add a yawOffset to the speed of two motors on the same axis, while you subtract it from the speeds on the other axis (so the overall throttle doesn't change). The final code looks like this:

void loop(){

motor1Power = throttle + pitchOffset + yawOffset;

motor2Power = throttle + rollOffset  - yawOffsett;

motor3Power = throttle - pitchOffset + yawOffsett;

motor4Power = throttle - rollOffset  - yawOffsett;

}

(Y)awesome.

And that's it for the basics of how to control a quadcopter, hope it was clear and detailed enough. If you want to take it to the next level and auto stabilize your quadcopter, it's right here ūüėČ

The quadcopter part 2 : specifications and first manufacturing

So, as you can see there, we had a beginning of stabilization at the end for our first prototype. Still, we were not able to correct the yaw axis, making the drone really hard if not impossible to control. We decided last weekend to build from scratch a new version of the drone. We established the following requierements for this V2 :

- The drone must be built from carbon tubes and balsa wood (that solution seems to be the easiest way to have something very light and robust). To ensure a perfect aligment of the 4 motor axes, we'll double the carbon tubes  for each arm.

- We'll use the following sensors :

  • A gyroscope L3G4200D and an accelerometer ADXL345 to capture the rotation angles of the drone
  • A magnetometer to capture the absolute rotation around the yaw axis (actually, we found a thesis paper showing how a magnetometer, a gyroscope and an accelerometer can work together to give a very precise angle for each axis, so it will do more than only give us the cap)
  • A GPS to capture the absolute position in the 3D space
  • A telemeter (basically a sonar) to capture preciselly the altitude of the drone between 0m and 5m.

Here is a little description of the elements we ordered (unfortunately, we didn't receive the shipment this weekend)

 

3 axis magnetometer "HMC5843"
SiRF StarIII‚ĄĘ based GPS module
SRF02 telemeter

 

 

 

 

 

 

 

 

You can find pictures of the accelerometer and the gyroscope in the previous article. if you want to know more, here are the links to the datasheets

As you can see, all the devices are controlled by numerical interfaces : I²C , SPI or serial bus. This is very convenient to use thanks to the existing Arduino's libraries.

We tried after this to build a 3d model of what the drone will look like

 

Very basic modelisation, but still usefull to check if everything's OK.

Actually, this modelisation will be also used to machine the different parts. Indeed, we made a CNC a few years ago (may be will come an other series of articles to describe this awesome project). To generate the toolpaths, I use Mastercam , and the software used to control the mill machine itself is Mach3.

The toolpath used for machining 4 motor mounts

For now, I made a little video of the machining of a motor mount.

 

[youtube]http://www.youtube.com/watch?v=L6pmeJbbn9Q[/youtube]

 

Gluing the landing gear.

 

 

 

To assemble the parts, we massively use epoxy glue (made of 2 components : a resin and a hardener) so there is no possibility for the vibrations to disassemble it.

 

 

 

 

Here is the result. So far, so good : the 4 motors are perfectly aligned, and we should avoid any excessive yaw-drift problems.

The quadcopter part 1 : genesis of the project

When I was a student in my engineering school, we decided to build a drone. The project was abandonned after about one year, more or less because members of the robotic team didn't succeed to stabilize the drone. So with my bored engineer friend , we decided to give a second chance to this project. We took what the students made, which basically looks like this:

The very first version of the quadrotor.

After a few tries, it turned out that the power of the 4 motors wasn't enough for the drone to fly. So, we decided to make another frame, using light materials: carbon tubes and balsa (it's a very light wood used by modelists for their aircrafts). The verdict was straightforward : old frame's weight : 350g, new one : 70g. Only half of the power was enough to make it fly.

The quadcopter V1, and its effective and beautifull landing site

We had here a nice frame to start our experiments. The first version came with an accelerometer and a gyroscope that we decided to keep. We also decided to use an Arduino because it's really easy to use, and there is out there a massive list of existing libraries. Implementing a PID controller, and gathering the commands of a 4 channels radio-emmiter, we were able to make it slighly steady. So this is how it worked. The 2 sensors (accel and gyro) are constantly read by the Arduino, which compute the angle of the 3 orientations of the drone. Why using a combination of a accelerometer and a gyroscope ? Because the accelerometer is nice for a static use of the drone (i.e. it flies at a constant speed), but as soon as it start to move, the accelerometer can't be used. The gyroscope gives us an angular velocity, which means that we have to integrate the value to retrieve the angle. The wrong part is that, due to the integration, the obtained angle will slowly drift. We compensate with a negative term in our equations, which is found experimentaly.

 

Basically :

angle = k*angle_{accelero} + (k-1)*angle_{gyro}

Where, if the ADXL gives us a value between 0 and 1g:

 angle_{accelero}(deg) = \frac{180}{\pi}*\arcsin{ADXL_{value}}

And if the gyroscope gives us a value in ¬į per second, and d the drift value.

 angle_{gyro} (deg) = \int_{0}^{s} L3G4200D_{value}\, \mathrm dt-d

Then, we use a PID to control each of the drone axis :

 order=k_p*angle+k_i* \int_{0}^{s} {angle}\, \mathrm dt +k_d*\frac{\mathrm{angle}}{\mathrm t}

Now come the hardest part of that chemistry : find out k_p,k_i and k_d; which can bring the drone to destruction (actually, it did).

The tiny ADXL345 accelerometer and the L3G4200D gyroscope

But still, there is a lot of work there before this drone can fly on its own. We are currently working on a frame v2, which will be the object of a soon-coming article.

Our astronomy rig

The milky way over our telescope
The milky way over our telescope

We started  to think  about buying a telescope last year in October, when one night, we took pictures of the Moon with my camera and a 300mm lens, and that was pretty cool to see some details on the surface. So then we looked for other objects to shoot  and pointed the camera towards the Orion Nebula, one of the biggest objects you can observe in Winter. The result was amazing.

Orion nebula
Amazing, indeed.

NOT. It was not amazing. But we were really excited about seeing this reddish thing surrounded by a lot of stars. Why are the stars looking like white lines? Because the earth is moving, and the higher your lens focal length is (basically the zooming factor), the faster the stars will seem to move in the viewfinder(only two seconds of exposure here).

We didn't know it back then, but this was the beginning of our new passion for astronomy. A few weeks later, after having read all the possible things we could about telescopes, we decided to  acquire a telescope, the Skywatcher 150/750mm.

The Skywatcher 150/750 on an EQ3 equatorial mount
  • ¬†150 is for the diameter (in mm) of the principal mirror of this Newtonian telescope, which determines the quantity of light that it will gather. So the larger the mirror, the more light you get. And obviously, the more light you get, the better you will see!
  • 750mm is ¬†the focal length of the mirror, the length necessary for the light beams hitting the mirror to converge. In the end, it means zooming. The higher the focal length is, the higher the magnification will be.

So, where do we look? As you would do on a microscope, you look through the eyepiece (or ocular lens) , an optical lens magnifying the telescope image. To get the magnification of what you are looking at, you just need to divide the focal length of the telescope mirror by the focal length of the eyepiece. Hence, having different eyepieces enables you to look at objects with different magnifications, the same way you would do with a microscope.

The Hyperion 5mm eyepiece, giving us a magnification of 750/5=150x

Unfortunately,  the magnification has a limit. Indeed, the bigger the magnification is, the smaller the zone of the sky you're looking at is. So this means that the amount of light  getting to your eyes gets smaller with the increase of magnification. A general rule of thumb says that the maximum magnification you can reach with a telescope is two times its diameter in mm, so for our telescope, 150*2=300x. If you want to use an eyepiece giving you a magnification higher than this threshold, you can, but don't expect to see anything with such a small amount of light getting to your eyes.

The "tube" and the eyepieces are not the only parts of the telescope. Another very, very important part of the telescope is the mount. Indeed, as we saw earlier, the earth moves and if you want to observe objects in the sky and keep them in your field of vision, you need a way to compensate the rotation of the earth so the celestial objects "stay" in the eyepiece.  This is where the equatorial mount comes in.

The equatorial mount EQ3-2

An equatorial mount  is a telescope mount made to easily compensate the rotation of the earth. It has two axis of rotation, one of them being the same axis the earth rotates around! Hence, you can just move the mount around one axis (the right ascension axis) to keep the object in your field of vision. This task can be done by a motor, compensating almost perfectly the rotation of the earth.

Credits to http://nightskywatching.blogspot.fr
Long time exposure shot showing the rotation of the earth. Polaris is the center of the circle

The tricky thing with an equatorial mount is to align its rotation axis with the North/Pole axis of our planet. This alignment is fundamental for astronomers who want to take pictures with long exposure times (a few minutes) and don't want the stars to "move" during the shot (like it did on the first Orion nebula picture). For this, the goal is to align the right ascension axis of the mount with a star aligned with the N/S axis of the earth. In the northern hemisphere, Polaris( also known as North Star, Northern Star or Pole Star) is this star. In the south hemisphere, it's a little bit more complicated, because no eye-visible star is close enough to the south pole. People need to use two stars of the Crux constellation to "find the South" on the line joining them.

Our mount is equipped with two motors(one per axis), allowing us to compensate the rotation of the earth but also to move from a location in the sky to another without having to touch the tube. Having two motors is also necessary for what is called the "goto". The goto is a really great feature of telescopes where the user can say for example "I want the telescope to go to the Andromeda Galaxy" and the telescope will automatically position itself to the coordinates of this galaxy. A lot of telescopes are sold with a goto pad, where you can just select where you want the telescope to look at. This feature represents a huge gain of time for astronomers, and especially beginners like us.

We really wanted to have this goto function on the telescope, but since the control pads were so expensive, we decided to build a Picastro, a great hardware "box" based on a PIC micro-controller and designed by Arnaud Gérard( more details here ). The Picastro is able to communicate with a wide range of telescope (there are different protocols for communication) and has a lot of features that most of the goto kits don't have( such as controlling a focus motor). So cheaper and better? Yes. The downside, if it's one, is that you have to build it yourself. A bit like an IKEA goto kit, if you will.

The picastro

The Picastro can be controlled by a computer, via a serial port, or by a pad, and since it is a DIY object, you can tweak it as you want, and re-use it if you change of telescope one day since it is compatible with many communication protocols. We are currently working on a big project for the Picastro, more news on this coming soon ūüėČ

Finally, the last part of the rig is the camera. Astronomy cameras can be very, very expensive because they use CCD sensors, extremely sensitive to light. They are almost always monochrome, which means that if you want to have colored pictures, you need color filters (RGB filters for example) , and at least 3 pictures (one with just red, one with  green and one with blue light) and then recombine them to get a picture. Even if the quality of those pictures can't be matched by a traditional camera, DSLRs (or reflex)  cameras can be mounted on the telescope like an eyepiece would be, and give pretty good results for beginners eager to start learning the real science that astrophotography is. The CMOS sensors of a DSLR may be less sensitive than a CCD sensor, but it offers for lower price a much bigger resolution (18 millions of pixels for our Canon 550D) than entry-level CCD cameras (just 1MP). The camera is controlled on the computer via the Canon EOS utility software.

Even if we are still extremely far from being good astrophotographers or astronomers, we are starting to get better and from the first shot of the Orion nebula taken with a reflex camera on a regular tripod, we've come to this:

M42 Orion nebula
A little bit better

So far, so good. We will try to post as often as we can new pictures and will soon explain the basics of astrophotography!