Monday, June 12, 2017

OnShape In-Browser Parametric CAD

I've been using OnShape for hobby projects for a while.  I used Pro/ENGINEER when I was an undergrad, but wouldn't spring for a license for it or Solidworks for just hobby stuff.  (You know a license is going to be expensive when you can't find a price on the website.  "If you have to ask...")  I get the impression that a lot of hobbyists use SketchUp, but I'm totally hooked on parametric CAD and so SketchUp seems underpowered.  OnShape is remarkable in that it implements a pretty interesting range of parametric CAD features, but runs in the browser.  It has a free tier that lets you use it as long as you don't mind everyone being able to see and copy your projects.  (FYI: Buried in the terms of use it is suggested that you put a LICENSE tab in the project to determine reuse rights.) Unfortunately, the step up beyond the free tier is $100/month, so it immediately becomes unrealistic for a hobbyist to have any private documents.  Free accounts could have a couple of private documents when I first joined, but they removed that after a while.  Anyway, OnShape isn't perfect but it is a nice and free way for me to design things.  I use it mostly for 3d printing, but I'm now exploring how to use it for woodworking projects.

Sunday, November 22, 2015

Arduino Makefile on Mac OSX

In my continuing project to build a little hexapod robot, I figured I would try to get the Arduino code running from the command line.  I like to use Emacs and all that, old school style.  Here's what I did to get that going.

  1. I cloned Arduino-Makefile off of Github.
  2. I installed CrossPack for AVR to get the AVR toolchain.
  3. I set various environment variables in my ~/.profile .  You'll need to set these according to the system and board that you actually have.
    • ARDUINO_DIR = /Applications/Arduino.app/Contents/Java
    • ARDMK_DIR = $HOME/Dropbox/Robotics/Arduino-Makefile
    • ARDUINO_CORE_PATH = /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino
    • BOARDS_TXT = /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/boards.txt
    • AVR_TOOLS_DIR = /usr/local/CrossPack-AVR
    • MONITOR_PORT = /dev/cu.usbserial-AL01CARS
    • BOARD_TAG = diecimila
    • BOARD_SUB = atmega328
  4. After setting these up, make show_boards, make, and make upload seemed to work.

Sunday, November 15, 2015

Using Pololu Mini Maestro on Mac OSX 10.10

For my little hexapod project, I want to control 18 Tower Pro MG90S servos with an Arduino Nano.  To perform the motor control, I bought a Mini Maestro 18-Channel USB Servo Controller, made by Pololu.  However, I'm on a Mac and Pololu doesn't seem to offer support for Macs or be interested in doing so.  I want to manage the Mini Maestro via the Nano, but there seem to be settings that can only be adjusted via USB, e.g., the baud rate.  So, I spent some time trying to figure out how to do this and figured it might be useful to someone else.

The first thing I did was grab the Maestro Linux software. Then I used Homebrew to install Mono:
$ brew install mono
This gave me some obnoxious errors about missing libraries, which were sorted out by an additional installation:
$ brew cask install mono-mdk
After this, it became possible to fire up the Maestro Control Center GUI via:
$ env PATH=/Library/Frameworks/Mono.framework/Commands:$PATH mono MaestroControlCenter
However, it seems not to play nicely with the default installation of libusb.  So I uninstalled the default version and installed the cutting edge universal version that would hopefully play better with Mono:
$ brew uninstall libusb
$ brew install libusb --universal --HEAD
After this, I was able to open the GUI, although it was almost unusable due to visual artifacts.  However, it was enough to verify that I could move a servo on channel 0 and ensure that the controller settings had the right values.


Saturday, November 14, 2015

Getting an Arduino Clone Working on Mac OSX 10.10

I recently treated myself to an Ultimaker 2.  In addition to making doll furniture for my daughter, I also hope to get back to playing with small-time robotics.  I've decided my first project will be a hexapod, like this one: http://www.thingiverse.com/thing:432829.  Printing the parts is going fine, but the last time I did any embedded programming was with a 68HC11.  Needless to say, times have changed and we're in the era of Arduino for hobby embedded device development.

So I ordered myself an Arduino Mini clone ("Ieik Mini Nano V3.0 Atmega328p") off of Amazon to get started.  I use Homebrew, so I grabbed the IDE via:
$ brew install brew install Caskroom/cask/arduino

I fired it up with
$ open ~/Applications/Arduino.app
and loaded up the basic blink example, as described on the Arduino tutorial page.  A lot of people have been reporting issues the USB connection and I immediately got:
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
I started hunting around for the way to fix it.  I went to the FTDI site, grabbed the VCP drivers, and installed them.  This didn't work, even though my clone has a genuine FTDI chip.  After lots and lots of web pages, I finally got it to work.  The key thing was to treat it like a Duemilanove, despite it having both "Mini" and "Nano" in the Amazon web page and it having the same layout as a Nano.

Monday, February 18, 2013

Replacing Make with SCons

After a long hiatus, I decided to start once again playing around with building a game engine in C++ on my Mac. I've been reading the very enjoyable Game Engine Architecture by Jason Gregory, and it's really opened my eyes to the number of distinct modules that go into even a hobby-developer game. In particular, I hadn't appreciated how many executables a game might have that aren't the game itself, e.g., map builders, scene debuggers, asset viewers, and servers. Many of these are going to share a lot of code, and so it seems very important to have a modular source tree and build system. (This is, of course, true for essentially any large project, game or not.) I've been using Makefiles for my build management for a long time - being an Emacs/Terminal type of software developer. The only exceptions are that I tend to use Ant when I'm writing Java, and I use Visual Studio when I have to write C#. I even use Makefiles for LaTeX.

Highly modular projects tend to have multiple source directories, and these tend to require complex recursive Makefiles that are not usually very efficient. In browsing StackOverflow, I've noticed several references to the tool SCons. I installed it via MacPorts and thought I'd check it out. The SCons Wiki has a list of reasons why you might prefer SCons to Make. Here is what I did to try it out on a tiny little stub of a project with dependencies across directories:

project/
  util/

    Logger.cc
    Logger.hh
  lua/
    Lua.cc
    Lua.hh
  client/
    ClientMain.cc
  server/
    ServerMain.cc

Honestly, the introductory documentation on the wiki for SCons is pretty poor.  Despite all the statements about it being scalable for large projects, the tutorial examples are for situations where you'd hardly even need a Makefile: the build system is just running one or two commands.  The user guide gradually reveals the more important details.

The basic situation is this: some of these subdirectories are library modules (here, "util" and "lua") and some are executables ("client" and "server").  What I want to happen is for "util" and "lua" to compile to "libutil.a" and "liblua.a", respectively.  Now, "client" depends on both "util" and "lua", but "server" only depends on "util".  The question is, how do I tell the SCons hierarchy to look for a set of other modules, without hard-coding them?  In browsing through the many StackOverflow questions about SCons, I came across this one, which made it seem easy for some reason.  However, it isn't quite that easy, as it's still necessary to tell it about the dependencies via Python string slinging.

project/SConstruct

project/util/SConscript

project/client/SConscript

project/server/SConscript There is almost certainly a better way to do this. The main SConstruct file first makes sure that everyone has the correct include directories. Then it loops over all of the modules. Each module specifies what other modules it requires and constructs an appropriate LIBS and LIBPATH to get them.

Monday, May 30, 2011

Modding Minecraft for 3d Automata: First Attempt

I like messing around with Minecraft. I went through a phase of actually playing it, but I now mostly just enjoy looking at what other people make. I love the mutability of the world. What bores me about it, however, is the lack of dynamics. In the basic game there is essentially no way to move blocks in an automated way. The in-game redstone wiring mechanic is interesting, but limited. Adding such functionality doesn't seem to be a priority for the developers, which is their right, of course. However, the game has a thriving community around engine modifications.

So, I thought I would implement 3d cellular automata (CA) in the game and see where that goes. Interestingly, although a huge amount of research has been done on 2d CA, e.g., Conway's Game of Life and that book by Stephen Wolfram, fewer things seem to be known about 3d automata. To get started, I implemented a couple of the rules in this paper by Carter Bays in the journal Complex Systems. The paper discusses totalistic CA, where the state of one cell depends on how many of the adjacent 26 cells are occupied. Bays uses a notation E1, E2, ... / F1, F2, ... where the En indicate the sums which lead to an extant cell continuing to be occupied, and the Fn indicate which sums cause an empty cell to become occupied. I tried out the 6,7,8/5 and 2,3/5 rules.

The video below shows the result of the 2,3/5 rule. Note that this isn't really "proper" because I'm not stepping everything forward at once. I am depending on the block-wise updates that Minecraft already implemented. I've appropriated the mossy cobblestone block. I've also set it up so that it cannot evict any cell other than air. So it cannot grow into the ground and other objects in the world. It basically takes over the game to such an extent that it becomes unplayable.



Here's a rendering of another 2,3/5 run:


Next up: 1) making the CA update in lockstep to allow gliders, 2) enabling interaction with other blocks in the environment.

Sunday, May 1, 2011

Resources for Beginning SDL Development

I'm currently messing around with the Simple DirectMedia Layer (SDL). For just getting going with putting a window on the screen and starting an event loop, I found this tutorial by Tim Jones to work as advertised, even though it's almost four years old. Following that, I expanded it with his OpenGL tutorial and was in business. My silly codename for this project is "NZ" -- don't ask why. So, I have four interesting files right now: Makefile, main.cc, NZ.hh and NZ.cc. These put a colourful square in the top left corner of the screen.

Makefile



main.cc



NZ.hh



NZ.cc

Run 'make' and then './main' in your terminal and you'll get something like this: