The Petri Task File is PetriTask class of serialized form. This file contains all necessary information of the model. In this tutorial we show how you can create a new model file by using the gCodeAPI.NET and the C# language. This new model is a simple circle which is localized in the center of petri dish. We also define an approaching and leaving printer path to the model.
Before we start the practical implementation of PetriTask class let’s see its structure. The PetriTask class contains three properties.
The PetriTask class has a public Print function. This function is called by the PetriPrinter program and provides the dynamic repositioning according to the position of the current petri dish. This means that there is no need to set different printing positions. Just set the center of your model into the origin of XYZ coordinates and your model will always be shifted in the necessary position.
1. First, you need the Visual Studio which is a IDE from Microsoft. Please visit the Visual Studio website.
2. Make a new Visual C# Console Application.
3. Add the dll of gCodeAPI.NET into the references. Click the Project menu and select the select the Add reference... item. Select the Browse tab then click the Browse... button. Select the GCodeAPI.dll
4. Add the using GCodeAPI; line top of the Program.cs file;
5. Create a new PetriTask class into the Main function of Program.cs file. Set the name (first argument) and the description (second argument) of the model.
1 2 | var task = new PetriTask( "SimpleCircle" , "This is a simple circle. (Diameter: 6 mm; Height: 1.8 mm)" ); |
6. Define the important parameters and get GCodeCollector of our PetriTask object.
1 2 3 4 5 6 | double radius = 3.0d; //radius of circle double stepZ = 0.2d; //distance between two layers int maxZ = 9; //number of layers double zOff = 0d; // current Z offset. GCodeCollector code = task.Code; |
7. Set the exctruding rate. This is a static constant which helps you calculate the necessary amount of extruded material. It depends on your printer and the requested wall thickness. In our setup (Ultimaker Original with 0.4 mm nozzle) this constant value is 0.0405. You may have to try various values before you find the perfect settings.
1 2 | GCodeSpecial.ExtrudeRatio = 0.0405d; |
8. First, you have to define the place of printer nozzle landing. It is practical to select an outside place to prevent the damage of cell culture area. Define a new GLine object 10 millimeters left from the center of dish.
1 2 | code.addCode( new GCodeLine(x: -10d, y: 0d, speed: 9000d, mode: GCodeLine.SpeedModes.Fast)); |
9. Set printer nozzle to the bottom of petri dish.
1 2 | code.addCode( new GCodeLine(z: 0d, speed: 9000d, mode: GCodeLine.SpeedModes.Fast)); |
10. The circle path is defined by using a line (diameter). The start point of the line is the current position of printer head. Send the printer nozzle to the edge of circle.
1 2 | code.addCode( new GCodeLine(z: -radius, speed: 9000d, mode: GCodeLine.SpeedModes.Fast)); |
11. The second point is defined by angle with horizontal axis and length of line (2x radius). Set the angle (in degree) and radius into the getCircleByRadius() function.
1 2 3 4 5 6 | code.addCode(GCodeCircle.getCircleByRadius( speed: 500, axisAngle: 0, radius: radius, extrude: GCodeSpecial.ExtrudeCircle(radius))); |
12. Embed the circle maker line into a for loop and add a Z distance incrementing line.
1 2 3 4 5 6 7 8 9 10 11 12 13 | for ( int z = 0; z < maxZ; z++) { code.addCode(GCodeCircle.getCircleByRadius( speed: 500, axisAngle: 0, radius: radius, extrude: GCodeSpecial.ExtrudeCircle(radius))); zOff += stepZ; code.addCode( new GCodeLine(z: zOff, mode: GCodeLine.SpeedModes.Slow)); } |
13. Save the PetriTask object into a file.
1 2 | task.Save( @"C:\R1D6.ptf" ); |
14. See the hole Program.cs file below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | using GCodeAPI; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PetriTaskFileTutorial { class Program { static void Main( string [] args) { var task = new PetriTask( "R1-D6" , "Single ring (Diameter: 6 mm; Height: 1.8 mm)" ); double radius = 3.0d; //radius of circle double stepZ = 0.2d; //distance between two layers int maxZ = 9; //number of layers double zOff = 0d; // current Z offset. GCodeCollector code = task.Code; for ( int z = 0; z < maxZ; z++) { code.addCode(GCodeCircle.getCircleByRadius( speed: 500, axisAngle: 0, radius: radius, extrude: GCodeSpecial.ExtrudeCircle(radius))); zOff += stepZ; code.addCode( new GCodeLine(z: zOff, mode: GCodeLine.SpeedModes.Slow)); } task.Save( @"C:\\R1D6.ptf" ); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | using GCodeAPI; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PetriTaskFileTutorial { class Program { static void Main( string [] args) { var task = new PetriTask( "R3-D6" , "This is the basic thee ring model. Perimeter: 6 mm; Height: 1.6 mm;" ); double circleSpeed = 300d; // First layers speed; double circleSpeedFast = 500d; // Upper layers speed; double centerX = 0; // X position of model (mm) double centerY = 0; // Y position of model (mm) double zOff = 0; // Z position of model (mm) double radius = 3.5; // Radius of rings. double r2 = 10d; // Radius of cleaner circle, aid to even PLA flow double extLine = 2; // Distance between the center and circles int layers = 18; // Number of layers double zStep = 0.2; // Distance between two layers GCodeCollector code = task.Code; // Put down the head into the petri dish code.addCode( new GCodeLine(x: centerX - r2, y: centerY, speed: 9000, mode: GCodeLine.SpeedModes.Fast)); code.addCode( new GCodeLine(speed: 4000, extrude: -3, mode: GCodeLine.SpeedModes.Fast)); code.addCode( new GCodeLine(z: zOff, speed: 9000, mode: GCodeLine.SpeedModes.Fast)); code.addCode( new GCodeLine(speed: 4000, extrude: 3.5, mode: GCodeLine.SpeedModes.Fast)); //Save and change the global extrude ratio. double extrudeDefault = GCodeSpecial.ExtrudeRatio; GCodeSpecial.ExtrudeRatio = 0.02025; // Printer and model specific value for (var i = 0; i < layers; i++) { // Turn off the cooler after the first layer. if (i == 1) code.addCode(GCodeSpecial.FanOn(255)); // Increase the printer speed after the second layer. if (i > 2) circleSpeed = circleSpeedFast; // Print the cleaner circle if (i == 0) { code.addCode( new GCodeLine(x: centerX - r2, y: centerY, speed: 1200, mode: GCodeLine.SpeedModes.Slow)); code.addCode(GCodeCircle.getCircleByRadius( speed: circleSpeed, axisAngle: 0, radius: r2, extrude: GCodeSpecial.ExtrudeCircle(r2))); } // Print first ring code.addCode( new GCodeLine(x: centerX, y: centerY, speed: 1200, mode: GCodeLine.SpeedModes.Slow)); code.addCode( new GCodeLine(x: centerX + extLine, y: centerY, speed: 1200, mode: GCodeLine.SpeedModes.Slow)); code.addCode(GCodeCircle.getCircleByRadius( speed: circleSpeed, axisAngle: 0, radius: radius, extrude: GCodeSpecial.ExtrudeCircle(radius))); // Print second ring var p = Point.PolarToCartesian(extLine, 120); code.addCode( new GCodeLine(x: centerX, y: centerY, speed: 1200, mode: GCodeLine.SpeedModes.Slow)); code.addCode( new GCodeLine(x: p.X, y: p.Y, speed: 1200, mode: GCodeLine.SpeedModes.Slow)); code.addCode(GCodeCircle.getCircleByRadius( speed: circleSpeed, axisAngle: 120, radius: radius, extrude: GCodeSpecial.ExtrudeCircle(radius))); // Print third ring p = Point.PolarToCartesian(extLine, -120); code.addCode( new GCodeLine(x: centerX, y: centerY, speed: 1200, mode: GCodeLine.SpeedModes.Slow)); code.addCode( new GCodeLine(x: p.X, y: p.Y, speed: 1200, mode: GCodeLine.SpeedModes.Slow)); code.addCode(GCodeCircle.getCircleByRadius( speed: circleSpeed, axisAngle: -120, radius: radius, extrude: GCodeSpecial.ExtrudeCircle(radius))); // Increase Z positon zOff += zStep; // Step up printer head code.addCode( new GCodeLine(x: centerX, y: centerY, speed: 1200, mode: GCodeLine.SpeedModes.Slow)); code.addCode( new GCodeLine(speed: 9000, extrude: -0.2, mode: GCodeLine.SpeedModes.Fast)); code.addCode( new GCodeLine(z: zOff, mode: GCodeLine.SpeedModes.Slow)); } // Go to the exit point of petri dish code.addCode( new GCodeLine(x: centerX - r2, y: centerY, extrude: -2.5, speed: 9000, mode: GCodeLine.SpeedModes.Fast)); // Turn of cooler code.addCode(GCodeSpecial.FanOff()); //Restore the original global extrude ratio GCodeSpecial.ExtrudeRatio = extrudeDefault; return task; } } } |