Category Archives: Programming

ScorchCAD Version .04

ScorchCAD_444

After a summer break from ScorchCAD development I am back at it.  The latest version of ScorchCAD is available on Google Play.  ScorchCAD is also now available on the Amazon App Store.

Here are the highlights of the new features:

  • Hull
  • Multmatrix
  • 2D shapes (circle, square, polygon)
  • 2D boolean operations
  • Resize
  • Intersection_for
  • Nested for loops (i.e. for(i=[1:5],j=[1:5]) )
  • Polyhedron
  • norm
  • cross
  • min
  • max

Additionally there are some usability changes.  ScorchCAD will now backup the current data in the code editor when the compile button is pressed.  This data is reloaded when a new session of ScorchCAD is started.  This will allow for data recovery in the event of a crash.  Additionally ScorchCAD is now associated with *.scad, *.stl, and *.dxf file extensions.  So from a file manager you can click on one of these files and ScorchCAD will show up in the available programs to open the file.  File associativity also works for *.scad files in e-mail attachments.

 

A Much Faster F-Engrave (V1.40)

F-Engrave

The latest version of F-Engrave includes major improvements to the v-carve calculation speed.  The first is based on input from geo01005.  He shared his work on his BLOG and in this YouTube Video.  The added code that breaks up the design area into a grid and stores the grid locations that are within the tool diameter.  The v-carve algorithm uses this data to skip over line segments that are farther than the max tool diameter from the current line segment.  F-Engrave had previously skipped some segments but geo01005’s implementation was significantly (2 to 3 times) faster.

In addition to the code changes geo01005 also showed that using Psyco with F-Engrave was of great benefit.  Psyco is no longer supported and is not compatible with the latest (or most commonly used) Python distributions.  However, the speed improvements were significant enough (3 to 4 times faster) to convince me to downgrade to Python 2.5 for the windows executable distribution.  I am sticking with Psyco rather than another JIT compiler (pypy, Jython, IronPython, etc.) because Psyco is easy to implement and compatible with Py2exe.  I use Py2exe to generate the windows executable files.

The final speed improvement, which is turning off plotting, has been available for some time in F-Engrave.  I have not pushed the use of this feature because the savings has only been a small percentage of the total v-carve time (depending on the design).   With the other improvements included in V1.40 plotting has become a significant player in the total calculation time.   Now turning off plotting can make the v-carve calculation 2 to 3 times faster (or significantly more depending on the design).  I have added a check button to the calculation window so the plotting can be turned on/off, on the fly, during the v-carve calculation.

So if you are paying close attention you can see that all of these increases in speed build on each other (multiply not add) and result in a v-carve calculation 12 to 36 times faster than in the previous versions of F-Engrave.

I have also been digging into the code and fixing various minor bugs and adding some features to make aligning multiple v-carve files easier.  Here are the highlights of the other changes:

  • Changed Default Origin behavior (for DXF/Image files) to be the origin of the DXF file or lower left corner of the input image. (“Bot-Left” still provides the same functionality of the old “Default” setting)
  • Added automatic scaling of all linear dimensions values when changing between units (in/mm)
  • Fixed bug in clean up function in the v-carve menu. (the bug resulted in excessive Z motions in some cases)
  • Fixed bug resulting in the last step of v-carving for any given loop to be skipped/incorrect.

ScorchCad Preview (Update 1)

ScorchCAD Demo ScorchCAD Snowman ScorchCAD Lego

This is a quick update of my progress on ScorchCAD (A clone of OpenSCAD for Android devices).  I am slowly adding features.  So far I these are the items that are working:

  • Basic shapes (cube, sphere and cylinder)
  • Basic boolean operations
  • Colors
  • OpenSCAD file opening and saving using file dialogs
  • Support for variables is partially complete (I need to make set at compile time as are in OpenSCAD)

The pictures above are small models that I made using ScorchCAD while I was waiting for my kids hockey games to start.

Simple File Dialog For Android Applications

Since there isn’t a built in file dialog interface for android development I have been searching for one that I could use without starting from scratch. I did eventually find a Simple Directory Chooser with a very lenient license (The Code Project Open License (CPOL) 1.02). The directory chooser I found uses a dialog interface so there is no need to create an additional activity to use it.

The directory chooser was great but I needed a file dialog for choosing files for opening and saving not a directory chooser. To get the file dialog I needed I modified the original directory chooser adding to it as needed to create a Simple File Dialog for my own use. I thought I would post my modified version here for others to use or build on.

The file dialog code consists of a single file and uses standard Android resources. This file dialog code should be very portable and easily inserted into any project to add menu driven file selection within Android.  Screen shots of the three file dialog modes (Open, Save, and Folder Select) are shown below. The “Save” and “Folder Select” modes include a button for adding a new folder to the file structure.

Open Dialog save folder

The code can be downloaded here: SimpleFileDialog.java and MainActivity.java

Bare Bones Application Using the Simple File Dialog

This is a very bare bones application with three buttons that call the Simple File Dialog in all three modes (Save, Open and Folder Select). To make this application I just started a new Android Application Project in Eclipse. Edited the Layout to add three buttons and edited the MainActivity.java file. The finished MainActivity.java file is shown below.

Demo Screen

//MainActivity.java
package com.scorchworks.demo;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;

import android.widget.Button;
import android.view.View.OnClickListener;
import android.widget.Toast;

//import android.view.View;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		//Button1
		Button dirChooserButton1 = (Button) findViewById(R.id.button1);
		dirChooserButton1.setOnClickListener(new OnClickListener() 
		{
			String m_chosen;
			@Override
			public void onClick(View v) {
				/////////////////////////////////////////////////////////////////////////////////////////////////
				//Create FileOpenDialog and register a callback
				/////////////////////////////////////////////////////////////////////////////////////////////////
				SimpleFileDialog FileOpenDialog =  new SimpleFileDialog(MainActivity.this, "FileOpen",
						new SimpleFileDialog.SimpleFileDialogListener()
				{
					@Override
					public void onChosenDir(String chosenDir) 
					{
						// The code in this function will be executed when the dialog OK button is pushed 
						m_chosen = chosenDir;
						Toast.makeText(MainActivity.this, "Chosen FileOpenDialog File: " + 
								m_chosen, Toast.LENGTH_LONG).show();
					}
				});

				//You can change the default filename using the public variable "Default_File_Name"
				FileOpenDialog.Default_File_Name = "";
				FileOpenDialog.chooseFile_or_Dir();

				/////////////////////////////////////////////////////////////////////////////////////////////////

			}
		});

		//Button2
		Button dirChooserButton2 = (Button) findViewById(R.id.button2);
		dirChooserButton2.setOnClickListener(new OnClickListener() 
		{
			String m_chosen;
			@Override
			public void onClick(View v) {
				/////////////////////////////////////////////////////////////////////////////////////////////////
				//Create FileSaveDialog and register a callback
				/////////////////////////////////////////////////////////////////////////////////////////////////
				SimpleFileDialog FileSaveDialog =  new SimpleFileDialog(MainActivity.this, "FileSave",
						new SimpleFileDialog.SimpleFileDialogListener()
				{
					@Override
					public void onChosenDir(String chosenDir) 
					{
						// The code in this function will be executed when the dialog OK button is pushed
						m_chosen = chosenDir;
						Toast.makeText(MainActivity.this, "Chosen FileOpenDialog File: " + 
								m_chosen, Toast.LENGTH_LONG).show();
					}
				});

				//You can change the default filename using the public variable "Default_File_Name"
				FileSaveDialog.Default_File_Name = "my_default.txt";
				FileSaveDialog.chooseFile_or_Dir();

				/////////////////////////////////////////////////////////////////////////////////////////////////

			}
		});

		//Button3
		Button dirChooserButton3 = (Button) findViewById(R.id.button3);
		dirChooserButton3.setOnClickListener(new OnClickListener() 
		{
			String m_chosen;
			@Override
			public void onClick(View v) {

				/////////////////////////////////////////////////////////////////////////////////////////////////
				//Create FileOpenDialog and register a callback
				/////////////////////////////////////////////////////////////////////////////////////////////////
				SimpleFileDialog FolderChooseDialog =  new SimpleFileDialog(MainActivity.this, "FolderChoose",
						new SimpleFileDialog.SimpleFileDialogListener()
				{
					@Override
					public void onChosenDir(String chosenDir) 
					{
						// The code in this function will be executed when the dialog OK button is pushed
						m_chosen = chosenDir;
						Toast.makeText(MainActivity.this, "Chosen FileOpenDialog File: " + 
								m_chosen, Toast.LENGTH_LONG).show();
					}
				});

				FolderChooseDialog.chooseFile_or_Dir();

				/////////////////////////////////////////////////////////////////////////////////////////////////

			}
		});

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
//

For the New Folder button to actually create a new folder in the demo you need to include the following line in the Manifest file to give the app permission to write to the SD Card.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

None of this code would have been possible without the jump start I got from the Simple Directory Chooser

Simon Hack a Day’ing

Simon
Hack a Day is having another contest.  This time it is a microcontroller based contest.  The entries need to hide hackaday.com in a microcontroller project as an Easter egg.  The extent of my experience with microcontrollers was soldering together at a Simon project at a Maker Faire a few years back.  I have been meaning to buy an FTDI board to program the Simon for a while now but never seemed to get around to it.  When the Hack a Day contest launched I decided now was the time to give it a shot.

A few days later with the FTDI in hand it was time to start creating my Easter egg.  I downloaded the original source code for the Simon (available on the Sparkfun web site) and started adding my own code to incorporate the Hack a Day URL.  What I came up with is a fully functional Simon game with a couple of minor twists.  The first change is that when Simon is playing the sequence of buttons for the player to repeat.  The sequence is played by Simon in an irregular pattern which is actually Morse code for “hackaday.com”.  When playing the game it is clear that the timing is a little off but it hard to tell it s Morse code because the tones change with the different colored buttons.  The video below shows the Simon playing with the modified program.

Game Play Video: Game Play Video Direct Link

Since I am not great at playing the Simon game I added another method to generate the full Morse code for “hackaday.com”.  Usually to start the Simon game the player needs to push one of the buttons to initiate the beginning of a new game.  I modified the program to detect if two buttons are pressed rather than one.  With the modified program when two buttons are pressed at the same time the Morse code it pulsed out prior to the game starting.  The video below shows the full Hack a Day URL being played by Simon.

Two Button Press Video: Two Button Press Video Direct Link

I have uploaded my modified code here: Simon_Game_Code_with_morse_code.ino. I included all of the letter codes in my look-up function so the Morse code message can easily be changed.  The length of the game is automatically adjusted to the length of the string entered in the egg array.

 

F-Engrave V1.32

F-Engrave

F-Engrave Version 1.32 is now available on the F-Engrave Web Page.  This release includes a few minor items that I have had backlogged for a while.  The items are listed below.

– Added limit to the length of the engraved text included in g-code file comment (to prevent error with long engraved text)

– Changed number of decimal places output when in mm mode to 3 (still 4 places for inches)

– Changed g-code format for G2/G3 arcs to center format arcs (generally preferred format)

-Hard coded G90 and G91.1 into g-code output to make sure the output will be interpreted correctly by g-code interpreters.

G-Code Wrapping with G-Code Ripper

wrap_g-code_pic

G-Code Ripper version 0.03 has been posted to the G-Code Ripper Homepage.  The new version has more plotting options including more isometric view angles.  The big addition in this version is the ability to map g-code from the X or Y axis to a rotary axis A or B.  This functionality is very similar to CNC wrapper.

G-Code Ripper: G-Code Wrapping Features

  • Graphical preview of the resulting g-code.
  • Automatically maps g-code arcs to linear movements prior to conversion to rotary moves.
  • Options for scaling feed rates to make them compatible with the rotary movements.
  • Interpret g-code variables and equations.
  • G-code Rippers basic features can also be used to scale and rotate the g-code before wrapping the code for the rotary axis.

G-Code Ripper Released

G-Code Ripper

I have uploaded the first version of G-Code Ripper (formerly referred to as the g-code splitting program).  G-Code Ripper can read g-code files and scale, rotate, translate and split the g-code data before writing back to another file.  On the G-code Ripper page I posted an example workflow showing one potential use for the software.  With the basic building blocks of reading and interpreting the g-code completed I will be thinking of new features to add to G-Code ripper.

Everything is new in this program so be careful and check the output.