Welcome to this talk. I'm David Melendez and I want to share with you several projects that I have been over the years. The title of this talk is Building Drones the Hard Way because we are talking about three robots. One each with their particularities. So I named this project Trust Robotic Router Platform at the beginning. And the leitmotif was low or nothing cost of embedded platforms. The Internet of Things and they use whatever is lying around. And I don't like that. I don't like that. I don't like to recycle. Don't recycle at all. Simply reuse. So for the first two robots, I decided to use a router. Some of you may know the Linksys. It's a very classic router. So like seven years ago, I decided to build my first robot. It's called Texas Ranger. So we are going to see why. The main reason is to use the Linksys. Seven years ago, there was no Raspberry Pi or maybe Arduino, but it was very new. So I decided to use a Linksys and a homemade PIC board. Homemade. So I loaded it to Linksys, the Linux open WRT, and we got everything. And the second one was a drone. We are talking about all of them. With the Lafonera 2201, a very old model indeed. So the wrong one is the... This is a rover, Texas Ranger. You can Google it and you will find a lot of stuff about this. But I would like to share with you this robot. But this was the first time with a robot. So this robot has a Linksys, two boards, an IP camera, and two guns. Okay? The two guns are made with plastic guns, turned backwards, and all the bullets fall into the camera. So I only need a transistor to make work the gun from the PIC. The PIC was connected directly to the Linksys. By serial port. And we have an interface. And the laser, this is the laser, was used to estimate the distance between the robot and, for example, the wall. By calculating the distance between the most bright light on the screen, the capture screen by IP camera. The router decompressed. they might damage. And then to calculate, estimates the distance between the robot and the wall. So the first one is the Texas Ranger. And the second one was the MIT the And it's little wind for on ARA as a router, like the Texas Ranger is the same. Aye aye. the same technology at the beginning because I still use the open WRT and I was to program the stabilization process inside the router because I decided to program my own stabilization program and avoid any kind of like Ardupilot or so on, just for fun and to learn how the stabilization process works and I would like to share with you my insights so the telemetry and control, the first attempt was a success it was by control by the web page of the router by case logs by javascript but I found that it was that was not very comfortable to pilot the drone, especially with the drone can kill you because it's too big. So we all know what's the ABC for quadcopters and drones. So we can skip this slide. I think that we all know we have four motors, two spinning clockwise and the other two spinning counterclockwise. So we have a complete control over all the axis. You want to turn to one side, we spin faster one motor and the other. Well, this is the architecture of the ATROPOS. This kind of slide is for troll you. So... So, don't be afraid. We have a lafonera in the front with a background process. But at the beginning, we have a client in web page with an iframe taking the camera. At the first time, it was an IP camera. And we have a control, a control for like this one. This is not an ERC, it's a USB trainer. So, it's like a remote control, like with PlayStation and so on. Lafonera takes the commands through our Wi-Fi and tells to the main process all the commands. All the commands from pilot. That flight control runs inside the Linux box, inside the Linux router. And it has to be some kind of special tweaks in order to achieve some kind of real-time execution. We know that Linux is not indeed, by default, a real-time operating system, so we have a special policy, a scheduling policy to achieve this, some sort of real-time response. So, we need to read sensors, make equations and send the commands to the motors in a fixed time. In a specific fixed time. So, we cannot make 100 calculations. in a second and 200 in another second because you have to be very time constrained. We are talking about that later. So the inter-process communication is made by shared memory for fast response. And the sensors are Wii motion, are the Wii motion plus and the Wii nunchaku. It was taken from the Nintendo Wii console because like six or seven years ago it was not so easy to buy a complete set of sensors and the best choice was to go to the supermarket, buy some Wii sensors, not having the Wii console and connect it to the Nintendo Wii console. So it was taken from the supermarket to the router lights. Okay? So the first step we need to identify in the router is where is, where are the lights? Because the lights are GPOs. Okay? So if we have enough GPOs identified, we could make a virtual I2C bus. Okay? By software. So the first step we need to do is connect the I2C bus to the Wii motion and the Wii nunchaku. I could identify four pins. For example, the network, the LED network activity or the Wi-Fi activity. We have several pins identified here. So I could make two I2C buses to connect the Wii motion and the Wii nunchaku. Well, this is some kind of professional soldering. I pretty, this is pretty awesome, I know. So we have the GPOs, LEDs attached to that, and the serial port. That is useful too, as you know. And this is, there are the steps to load the, to compile the model of the I2C. This is the I2C bus. This is the I2C bus. This is the I2C bus. So then, you, you would put theseà — this is the bus for I2C bus. Because this is not, you, you, you don't have a driver because you don't have the specific hardware with I2C. Simply you, you create an I2C bus but by software. Is not related to any specific hardware. So we have to load the modules and that's the commands. We, we tend to the, to to the, to the kernel me. What, which pins of this module we have called the I2C models? CPU are related to clock and the data, okay? So we will bus 0 and bus 1 with the GPOs 4, 7, 3, and 1, okay? So I leave this information. We load the module at the start, and we can throw the I2C detect command as normal. But this is the serial port of the Fonera. It's no real mystery here. And I would like to explain how it works a little and why I need Wiimotion Plus for the Atropos. Well, Wiimotion Plus is a gyroscope, so we have three axes. Pitch roll and jab. But it gives me angular velocity, okay? To take the real angle, we multiply angular velocity by time, okay? But there is a problem. It drifts, okay? If you multiply over and over time, it will drift, and it's the same problem that if you are too drunk, and you turn around enough times, you can go to the ground, okay? So we need an accelerometer to cancel that drift. And the accelerometer is taken from the wind and chuck. It's also an I2C port. And if acceleration. Well, we need this to cancel the drift, and the acceleration is taken only when the drift has to be cancelled. The other time is not necessary, okay? And the magnetometer, this is not mandatory, because this only cancels the course angle, so it's optional. Well, in order to read with the I2C with a Linux program, we need to have the I2C port, and we need to have the I2C port. One of the easiest ways to read it is including the I2C header of the Linux kernel, and we rate it like a regular file, okay? We can ask for the specific sensor that we want to read. We can also use the CTO command to read the gyroscope or the accelerometer, okay? So this is the funny part, because we have to mix these two sensors to obtain an attitude, where the real motion on the how the drones is moving, in order to react and send the proper commands to keep the drone stabilized. All this shit is managed by Arduino pilot easily. You can put the Arduino pilot, and everything works fine, okay? But if we want to make this by ourselves, we have to deal with this shit, okay? But this is a pretty fancy. fancy because, well, the first approach that I made was for, okay, we have the poor man Kalman filter, okay? Do you know Kalman filter, please? How many? One? Well, it's fine. You? Okay, two. It's pretty fun. So, this is like the paper, the original paper was the balancer filter of the MIT. You can see that. And you can stake in for that, okay? So, the first approximation, the first approach was to take the angle of the gyroscope, multiply for delta time. Delta time is the time between rifts. That is because it's important to keep rifts at the same time because the T is fixed. It's a constant. So, you can remove that from the equation if we have a fixed delta time. So, this is our first approximation. So, we have some kind of stabilization because I'm taking into account a very, very much the gyroscope, but too little the accelerometer. You have here the gains. And we have some kind of stabilization. But this is the funnest part because what happens if the drones, okay? This is the sensor, okay? And the sensor takes into account this turn, this turn, and this, pitch, roll, and IH. Okay? But each axis is related to each axis of the sensor. But what happens is I'm moving like this. The pitch is no longer the pitch. The gyro is no longer the gyro. The gyro is no the last movement. The last movement, this is the gyro. We will have to make videos later. And the gyro is Well, it's not the same movement. Well, again, we have a jowl, okay? And the jowl is like this. But the jowl now is not like this. It's like this. But the related axis of the sensor remains the same, okay? The jowl for the sensor still is that. But for the drone, no more, okay? That pretty stuff is blown mine from the first time because we need a 3 plus 3 matrix transformation in order to transform the coordinates of the hair or the sensor to the coordinates of the drone. So we have an I values. That is related to the X of the aircraft. It's related to the X. Well, you see that, okay? So we have to work. Once we have the conversion between the axis of the drone and the axis of the sensor, we have three things. Absolute angle, radiance, okay? We have angular velocity, radiance per second, from gyroscope. And the angular acceleration, radiance per second per seconds, okay? So don't go away, please. Once we have an attitude, we have to send a proper command to motor. But what command? What quantity? What fucking sheet of anything? So we have this algorithm. So we have this algorithm that you can... It's taken from the Wikipedia, okay? This image. You can search for that. And we have three terms, okay? We have the proportional term. That is, we have a zero... I have to stay at zero angle to stay stabilized, okay? My set point is zero. But I am at 10 degrees. My error? My error is minus 10 degrees. So I have to take into account the error that this is the difference between where I am and where I want to stay. So I multiply the error by a number. Which number? I have no idea. I have no fucking idea. The first approximation is, okay, let's test, okay? And you test. You put the drone like a segway. I fix it with only movement with one angle. And you test its behavior. But it's not enough. You can't control a drone with a proportional gain because it's not enough. You have to take into account the integral. Don't throw me things, please. The integral is to only take into account how much time I am with the error, okay? It's like you take the mouse and you naturally, your brain, are calculating the integral. Because if I can't lift the mouse, my brain without notice... I'm not noticing that. But my brain... Will send more power to my hand to lift the mouse. That is the integral. I'm alone time with the error. So I accumulate the error to correct. And the other one is the derivative, okay? The derivative thing takes into account how much speed I'm approaching or leaving my setpoint, okay? So I have to take into account that's free terms, and I have to tune it by trial and error, okay? It's the best way, although you have the real model of your drone, almost all the variables, and you can calculate Laplace transform and so on, okay? But the... For poor men, you can try to real an error. So this is a nested PID because we applied a PID to angular velocity, but over the roof, we apply a PID controller. This is just for the record. So this is the Atropos with a professional grade mounting with all the stuff. And we say... And we say... And we say... So we have to send... Once we have to send... We have calculated all the calculations, we have to send to the motors the signal. So the signal is a PWM, a pulse width modulation, but it cannot be made inside the router because it's not real time. We have specific hardware. So I use a PID, okay? scheduling from the process inside of the Linux box. This is only for if you want to investigate. I use the get priority, the library. So in a policy of first in, first out. Okay? So, there is some process by default in the Linux box that it's, that they are not, they are useless. Okay? Like the watch log. Because this is what happens if the router hangs with I'm flying my drone. Okay? It's no, it makes no sense. Well, we see the, the motors and so on. Okay? So, this is what happens. And this is how I control the drone throughout the web page. This is what's my first approximation with Ajax. But I had, I had to tweak the, the web server because too much, too fast Ajax petitions, queries. They are not, they are not too much for the, for the router. So I have to tune the, the web server. Okay? That's the, the remote. This is onlyhö ajostik. Okay? It's regular just stick. And, I would like to. Do you say something off Android? Because, I was thinking about to, to indicate a thing on that part. So, we have a then avoid a PC to control my drone, okay. I'm going to put all my stuff, my pilot stuff to a tablet. Okay? So, I have to recompile the whole image only for tiny and ridiculously module of JoyDev.ko. So, thank you. And the last one was in the last part of this talk, in Spain, a guy sent to me the authentication package to the Wi-Fi of the drone. It was not so funny. Okay? So, I decided to make my own protocol by Wi-Fi that I explained in the talk before this. You can find it with the... I don't know if you can see it. I don't know if you can see it. The project interceptor, you can find it in the DEF CON web page. This is my project interceptor. It's made with chopsticks because if I make with a 3D printer, nobody believes me that this is my drone. Okay? So, and I like this sheet. I like to make things with my hands. Okay? So, I decided to make a much smaller drone than the Atropos because Atropos can kill me. And especially when I travel with it, with the airport. So, I decided to make a hand-sized drone. This time with a regular sensors that you can buy in Chinese... dealers and so on. And... but there are some... there are some things that they have to take into account. First time... first one that Chinese sensors maybe... maybe they are not documented. Okay? Maybe you can tune the filters and maybe your drone has too much vibrations. If you... if you look close enough, you can see that it has a lot of vibrations. Look at this. Look at this. What do you think that... that could be? Well, there are... the English term, thermo... thermofusible? With the... this... this kind of... pipes you have... do... you take to... to protect wires with the solder. Okay? Shrink to it. Thank you. As a... as a dampening. Okay? To... to... to take into account the vibrations. So, it was not enough. And I attached a 20 euro cent coin. To make the sensor the... the... the perfect way to absorb the vibrations. Okay? I have to do this because I can't tweak the filters of the sensor. But it has... it has an advantage. That sensors make all the math stuff for me or not all but the first part. Okay? The... the real estimation. It's low budget. Forty dollars. No, seriously. And it has hacking capabilities. And it... the idea is have to minimum size and weight. So, it is based on the vCore 2 Linux board. I think it is the tiniest board on the market. I don't... I don't know if any other... but it's tiniest. But it's like a router. It's like a regular router. But you only have the board. Okay? The... I have no commission for this. But... you... you can see all the parts. Let's see the vCore. And the... the interesting part is it has four pools with modulation outputs. And that's because... I can't avoid an extra microcontroller for my setup. But there is a problem. When you build the vCore, only two modules of the pulse width modulation are enabled. The other two are for UART debugging. Good job. So we have to disable UART and enable the other one. But I went to the forum of the vCore and a random guy asked, how can I enable all four pulse width modulation pins? And the vCore creator said, this is a hard way. And I said, I don't know. This is a hard way. And the vCore creator said, this is a hard way. And the vCore creator said, this is a hard way. And the vCore creator said, this is a hard way. And the vCore creator said, this is a hard way. And the vCore creator said, this is a hard way. And the vCore creator said, this is a hard way. And the vCore creator said, this is a hard way. And the vCore creator said, this is a hard way. And the vCore creator said, this is a hard way. And the vCore creator said, this is a hard way. And the vCore creator said, this is a hard way. And the vCore creator said, this is a hard way. And the vCore creator said, this is a hard way. And the vCore creator said, control section and better take the so-called so then you can enable the this module and you will be a good Linux hacker good job man very helpful so the this is what you need to enable the the four pulse width modulation output and disable the debugging UART so we have to redefine the pins but we have a pin name but and a pin function this can be tricky because we have UART function and UART name if you can see that we have the UART pins but then we with the not the word a function but the pulse width modulation function okay we redefine the the muxer and we have this is only for the record the that's it that you can you have to take this information and the this is my impretending time I'm knowing that I'm doing my work the power stage of the interceptor drone is a is not performing with a electronic speed controller as usual because I choose a bruiser a bruised motors okay Bruce motors don't doesn't need an entire electronic speed controller it's only needed one mosfet a capacitor and a Scotty diode why we need some kind of stuff apart of the mosfet that is because the motors we when we power the motors we are putting power power on the circuit okay but we're not powering the motors are at maximum capacity okay we are modulating more or less the the the power so what happens we when we turn on and off the switch of the of the motor the motor gene generates electricity work because it is spinning it it acts as a generator so we have a a generator so we have a generator so we have a generator so we have a generator here not going to be you removed shoots some more motor later you got more now we dag all change the abrupt which is the first what came out of it and assume it all change the abrupt which is the first what came out of it and assume it relatively well and is supporting the motor and using the batteries we pulled less and less power this process I think very well is notых the capacitor and the scotty diode