diff --git a/tutorial/03_building_engines/03_Buliding_Engines_01_Single_Cylinder.md b/tutorial/03_building_engines/03_Buliding_Engines_01_Single_Cylinder.md new file mode 100644 index 0000000..d5ebda7 --- /dev/null +++ b/tutorial/03_building_engines/03_Buliding_Engines_01_Single_Cylinder.md @@ -0,0 +1,37 @@ +# WIP + +## 01 - single cylinder engine + +#### Intoduction + +In this tutorial you will learn how to make a simple single cylinder engine completly from scratch. + +When you're actually making engines, it's generally preferable to simply modify other engines (LTSP created by Archangel Motors is a good example of engine templates made to be modified by users), however I belive it's important to understand the syntax of Piranha to be decent at making ES engines. Due to that this tutorial will cover every step necessary to get a simple 1 cylinder engine running in Engine Simulator. + +In further tutorials you'll learn how to add other fetures, such as more cylinders, the vehicle model, and much more. + +#### Creating the file + +Engine Simulator engines are saved in a special file with the extention of .mr. We need to have that file to actually have a place to write code in, so let's make one. + +Firstly you need to be able to edit file extentions, for that we need to see these extentions, so let's enable that. + +In file explorer go into the view tab: + +![alt text](assets/file_explorer_file_extentions.png) + +In that tab you want to make sure "File name extentions" is checked + +![](assets/file_explorer_checkboxes.png) + +Once you have that, you want to create a text file by right clicking in the destination folder, and navigating to new -> text document + +Then right click on the file, click rename, and change the last three letters (.txt) to .mr + +#### Getting an editor + +Now that we have the file, we need to be able to edit it. Technically it's possible to edit .mr files in the Windows notepad, however it's preferable to use an actual editor. Visual Studio Code is recomended, as it has syntax highlight for Piranha. + +To install VS Code, you'll want to download the installer from [this webside](https://code.visualstudio.com/) + +Once you have that installed, you also want to download the Piranha extention from [here](https://marketplace.visualstudio.com/items?itemName=EktoromSoftwareInc.piranha-extension) diff --git a/tutorial/03_building_engines/03_building_engines.md b/tutorial/03_building_engines/03_building_engines.md deleted file mode 100644 index e876a7f..0000000 --- a/tutorial/03_building_engines/03_building_engines.md +++ /dev/null @@ -1,149 +0,0 @@ -# Build Your Own Engine From Scratch - -## WARNING: This tutorial is currently under development and not yet complete! - -This tutorial will teach you how to build an engine from scratch using *Engine Simulator's* scripting interface. - -## Prerequisites -### 1. Download and Install VS Code -If you don't already have VS Code installed, you can do so [here](https://code.visualstudio.com/download). You could use any text editor for this but VS Code is recommended if you want syntax highlighting. - -### 2. Install the Piranha Syntax Highlighting Plugin -Open VS Code and click on "View" then "Extensions". In the search bar, search for "Piranha". - -![Alt text](assets/screenshot_01.PNG?raw=true) - -Click on the search result and install the extension. - -![Alt text](assets/screenshot_02.PNG?raw=true) - -Once the extension is installed, `.mr` files should be colored in VS Code. - -![Alt text](assets/screenshot_03.PNG?raw=true) - -## 1 - Setting up the Script -1. Create a new file called `tutorial-engine.mr`. It can be called whatever you want, however the `.mr` extension must be present -2. Open the file in VS Code (or the text editor of your choice) -3. The first step is to include the following line at the top of the file, which will import everything needed from the *Engine Simulator* library. - -``` -import "engine_sim.mr" -``` - -4. Next we need to define an engine. To make organization a bit easier, we will create this engine inside a *node*. A node is a logical unit of code within the Piranha programming language. This can be done with the following code: - -``` -public node my_engine { - alias output __out: engine; - - engine engine( - name: "My Engine" - ) -} -``` - -Line by line, this is what the code does: -- Line 1 - creates a new node type called `my_engine` -- Line 2 - the main output of this node is going to be the engine node defined below -- Line 3 - empty -- Line 4 - create an `engine` node. This is a node-type that is built into *Engine Simulator* and signifies a common piston engine -- Line 5 - the name of the engine -- Line 6 - closing bracket -- Line 7 - closing brace - -5. Tell *Engine Simulator* that this is the engine we want to simulate. To do this, add the following code at the bottom of the file: - -``` -run( - engine: my_engine() -) -``` - -The full script should look like this at this point: - -``` -import "engine_sim.mr" - -public node my_engine { - alias output __out: engine; - - engine engine( - name: "My Engine" - ) -} - -run( - engine: my_engine() -) -``` - -6. Let's try running this script now by pressing the "Load Script" button in *Engine Simulator*. - -You should see this in the console: -![Alt text](assets/screenshot_04.PNG?raw=true) - -Our script compiled successfully but *Engine Simulator* correctly pointed out that our engine does not have any crankshafts and is therefore invalid. Everything looks fine so far, we just need to continue building our engine. - -## 2 - Creating a Crankshaft - -1. Specifying engine measurements is much easier with standard units. To use units, add the following line before line 3: - -``` -units units() -``` - -2. Next it'll help with our code organization to specify a list of engine parameters. To do that, add the following code before line 9: - -``` -// Engine parameters -label stroke(86.0 * units.mm) -``` - -The `label` node is simply a way to give a name to a value. In this case, we are saving the value of 86 mm in a node called `stroke` for use later. - -2. Now, it's time to create the crankshaft. The two most important parameters that define the crankshaft are the `throw` and `tdc` position. TDC stands for top-dead-center which is the point at which the piston is at the top of the compression stroke. We'll discuss how this is set in more detail later. Add the following code after the `engine` node: - -``` -crankshaft crankshaft( - throw: stroke / 2, - tdc: 90 * units.deg -) -``` - -This code creates a new crankshaft object called `crankshaft` with a *throw* of the engine's stroke divided by 2 and `tdc` point of 90 degrees. A crankshaft's "throw" is the distance between the center of the crankshaft to the center of it's rod journals (also called crank-pins). - -3. The final step is to add the new crankshaft to the engine using the following code placed underneath the `crankshaft` code earlier: - -``` -engine.add_crankshaft(crankshaft) -``` - -By this point, the entire script should look like this: - -``` -import "engine_sim.mr" - -units units() - -public node my_engine { - alias output __out: engine; - - // Engine parameters - label stroke(86.0 * units.mm) - - engine engine( - name: "My Engine" - ) - - crankshaft crankshaft( - throw: stroke / 2, - tdc: 90 * units.deg - ) - - engine.add_crankshaft(crankshaft) -} - -run( - engine: my_engine() -) -``` diff --git a/tutorial/03_building_engines/assets/file_explorer_checkboxes.png b/tutorial/03_building_engines/assets/file_explorer_checkboxes.png new file mode 100644 index 0000000..4445dc7 Binary files /dev/null and b/tutorial/03_building_engines/assets/file_explorer_checkboxes.png differ diff --git a/tutorial/03_building_engines/assets/file_explorer_file_extentions.png b/tutorial/03_building_engines/assets/file_explorer_file_extentions.png new file mode 100644 index 0000000..1f2d9bd Binary files /dev/null and b/tutorial/03_building_engines/assets/file_explorer_file_extentions.png differ diff --git a/tutorial/03_building_engines/assets/screenshot_01.PNG b/tutorial/03_building_engines/assets/screenshot_01.PNG deleted file mode 100644 index 954c498..0000000 Binary files a/tutorial/03_building_engines/assets/screenshot_01.PNG and /dev/null differ diff --git a/tutorial/03_building_engines/assets/screenshot_02.PNG b/tutorial/03_building_engines/assets/screenshot_02.PNG deleted file mode 100644 index 123be4f..0000000 Binary files a/tutorial/03_building_engines/assets/screenshot_02.PNG and /dev/null differ diff --git a/tutorial/03_building_engines/assets/screenshot_03.PNG b/tutorial/03_building_engines/assets/screenshot_03.PNG deleted file mode 100644 index 421b754..0000000 Binary files a/tutorial/03_building_engines/assets/screenshot_03.PNG and /dev/null differ diff --git a/tutorial/03_building_engines/assets/screenshot_04.PNG b/tutorial/03_building_engines/assets/screenshot_04.PNG deleted file mode 100644 index b7dfb6f..0000000 Binary files a/tutorial/03_building_engines/assets/screenshot_04.PNG and /dev/null differ diff --git a/tutorial/03_building_engines/assets/screenshot_05.PNG b/tutorial/03_building_engines/assets/screenshot_05.PNG deleted file mode 100644 index edc4ca6..0000000 Binary files a/tutorial/03_building_engines/assets/screenshot_05.PNG and /dev/null differ