 Okay. So how many of you saw this talk proposal at the PyCon website and asked yourself how could anyone propose a talk using the Python pretty print library? Only one? Few of you. It's exactly not what I'm going to talk about today. There's one slot which I didn't want, the one before lunch because I know I'm going to be the one standing between you and your lunch. Okay. So please bear with me while I explain all the concepts. So what's the motivation behind this? The motivation is to print this, the Batman Superman logo that you can wear on your shirt. It should be something that you can do at home. Do it yourself type of kids. It must be economical, something you use with free and open source software and hardware and perhaps with Python too. Okay. And you have to come up with an art and actually print the part. So it's going from an art design to actually going to the part. So how do you represent a 3D object? There's one standard called serial lithography. It's called STL file. So what it says is that you can represent, you can represent a face as 3 points. So if I take a circle, somewhat like a circle, if I draw a triangle, right, this is 3 points. This represents one facet. But what about this sector? How do I represent that? You again use triangles. Similarly here. What about this sector? Again, you break it up into triangles. So you can construct your face as a 3D model using a million triangles. Okay. That's the concept behind STL. So there is an STL file for the soup for the Batman Superman logo. Okay. And just download that. And then you need hardware manufacturing 101. This is a 3D printer. We use a Prusa I3 model. This is called the extruder. You have the x-axis, the y-axis and the z-axis. This is the bed. The bed has a temperature. The extruder has a temperature. And you have the filament on top. So the filament that we use is PLA. I think it's called some polyelactic acid or something. So this is the ideal setup. In reality, this is how it looks. So this is custom assembled, bought in India, made in India. We assembled this printer. We control it using an Arduino 2560. We have ultrasonic sensors here. I think the HR, HCE SR04. So we have three sensors for the x, y and z-axis. And from the Arduino, we control it using the PC here. So these parts that you see here, the green ones here, the one that's holding the filament, that was printed using the 3D printer. So you actually print a 3D printer using a 3D printer. How cool is that? There's an analogy in software. Who compiles a compiler? A compiler, of course. Who compiles that compiler? A compiler? A compiler that compiles a compiler that compiles a compiler? Of course not. It's called a bootstrapping process. So you can get these parts in India, you can get this model, you can assemble it. Once you have the printer ready and connected, you can't just give the STL file directly to it. It doesn't understand. You write high level Python language. The machine doesn't understand that. You have to convert it into machine instructions. Similarly, you convert the STL file into G codes. This is how it looks. It's called a G programming language. A set of codes which are sent through the Arduino to the printer and the printer executes these G codes. So some initialization and you have setting the extruder off, setting the bed temperatures. The most important one is G1. This says move the extruder to point x, y and z. This is a feed rate. Feed rate says how fast the extruder should actually move. So you have like thousands of lines of G codes that are read by a printer. So there are software that you can use, Python software. This suite is called print run. It has got three main components. One is called printer phase. The other one is called PR on sole. The other one is called print core. I'm just going to quickly show you printer phase. So here you have settings to connect to your Arduino, port, everything. But the first thing you need to do is convert the STL file into G code. So you go to slicing settings. It's not a fancy UI. It needs some, it needs a lot of work. This is called Skyne Forge. It's also written in Python. The last release was 2012. So, but it works. It's not usable, but it works. So I click here on Skyne Forge here. It opens up this interface. I just opened the scaled one here. And it will basically load the STL file and convert it into G code. So you have the parts, how the extruder should actually move. You can do all sort of customizations here. A lot of options that you can play around with. I'm just going to move to the next slide. I'll also show you PR on sole. So since I'm not kind of to the printer, it says offline, but there are a lot of help commands. So from this prompt itself, you can actually issue commands. You can load the G code files. You can say, you can say print. You can print from SD card. You can monitor the printing. Everything you can do from the UI can be done using this PR on sole. The print core is a library which you can use to build your own applications for printing. So you currently have 3D printer. The next step is before you start printing, the extruder and the bed has to be in the right temperatures. So there was an initial testing that we did for the PLF element. And we found out that the extruder temperature should be around 170 degrees Celsius. The bed temperature should be around 55 degrees Celsius for a good print. So then you start heating. You give commands to setting the bed temperature and extruder temperature. It warms up and printer is ready. But the printer has to be in the right position to start. So let's say the podium is the zero, zero, zero position and the extruder. So you say homing X must goes to zero, goes to zero, Y must go to zero and Z is zero. Then you give the print command. So homing step takes care of the extruder position in three dimensional space. Now our interest is also to analyze how the printer is actually performing. So there is this MQGT queues. MQGT was initially an IBM product, IBM MQ series product for queuing for machine to machine communication. So there is one implementation, one implementation called mosquito, which we use in the system that we have. So it is a publisher, subscriber, broker, architecture. So you have a client which can send messages to a broker, a subscriber subscribes to a topic. So what we call as channels, channels of data, they are known as topics. So this subscriber subscribes to a topic to the broker, the publisher will publish a data to the topic and the subscriber will receive the topic. It's a simple client server architecture, but it goes through a broker. Traditionally, the manufacturing industry has been a proprietary industry. You have proprietary hardware, proprietary software, proprietary protocols. It's extremely, extremely difficult to extract data from these machines. Some of them are like millions of US dollars. They work so much and the computer control numerical machines will run on Windows 95, Windows 98. And so there is this MQGT standard which was designed in UC Berkeley so that there is some standard means by which we can extract the data from these machines. So traditionally you have a machine, you have a custom adapter that reads the temperatures, the XYZ position values, and then it goes to an agent which will collect snapshot, time snapshots of the machine states and you can actually see in the computer. So you can have a single agent and multiple adapters for multiple machines on the job floor. So you can have machines with like 200 machines in a plant. So empty connect plus the free standard, you can just download it. So how do we map empty connect to our 3D printer? So we have these channel topics. So there's one called availability. Here is a path for bed temperature, extra temperature, X, Y, and Z values. The general suggestion is not to have such long topic names, but since the empty connect standard is pretty huge, you can have as many as 400 variables reading from the machining process. So from the print run suite, we start printing, we get the data and we push it. It goes to the adapter. The adapter basically subscribes to the messages in the MQGT queue and it converts into an SHDR format, a simple header format which has a timestamp, the value of that variable, the variable and its value, variable name and its value. So you have a series of these coming from the machine, right? And then you have the agent. So for a particular device, how would we define the empty connect XML file? So I'm giving a very simple example. So the empty connect standard for every device or machine, we have its meta information, right? So here I'm just giving one example of availability and the bed temperature. So this is the template. Every time the agent spits out an XML, you will get the actual values. I'll give you a demo on that. So let me first start the agent. So the agent runs, it waits to connect to an adapter that is supposed to give machining information. So it is a simple MQGT empty connect Python adapter here. There is a ping pong protocol between the adapter and the agent. So it connects and it keeps checking every 10 seconds if the data is coming or not. So since I don't have the printer here, I'm going to just feed in some values to the MQGT queue. So from the queue, it's picked up by the adapter. The adapter goes to the agent and then you can see the output from the agent. So the agent is running on port 5000, so I just do a curl, local host, colon 5000 slash current. Every time it will give me a different temperature value, the one that it reads from the queue. So here, first value, it goes to the adapter and then this is the bed temperature that keeps varying. So the agent provides a means by which you can get instantaneous values of the XYZ positions of the printer at any point in time. So now we have the data from the printer. You give it to a web server that keeps pulling the agent for data, put it in a database, you can do your analytics there. This is standard stuff. So there are a number of Python visualization tools that you can use to analyze. There are three things that I really want to understand. The first thing is, what is it that I want to print? That's the sql file. The second thing is, what did the printer say it actually printed? And the third thing is from the printed object is that what I actually expected. So this is yet another gcode viewer. It's using the Python Piglet library that for you here. So it basically goes to all the gcodes and it tells you like how exactly does the print process happen. So you can do all sort of rotation here. What you see here is this called a brim. Before we actually start printing the object, this is called a brim. This is printed for some time before we actually start printing it because we want to make sure that the filament flow is smooth. Sometimes we stick tape on the bed. So the first layer actually sticks and then you start printing. So this is called additive manufacturing because you're going printing layer 0, layer 1, layer 2, layer 3 and so on. So this is a brim to use just to make sure that print is good. The other tool that we have is Blender of course. Let me open Blender. There is this Blender gcode plugin. The author is one Simon. He told me that he wrote this in a weekend. So it needs some work to be done. Blender has a nice Python interface. It's import bpy. You basically use the whole engine for your work. So I'm just going to delete this object. File, import, this gcode plugin, print, data. This is how it looks in Blender. So what this algorithm does is like when the extruder actually makes a turn, he converts that movement into an arc. So you see those smooth arcs here. Now this is from the gcode. So the ultrasonic sensors on the printer, the read x, y, z positions, those are diffs. So if x says x value will go from plus 2, plus 3, minus 2, plus 3 and so on. Those are delta changes. Before we actually write to the MPTQ, we will make it into absolute values. So when you start the homing, you start the reference point as 0, 0, 0. Any value of x, y, z that changes there afterwards will be computed accordingly. So we know the gcodes. We can import the stl file on Blender. So we know what we want to print. From the x, y, z values, we can reconstruct, see what the printer actually printed for comparing with what the stl file is supposed to actually, what the stl file actually says. Now of course these ultrasonic sensors are not very expensive, pretty affordable, you can buy it and use it. But we want to be able to see how the printed object actually is, right? Does it actually match with the gcodes and the stl file? So we have to go from the part to the art. So there are a couple of techniques here. One is there is this research lab in Italy, some university, they have this mesh lab software. So you take the object, let me take an example. So you take an object and you take a picture of it 360 degrees. Then you take from the top, side or bottom if possible and then you give it to this mesh lab software. So what it does is, it analyzes all the pictures, it tries to create a mesh point cloud which you can export to stl file and you can import it into Blender. That needs to be compared with the original stl file that you used for the print. So we are still working on this. It is not complete. We use digital cameras initially, but we are not able to actually get the mesh point cloud. We are resolutions were not good or settings were not proper. So we are still working on that. Some people suggest to use SLR cameras and then you make a rotating table and you keep rotating at every n degrees. You keep clicking pictures on that. That is one technique that you can use, but this is not completed yet. The other technique is software called pilot scan. What you do is, again you have a rotating table and you place the object on top. Then you have two lasers either side. The hit on the object and you keep rotating the object and you have a camera that takes pictures from the laser points. That again you give it to mesh lab and that it will create the mesh point cloud, export to stl and you can read it. So we have not come to this point yet, but the software is available. The RepRap 3D printer, the Arduino code, we use the Mendel model and the Merlin firmware. All the source code is available. Pilot scan also source code is all available online. You can just take it and try it out. But the hardware part you have to construct. So why do we need an adapter and agent? Traditionally that is how it is being, using the empty carrying standard, but you are not limited to that. Use the Python PAHO library, which you can use to read from MPTT and directly dump it to database and you can do your analytics on top of that. So you are not limited to that, but you have to do all the computation of the instantaneous values in the server side. Traditionally we deploy the adapter and the agent in the job floor where the actual machine exists. All this is done on the server side. But since the 3D printer and you are doing it at home, it is fine. Some credits I need to give. Clement is the author for Printrun. He hangs on the hash RepRap IRC channel. He can talk to him. He has been quite helpful in giving me some suggestions on how Printrun software has to be modified to do this. The traditional approach for Printrun is they are not interested in the XYZ values. They are more than happy to see the progress of the print and the extruder and bed temperature values. But I wanted something more. So she was able to give me some ideas and pointers on that. Ideas Manfoil 2 and Lucas T both are there on hash Blender Python. They are quite active. They are quite helpful. They also help me with some mat.lib stuff. So you can always ask them on that. We have two interns from IIT Madras, Roshan and Rohan. They did the initial hardware setup, the bootstrapping process, assembled the printer. Their experiments was on finding the best temperature for the filament for a good quality print. So they used to print cubes. So they start with the brim and then they start printing the cube layer by layer by layer. As they go higher, they lower the temperature of the extruder. Once the cube has been printed, then we use your vernier scale and images and compare how the texture is, what the quality of the print is. So they did a lot of the initial work. Rohan is still interning with us. We want to see more about how we can do transition manufacturing for the 3D printers. So also credits to Will. He is part of the MT-Connect standard. He is also the author of the CPP agent code which is written in C++. It's still free software. You can download it and you can play with it. Pal who is working with me on trying to go from the part to the art phase to see how you can validate the printed part. There are some references. There is a lot more. The MQTT.org site has the standards, another documentation. HiveMQ has got nice block series on how you should set up your machine-to-machine queues about security practices. They have good enterprise queues, implementations that you can use. Mosquito is a free open source server that we use for the MQTT queue. You can just install that in Ubuntu or Debian, and get installed. MT-Connect standard Thingiverse has got a lot of STL files that you can play around with. Printrun, software in GitHub. Skyinforge is old. It's usable. Right now Printrun has an option by which you can select which slicer you want to pick. Right now they default to using slicer number 3. It's actually C++ and has got pull bindings. It's something that you can start with writing Python bindings for. But you can choose which slicer you want to convert from STL to G-Codes. RepRap has got all the hardware information and the software that you need to build the printer. Altini, of course, is yet another G-Code viewer and Blender sites. There's a lot more. I'll put it up in the slide deck. Okay. So, to quickly recap, how do you go from R to part? You take an STL file, the CAD model, convert that into G-Codes, give it to a 3D printer, get the printer statistics into the queue, get int, use the adapter to collect the data, move to the agent, use the server to pull the agent, get the data, move to database, and then you can use it for analytics or UI. You can also directly take it from the queue and push it to the database. And that's how you pretty print in Python. Okay. So, just before I conclude, let me see if I can open cheese and show you the actual part. Anybody who knows the Batman theme song? That's the part. So, if you actually take a closer look at it, I don't know if you can see it here. You can see some slight texture. The scam is not very clear here. You can see the grain lines on the print. So, but it actually works. You can actually print stuff. The other things I can, I have a cube also. You can have a look at it offline. You can take it. But I'm open to take questions now. Thank you. The lightning talk participants, I request you all to kindly come and see it in this first row. If anyone is sitting back or something. Good afternoon. Please read. Agree? Here we go. Jack and Jill went up to the server to run the test with Marker. Jack pushed code and broke his test. And Jill never spoke to him thereafter. Tester, have you any bugs? Yes, sir. Yes, sir. Three code dumps. One for my master scrum. One for my lead. One for my manager who's a friend indeed. Not anymore. Humpty dumpty. Sad to debug. Humpty dumpty squashed a bug. All the team members and stakeholders gave Humpty a big tight hug. Goosey goosey coder. Where shall I wander? GitHub or Bitbucket. Decide on something sooner. Clone a project folder. Code to make it better. See collaboration working closer. And I shall be an eye opener. Code, code, code your way. Gently down the screen. Come it early. Come it often. And life is but a dream. See my little hands go hack, hack, hack. And my little tests run back to back. I just have one word to say to you. Come learn Python and say I'm happy for you. Project issues in the way, in the way, in the way. Project issues in the way, my fair user. Fixing bugs right away, right away, right away. Fixing bugs right away, my fair user. Modging PRs as I say, as I say, as I say. Modging PRs as I say, my fair user. All the tests are passing, hey, passing, hey, passing, hey. All the tests are passing, hey, my fair user. As a client you should pay, you should pay, you should pay. As a client you should pay, my fair user. Python really saved the day, saved the day, saved the day. Python really saved the day, my fair user. Thank you. Thank you, Shakti so much. At Shaktimaan, there's a Twitter handle. Because of some reasons, we are rescheduling Shivam's talk at the last. So now we have Ankur import Python.