Showing posts with label tinyg. Show all posts
Showing posts with label tinyg. Show all posts

Monday, September 24, 2012

Operator Commands

Well, after a very focused dev session, I was able to add the support all of the command DB elements, allow manipulation of the individual command elements (like deleting them), and feeding them to the TinyG incrementally.  It's not perfect, but it's working pretty well.  Next up is to enhance the communications protocol between the Arduino and the tablet so that it does more than passes the info on to the TinyG.  More specifically, I want to be able to send it relay commands in JSON format as well as to enable a download mode that will open up a file for writing on the Arduino.  Once I get that done I'll do another demo.

Code isn't up on github yet, but I expect to get it up there before the project is done.  Need to think about how this code will mix with the other TinyG app before I put it up there.


Sunday, September 23, 2012

TinyG Operator Progress

I've made substantial progress on the Android - Arduino link over the past couple of weeks.  I posted this video to demo some of the new work.  Still on the docket is to construct actual gcode based on the input, and to store that in the system.

I'm using a database backend to store the programs and commands.  It turns out that's easier than manipulating raw files.  I'm also using the same service abstraction I used for TinyG for Android that allows selection of either network or USB host mode interaction.  So that means that I should be able to roll this USB Accessory mode capability into the core program without a lot of pain.

I've started to think about refactoring the existing TinyG for Android code.  Instead of having a separate app with the USB support, I'm probably going to make a multi-ADK release.  So this means that folks who can use the advanced features will automatically download one app with all the code, and the ones who can only use a subset of a capabilities will get another.  It should make some of the handling a little less tortured.

Sunday, August 26, 2012

Updates to TinyG for Android and a hardware controller

I'm working on a new project that should lead to several big improvements to TinyG for Android.  The project overall is to build a simple "operator" control for an existing CNC system, which would be able to send a stored program to a TinyG when the "go" button is pressed.  For this to work correctly, the unit will need to be able to home the CNC system on reset.  It will also need to be able to handle a few additional control inputs/outputs, since in addition to the "standard" gcode-based axes and spindle controls, the unit requires the actuation of some relays.

The Android app comes into play as a programming and control pendant for the operator unit.  The idea here is to have the Android device be able to train/build a new program by providing step-by-step line, arc, and relay controls, and then to have these programs be able to be stored on the Android device and uploaded to the operator system as needed.  During the program mode, the operator control would act like a passthrough.

There are two reusable components that will come out of this project that are of general interest.  The first is the program builder.  The second and in some ways the most important is that I will be implementing the operator control as an Android Accessory.  This will require a shim device between the TinyG and the Android devices (unlike the current Host mode), but has the potential to open the application up to many more Android devices.  While my first cut will only support Android 3.1 and up, a compatibility library should allow support to even earlier devices.

I'm planning to use the Arduino ADK board as the core of the operator control.  It is in effect an integrated Arduino Mega 2560 and a USB shield.  The Arduino programming environment is kind of clunky, but I expect that it will be sufficient for this project.  I probably could have used an Arduino UNO for this project, but the Mega's additional hardware serial ports and additional IOs make it an attractive option.  I'll be combining the ADK board with at least a microSD card breakout to store the programs.  The relay integration is TBD.  Depending on the switching voltages, I may use a relay shield or a standalone relay module.

At the moment I'm just sketching out the design and gathering materials.  I will be documenting progress as I go, including some photos.

In other news, I picked up a Xilinx CPLD development board, and I'm looking forward to learning a bit more about Verilog and CPLD/FPGA programming.  Given the TinyG project, it will probably need to wait for a while.  Lots of fun toys!

Thursday, July 12, 2012

Social Work Android App



I've been working with some folks at the University at Buffalo School of Social Work to develop a feed reader that's tailored to the needs of social work professionals.  The app itself is built using a nice Android library called FeedGoal, and with a little tweaking we're adding channels that the school will manage to relate to various activities within the school and the disciplines.  Still a work in progress, but the app is up on Google Play for testing.

I'm also working on my todo list of bug fixes and enhancements for TinyG for Android.  In particular, I'd like to do a couple of behind the scenes things to make it more robust in the face of various status changes by moving the persistent objects into their own fragment.  I don't know if that's going to work, but we'll see.  I'm also planning to make it preserve the download filename between screen changes and app restarts, integrating a simplified file browser instead of using the openintents model, improving the throughput of the downloads, and a few other things.

Monday, June 18, 2012

Musical instrument CNC project

I'm taking a break from the Android app for a bit.  It's now to the point where it is functional, and before I go back and fix some of the little bugs, I want to play with it.  This will likely also identify a few more features I'll want to add.

So now I'm working on different CAD/CAM options.  The one that seems the most promising (but not the cheapest) is Rhinoceros and CamBam.  Through educational discounts I can get Rhino for $195, but it's still a good chunk of change.  CamBam and $149 isn't cheap either.  As a software guy, I know I don't want to reimplement Rhino, but for the feature set I need, CamBam might not be necessary.  Other options are PyCAM and HeeksCAM on the free end.

To help make things clearer, I've been using Rhino in eval mode to develop 3D models of objects, and then exporting the profile information for use in the CAM systems.  With CamBam, I find that unless I want to do a simple 3D profile, I end up redrawing some of the features (for example, to build a pocket or for a 2D profile).  I suspect this is just my lack of experience.  I'm spending most of my time in Rhino, since I'm pretty much sold on using it for CAD.


For a simple test, I did a small layout similar to a cake with a domed top, with a small sphere centered on the apex.  I dumped that as an STL, and then generated gcode for a full 3D profile.  This picture is really early in the cycle, but you can see the top surface being cut out, and the small bump that will become the sphere.  I terminated it after it got about 25k out of the 30k lines in the gcode, but if I left it to run it would have cut around the entire edge.  CamBam supports the use of tabs in this case, but I didn't use it.

Next I'm in the process of designing the solid body banjo and a neck.  I have the body layout I want, and no I'm working on the neck heel profile that I want to fit it.  I'm going to spend some more time with CamBam to see if there are clever ways to have it only do a profile cutout along the edge of the body, since the top surface is completely flat.  Using a 3D profile requires a lot of traverses that are incredibly inefficient.  I expect there's a way to do it.

Thursday, June 7, 2012

TinyG for Android v1.3

I've published a new version of both TinyG for Android and TinyG for Android USB Service.  This version cleans up the UI in a huge way, adds much better error checking/notification, and support for gcode downloads.  I'll put up a new video when I have a few minutes, but I was able to use this version to do some real routing last week.  It went through a small (660 line) gcode file without any troubles at all, and I expect it will work with arbitrarily large files since it operates a line at a time.

Let me know if you have any suggestions for improvements.  I have a few in the hopper (long press for a continuous jog for example), but I'm going to be working on CAD designs and bug fixes for a while.  I'm starting to design my solid body banjo prototype.  More on that soon too.

Friday, June 1, 2012

TinyG for Android updates

I'm making good progress on adding some new features, including support for gcode file downloads.  I'm spending a fair amount of time changing the UI to make better use of a tablet-size display where available.  To avoid a lot of duplicated code, this means expanding on the use of Fragments, and moving as much code as possible within them or related support libraries.

I'm also continuing to look at gcode generation options.  So far, CamBam seems to be the most reliable option, but I'm also still trying out HeeksCAM.

Another video when I have time to put together a real demo.

Monday, May 21, 2012

New TinyG for Android app demo

I worked out a few kinks in the app so that it's more robust in the face of bad data, and published a new demo up on youtube.  This demo walks through all of the current features, including connecting through both the USB and network services and looking at the system configuration.



As I mentioned in an earlier post, I'm working on adding additional support for tablet-sized displays and file upload.  In the meantime however, you can go over to my github page to pull down the latest source, and you can get the main app from Google Play.

Saturday, May 19, 2012

USB is working!

I spent some time digging through libftdi, and was able to get USB serial IO to work!  I had a problem sending gcode initially, but it turns out that I wasn't using the Message class correctly for inter-process IO.  Instead of handing the String to the Message directly, I needed to add it as a bundle:

public void send_gcode(String gcode) {
  if (messenger == null)
    return;
  Message msg = Message.obtain(null, TinyGDriver.GCODE, 0, 0, null);
  Bundle b = new Bundle();
  b.putString("gcode", gcode);
  msg.setData(b);
  try {
    messenger.send(msg);
  } catch (RemoteException e) {
    e.printStackTrace();
  }
}

So now all of the controls work via USB as well as through the network!  If you're interested in trying these out but don't have an Android development environment, I've placed packages for both the USB Service module and the TinyG for Android app up on my github site.

I'm working out a few kinks still, but the packages do seem to be useable.  The most important thing to note is that if you want to use the USB module, you need to select USB under Settings in the TinyG menu, but then exit the application.  I need to find a way to signal to main Activity when a preference has changed so that I can reset the Service binding, and I haven't found it yet.  Another point to be aware of is the USB permissions model on Android.  When you try to connect to USB, it will prompt you to make sure it's ok that the app does so.  It seems to be able to save this preference, but that doesn't seem to be reliable for me.

Now that the framework is all set, I can spend some time adding additional features, such as tablet-friendly layouts, and a gcode uploader.

Tuesday, May 15, 2012

More TinyG Android app work

I've been spending the past couple of weeks refactoring a lot of the existing code.  The network driver worked, but it relied on the bound Android service running in the same process so that it could access member functions.  While I can make that assumption for the network driver, my ultimate goal is to support USB host-connected devices, and that requires Android 3.1 or greater.  I didn't want to limit the use of the app for that one feature, and so I chose to isolate the USB code to a separate app.  The USB driver would have a service with the same API as the network driver, making it easy to change which was in use without a lot of code changes.

I needed to find a better way to have the activities communicate with the service (either USB or network) that was connected to the TinyG.  This communication needed to be bidirectional, and needed to work for multiple activities (screens).  What I settled on was using a Messenger to send commands to the service (asking for data, connect, disconnect, etc), and using broadcast intents to send messages from the service to one or more listening activities.  This seems to give the most flexibility without a lot of effort.  An alternative to the broadcasts would have been client messengers registered on the service end, but it seems like that's a lot of work for little gain.

To make more of the code reusable, I now have three projects on Github.  The main application is android-tinyg, and it contains most of the activities and preference code for the application.  android-tinyg-usb is a skeleton for the USB code, and requires API level 12 or higher.  Both of these rely on code in android-tinyg-support, which has the majority of the JSON parsing, messaging constants, and related items.  The TinyGDriver class is an abstraction for both the network and USB drivers, which subclass it.

I'm done with the refactoring, and it looks like the new code works as expected.  I hope to have a longer demo from my tablet up soon using the new code, and to have a prepackaged apk up on the site and Google Play soon after.

Friday, April 27, 2012

Android CNC App

I got the whole toolchain working today!  Android app to tgFX, to TinyG, to JGRO CNC.  See the video for a sense of how it currently works.  I hope to have the configuration settings exposed to the UI tonight, so that you don't have to edit the code to change the link to the server.

While the current version relies on tgFX to talk to the hardware (TinyG), that isn't strictly necessary.  I put together a simple serial to network java program which will serve a similar purpose.  I may put that up on github soon too.

Once I get the basics working fairly well, I'll move on to phase 2, which is using my ICS tablet to talk directly to the TinyG vis host USB support.  That will be very nice, and will get me to my main goal - use of the CNC system without a PC being required.

The write code is fairly pedestrian, but the read code from the network took a little work to sort out.  I'm using an AsyncTask to do the blocking reads, and after each line it parses the JSON and updates the necessary state info. 
private class ListenerTask extends AsyncTask {

  @Override
  protected Void doInBackground(InputStream... params) {
    byte[] buffer = new byte[1024];
    InputStream is = params[0];
    int b;
    int idx=0;
    try {
      while (!isCancelled()) {
        if ((b = is.read()) == -1) {
          break;
        }
      buffer[idx++] = (byte) b;
      if (b == '\n') {
        publishProgress(new String(buffer,0,idx));
        idx = 0;
      }
    }
   } catch (IOException e) {
     Log.e(TAG, "listener read: " + e.getMessage());
   }
   return null;
  }

  @Override
  protected void onProgressUpdate(String... values) {
    if (values.length > 0) {
      Log.i(TAG, "onProgressUpdate: " + values[0].length() + " bytes received.");
      if (machine.processJSON(values[0])) {
        ((TextView)findViewById(R.id.xloc)).setText(Double.toString(machine.getX()));
        ((TextView)findViewById(R.id.yloc)).setText(Double.toString(machine.getY()));
        ((TextView)findViewById(R.id.zloc)).setText(Double.toString(machine.getZ()));
      }
    }
  }

  @Override
  protected void onCancelled() {
    Log.i(TAG, "ListenerTask cancelled");
    mConnect.setVisibility(View.VISIBLE);
  }
}

Thursday, April 26, 2012

Android CNC code published

I finally setup a github repo for my CNC jogger application.  It's still very much a work in progress, but it's working!  I'm going to be spending some time adding some configuration controls next, and hope to have some additional features and a better control layout by the end of the week.

Code is in Github.  Will post a video of the whole things working on Friday!


Thursday, April 12, 2012

Android CNC Controller Progress

I'm making progress.

I've been discussing some of the controller options with the guys at Synthetos, looking for smart ways to collaborate.  Riley is working on a GUI called tgFX, and while it doesn't meet my needs, I didn't want to duplicate a lot of work either.  The outcome of that discussion means I've added one large new feature to the project, which is the ability to talk to TinyG via the network in addition to direct USB.  tgFX has a network port that it is happy to use as a network to serial gateway, and I've written a simple java program which does the same job without all of the GUI-ness.  What this means is that I've been able to spend more of my time recently working out the architecture in my app and less on the specifics of handling USB host on Android.

At the moment, I have a basic jog interface on the Android, and it is able to connect, get status information from the network port, and send commands.  Still left to do is to have the jog buttons actually send the right commands (easy enough now that I have the basic messaging working) and to have the status information from the device update the axis information/state on the device.  Hopefully it will all be up and working in the next few days.

I will have code posted up soon.

Saturday, March 31, 2012

Android tablet as CNC controller

It's been a while since my last post, and wanted to provide an update on my software exploits this month.  Lots of trial and error, but only limited progress.  I spent a couple of weeks trying to get the Chumby to work as a CNC controller.  I actually got it talking with the TinyG unit, had status data, used the touchscreen, etc, but I decided that to move it further would be counterproductive.

The first problem was the particular Chumby I was using - it seems to have a problem with the power regulator or the power connector, since it flakes out when the cable is moved around even a small amount.  After trying a few different ways to try to feed the thing power, I decided it was going to be dicey.  The other reason is the age of the Chumby internals - the ARM system it is using is old enough where many of the tools I wanted to use were simply not available.  I could get a version of java for example, but the standard Oracle JRE wouldn't work because it was ARM v7.  To top it all off, since the Chumby doesn't have any native framebuffer libraries, I ended up spending more time than I wanted simply developing methods to write to the raw framebuffer.

It's been a LONG time since I've implemented a line drawing algorithm.  Or writing out a bitmapped font one bit at a time.  Or double buffering.

So for all of these reasons, I've dropped the Chumby.

I do have a backup plan however, and that's to use my Viewsonic Gtablet.  It's a great little Android-based unit.  It's bigger than the Chumby, which for my purposes is fine.  With the help of the clever people at Team DRH, I have Android "Ice Cream Sandwich" installed, and the kernel understands USB serial IO!  While I have started to work on a UI and plan to use the Java RXTX serial communication classes, I may find a way to team up with the Synthetos folks with the UI system.  It's JavaFX-based, which isn't available on Android so far as I can see.  Hopefully I'll know more soon.

If an Android-based CNC controller is of interest to you, please let me know!

Thursday, March 1, 2012

TinyG Update

Now that I have a working TinyG and enough of a platform for some basic tests, I've started to think more about the software side of things.  I chose the TinyG because I liked the idea of making the device smarter - a lot of designs rely on software packages on a PC like Mach 3 to do all of the low-level pulse timing, interacting with the hardware and stepper controllers using parallel port breakout boards, etc.  I'm sure it works well and is quite modular, but it doesn't take into account the huge advances in microcontrollers over the past decade or so.  Since I have a background in computing and electronics as well as a fully stocked machine shop, I don't feel bad about trying something a little out of the norm.

The other reason I thought it would be nice to try TinyG is that, at some point, I want to convert my existing manual metal lathe to CNC.  The spindle control capability that is being developed for TinyG looks like it could be useful.

So I pulled enough parts out of the scrap bin to build a fairly nice Ubuntu CNC computer, which I've connected to TinyG via USB.  The PC and TinyG are currently sharing a beefy PC power supply, however I think I'm going to split those up once I find another junk supply.  It seems to work just fine, but I don't know how the supply will behave with "high" current motor loads - if it introduces ripple, it might annoy the CPU which also uses the 12V supply.

For a toolchain, I'm thinking of using PyCAM and/or Skeinforge to generate G code, and Inkscape and FreeCAD to generate the appropriate STL or other files.  I'm going to give the free software a good shot before I start looking at commercial packages, but things like CamBam are viable alternatives if the free stuff doesn't suit my needs.

Since there doesn't appear to be any really good software for talking to TinyG, handling status information and uploading G code, I might write something up.  If you know of something, let me know in a comment.  I saw someone who used the status info to graphically draw the tool path as output from TinyG, and that would be a great place to start - if I can find it again!

Friday, February 17, 2012

TinyG

Got the TinyG, but I'm having some problems getting it to talk to all of the axis.  Hopefully I'll be able to work it out with the guy who did the design.  I also got the 3 steppers, and I'm in the process of building a wiring harness.  I plan to make my own shaft couplers, and it looks like I'll need to space the motors off at least the Z axis for clearance with the axis trim bolts.