Using OpenJSCAD to print a house (2/N): Small Print!

I advanced the code significantly:

https://github.com/sunnywiz/housejscad/releases/tag/Post2

  • I introduced a “TwoD” class to take the pain out of working in the 2-D character space.
  • I traced out my house’s 4th floor plan to a text file, so I’m dealing with the real thing now rather than test data.
  • I got my 3D printer back up and running – didn’t need any re-calibration after 6 months of no-use.  I had to go read the powerpoint of the presentation I gave a while back to re-remember what to do.
  • The result is this print, which is 1:72 scale, and took about 4 hours (1 failed print included):  

image

Its in two pieces so that:

  • I don’t have to print support structures for the doorways and windows
  • We see things at eye-level, or about 5.5 feet; the model is 8 feet; this makes the model feel overly tall.  With a removable section a little lower, this becomes more “playable”. (I need to move the cut line up though to be at about 5 feet.  Or, move the windows down a bit)

I’ll do a full “How To” video at some point in the future – I’m not quite done yet.  There’s some bleeding edge stuff in the “cuts” branch at the moment:

  • I’ve learned how to do real drag-and-drop libraries, in a separate file, which will work with OpenJSCAD
  • I’m working on a cutting algorithm that will let me cut with tabs.  Its workable now, but needs some fine tuning on gap distances.
  • We’ve (wife and I) decided to do the final print in 1:48 scale – there’s a lot of toy furniture out there available at that scale.  And it will be printed in white.

More to follow at some point.

Comparing Nutrition Tracking Apps (iOS)

I’ve decided I’m going to track nutrition again.  I tested entering the same day into 4 apps and recorded myself:

Here’s the raw video of all 4 side by side.   Its provided for reference only, I don’t expect you to actually watch it, unless you work for one of the above companies trying to understand what I saw.

[youtube=http://www.youtube.com/watch?v=05zfzKXJlzA&w=448&h=252&hd=1]
4 Apps, Long and Boring

 

Here’s a close up of just the breakfast bits, for only two apps, trying to compare the same item to the same item:

[youtube=http://www.youtube.com/watch?v=cJ7z_74n_GQ&w=448&h=252&hd=1]
2 Apps, Just Breakfast, Almost Watchable

 

Frustrations

These are all my opinions, not statements of fact. 

  • Up!
    • Could not find some restaurant food, so I had to go find something else that might or might not be equivalent.
    • Amazingly wrong values for Orange Juice (45 cal per orange!), and Orange Juice (100 cal per g)
    • While the “just add it and edit the quantity later” seems like a good idea at first, I think there were a lot more touches in the end.
      • One reason why this one had a longer video – I had to go look up caloric values for stuff it couldn’t find, so that I could go back into the app and update things to more reasonable values.  The other apps, I already knew the caloric value I was looking for, so they were spared this embarrassment.
    • Their “slider” for changing quantity took a bunch of fiddling.
    • If you enter food as you eat it, it’s a lot easier, but otherwise, selecting times for meals gets hard.  I like the other apps “Breakfast, Lunch, Dinner, Snack” method better. 
  • MyFitnessPal
    • Looked kinda clunky?  (but it worked!)
  • FatSecret
    • I think I was trying to put in 471g of soup, since my scale tells me its 471g, and wow that was annoying to have to scroll gently from 100 to 471.
  • Lose It!
    • Their selection of foods seemed limited, didn’t find what I was looking for.  Its like they’ve tried to reduce complexity of what is available or something?
    • App crashed during data entry, I had to restart it.

Winner

MyFitnessPal gets my “business”.  I do not remember being frustrated trying to enter anything; everything I searched for came up; they had decimal input; and I agreed with the calorie estimates given the first time around.

Using OpenJSCAD to Print a House (1/N)

Since before I got my 3D printer, I’ve wanted to make a scale replica of my house.   I tried doing it with Legos once – it was cost prohibitive.

I came up with a workflow where I drew out the entire house in SweetHome3D, and then exported that, but I ran into manifold problems and stuff like that.

So I did one of the floors in Sketchup.  However, that was a painfully task – and the resulting model was still too big (I want 1:24 or 1:36 scale).  I’d have to slice up the model to print out individual pieces, which means I wanted to cut them in such a way that they joined together with some kind of self-aligning joint.

I was about to try it again, but the sheer amount of detail that I had to go through kept holding me back.  I wanted a formula.

A recent blog post brought my attention to OpenJSCAD. and an Idea formed in my head:

Convert THIS: image
Into THIS: image

I had tried to do something similar in OpenSCAD before, however, because that language doesn’t have procedural elements, I ran into all kinds of problems.   Fresh new start!

So I set about to do it.

As you can see by this screenshot, I succeeded.

The code is here: https://github.com/sunnywiz/housejscad.  It took me about 2 hours.   You can see the commit log, I committed every time I figured even a small piece of the puzzle out.

UPDATE 2/1/2015:  the code as of this blog post is tagged with “Post1”, ie https://github.com/sunnywiz/housejscad/releases/tag/Post1  — the code has since evolved. Another blog post is in the works.  I guess I could “release to main” every time I do a blog post.  Heh.

The Code

  • Provide a translation of map character to 1x1x10 primitive anchored at 0,0,0
  • convert the template into a 2D Array, so that I can look for chunks of repeated stuff.
  • Walk the pattern, looking for chunks.  Rather than get fancy, I made a list of all chunk sizes from 6×6 down to 2×1, and check for each one at a time.
    • There are more efficient ways to do this, but IAGNI.
  • If a chunk is found, generate the primitive for that chunk, scale it up, and add it to the list.  “Consume” the characters which we just generated.
  • When all done, union everything together.

Notes about the Code

  • The resulting file is not manifold, however, NetFabb fixes that pretty easily and reliably.
  • The chunking is necessary if I want to represent steps in an area.    Otherwise, I didn’t need it.
  • You can define any mapping you want .. from a character to a function that returns a CSG.
  • Could probably use this to generate dungeon levels pretty easily.  Or, maybe take a game of NetHack and generate out the level?  Coolness!

Where would it go from here

  • Lay out an actual template of (part of) the house, and fine tune it from there.
    • Probably involve adding “and I want the result to be exactly 150 by 145mm” type scaling.
    • The functions will probably start taking arguments like (dx,dy) => so that the function can draw something intelligent for an area that is dx by dy in size.
    • I just noticed, the output is mirrored due to axes being different between R,C and Y,X
  • Preferably, I’d like to create a object / class that does this work, rather than the current style of coding.  IAGNI at the moment.  Then, maybe running in node, I could take the different floors and convert then into objects, and then do further manipulation on them..
    • Like slice them into top and bottom pieces.  Windows and doors print a lot better upside down – no support material necessary.
    • Would also need to slice them into horizontal pieces.  My build platform is limited to 6” square.
  • I live in a very 90-degree-angle house.   Thus, this kind of solution would work for me.  Sorry if you live in a circular, or slightly angled, house, this solution is not for you.    Buy me a house, and I’ll build you a solutiion. 😛
    • Seriously thinking about this.  I’d probably have a template of “points”, and then a language of “Draw a wall from A to D to E”;  and then “place a door on wall from A to D at the intersection of F”  or something like that.

A fun night of short and sweet coding.  I had to look up a lot of javascript primitives, mostly around arrays of arrays, and checking for undefined.

Some day I’ll get that “doll” house printed.  Then I can make scale sizes of all my furniture from Lego’s!  Fun fun.

Using blender to make 3D font thingies to print at Shapeways

Posted in a how-to video here:

[youtube=https://www.youtube.com/watch?v=muMX3byfJ9o&w=448&h=252&hd=1]

 

0:00 Intro
0:49 Choosing a Font
1:06 Blender the inadequate Intro
2:00 The “Fast” route that doesn’t always work
6:07 “Reliable” way
9:40 Deleting Inner Shells
10:43 Exporting to Shapeways via OBJ – No Texture
12:00 UV Mapping, Texture
15:31 Exporting to Shapeways via X3D – With Texture

Having now finished the video, it occurs to me that using a picture as texture would work very well with cylindrical or spherical mapping.

While in this video I’m focusing on printing at Shapeways, its possible to print at home – just export to STL.  However, Shapeways uses a different process which allows for filler material which makes supports a lot easier for this kind of complexity, compared to the FDM process I would use at home on my Solidoodle.

Video captured using Open Broadcaster Software; edited down using Premiere Pro.

Code for doing Explosions

Playing FortressCraft Evolved, I played with explosives.  I was not particularly happy with how the explosives were handled – and I was on vacation, and I had no internet access, so my creativity got into my brain and I tried writing code that would handle explosions better.

I shoved the code here:  https://github.com/sunnywiz/explosion2d

Here’s the basics of what I did:

  • I did this in 2D instead of 3D because easier to Console.WriteLine()
  • I created a TwoDSpace<T> so I could store an arbitrarily large number of T’s in a 2-D plane
  • I created a function which mapped out, given a center 0,0, what the distances were to each X,Y. 
    • I kept distances as squares, so I didn’t have to do square roots.
    • I did it with an initial max-radius, but the final version in my head would jit-figure out what it needs and save the resulting calculations in a static – it only needs to calculate it once.  Bigger explosion might need to calculate some more.  
  • That function can then call to a lambda, giving it:
    • the X,Y of the point that is being visited by the explosion
    • an array of parent points for the explosion and the ratios by which to weight them
  • The caller then says, “circle visit an explosion starting from here”, and keeps track of the force per X,Y that is being experienced.  The caller is responsible for all the code that says “Ores are hard, but dirt is soft”, for example, or “Diamond cannot be damaged by the explosion”
  • I think its pretty fast. O(r^2), which given its a 2D explosion in 2D, is expected. 

Fun Fun stuff.   I miss the days of mud coding.   You just don’t need to do explosions like these in real-world paid programming.

Setting up a Private Key Double-Bind Retention System

It sounds really fancy, but its not.

The other day, I got to my office, and found that my fob was missing from my keychain.  I traced my steps back, and found it on the ground next to my car – it had fallen entirely of my S-biner.  Not cool. 

So, this is my solution:

image image

I have transferred all keys to very solid rings – not the little itty bitty loops that I’ve had 2 of them unwind on me. 

Then, I’m attaching each ring to the other rings in a big circle of beeners.   So if one fails, I have a backup.  RAID?  Nay, i say, RABID – Redudant Array of Beeners Implemented Dually.    (I made that up)  (Its okay for me to laugh at my own joke)

Angry Birds, btw, is my office key.

The Gray fob is the Anytime Fitness fob; and the White fob is a Tile.  Interesting app, Tile.   Another post, perhaps. 

Starting Running Again

This is at least my third or fourth time picking running back up.   I just got to the spot where I could do a (slow) 5k.     What is my awesome secret sauce?

  1. Heart
  2. Muscle strength
  3. Flexibility
  4. Form
  5. Joy

Heart

Find and read a book  or website about heart zone training.  In general, it goes like this:  There are different heart zones; You need to keep your heart in “Kinda working, but not very hard” zone, aka “I can still hum a song” zone, for 30+ minutes at a time, to exercise it such that it wants to grow and become stronger.

If you go too fast, and you get to the “I can’t really talk at the same time” zone, or even the “breathing heavy” zone, you’ve left the “lets invest in ourselves” zone and entered the “lion is chasing me deal with it now at expense of future” zone.

If you haven’t got the heart developed, as soon as you start running, your HR will spike up to to ridiculous levels, you’ll be panting, you won’t be able to do it for more than 5 minutes, and you’ll do it so sloppy that you’ll injure yourself.

For me, this is walking at 3.4 mph or so, and breaking out into a very minor jog of about 4.2 mph.   Everybody is different. 

Muscle Strength

Running involves a lot of muscles.  There’s an exercise called the Hundred-Up that’s pretty dang simple.  If you can do the Minor for 100, you’re ready to joggishly run.  If you can do the Major for 100 reps, you’re ready to run fast.  And we’re talking good form, not sloppy, when doing them. 

Flexibility

I am already pretty flexible, so I skipped this, but I think it gets a lot of people.   Here’s what happens: If certain muscles / joints don’t have the right range of motion, then the body still gets it done – but it does it with bad form, at the expense of some other muscle that’s not supposed to bear that kind of load.     There’s a dude wrote a book about it:  Ready to Run.    Also has lots of solutions for each of the problems.  Good book.

Form

This is touched on in the Hundred-Up exercises and the Ready to Run book.   You do NOT want to heel strike.  Bad stuff happens.   More written in the book above; for me, running barefoot was my solution – it re-trained me to land differently.  My cadence went up .. from 150bpm to about 180bpm.   So when I’m jogging at 4.2 mph on the treadmill, I look like a video of a waddling penguin sped up 200%.   Maybe.

Joy

Running, for me, is like dancing, or playing the drums.  I love to run with music.   There’s a song, Stompa.  Its way fun to run to.    I have to find my joy in the activity, or it doesn’t stay.

 

So, here I go.. back in the saddle again.. out where my foot is my friend…

A small victory

There’s a lot of change going on in my life… internal change.   A quick summary would be:  CPAP, sleep, goal setting, sticking to a schedule, kid moved out, gym.

Part of the goal setting thing was to not advertise them, so I won’t.. they have to stay personal, private, and accountable to important people.  What I will say is that this is the calendar I’m trying to stick to, with blessings from my partner:

image

The idea at first was to work out after work, as the gym is on the way home.  However, that ran into a few things:

  • I had to take the right Gym clothes with me at the start of the day
  • I had to transition from work to gym clothes and then back out to winter coldness
  • If I was going to bring home take-home, it had to be near the gym
  • I got home all sweaty

So, today, we reversed it.   I brought home takeout first, and then hung out with my darling, and THEN, with her blessing (I’m a little co-dependent at times), I went back out to the gym.. already in my gym clothes.

image It was awesomely wonderful!  I ran PI miles (3.14) .. there were less people there, I could get on the treadmill when I wanted.. I was not on a schedule so I ran an extra 15 minutes or so because I was feeling good.. heck, I was dancing on the treadmill.  Yeah, one of those guys.  Not sorry. 

And then I got home, did a few more messy things involving garbage, then took a shower.. transitioning to “self” time – which I’m spending typing up this blog post.

Life is Good. 

Separate post about picking up running again.   I forget what I’ve posted about already and what I haven’t.

Sleeping at the Office

Based on vacation hours, I could either have worked the day after Christmas, or, thanks to flexible hours, I could try to get all my hours in before Christmas Eve.  

How

I took a blanket to the office, and stayed there till the deed was done.  I slept when I was tired, took time out for walking and eating and other minor things, but mostly worked.  Out of curiosity, I logged what I did in Excel:

image

Analysis

Below is the distribution of sleep, work, and other (life) that I endured.  This is NOT STACKED though it looks like it.

image

See the flat line of blue from 1pm to 9pm?  My wife picked me up, we went to look at a house, had dinner, then I went home, slept, and showered, then returned to work.

Comparatively, if I had done normal hours: (sleep midight to 7; work 9-12 and 1-4):

image

 

Thoughts

  • I converted “Other” time into “Work”.   Sleep was more or less identical.   Theoretically, this gave me more “Other” time on Friday.
  • It was quite stressful.  I should probably include the day it took for me to return to normal.  (Stress as in “my body was under stress”)
    • If I ever do this again, I’m taking blood pressure and other measurements.
  • Interesting that a segment of work translates to a segment of sleep shortly after.  This was certainly not planned, but it worked out that way.  You cannot escape needed sleep.
  • Assuming the ratio stays about the same, I could do a regular week of work from Monday 8am to Thursday 8am?   Assuming no meetings and scope changes, of course.  (hah!) 

Tips

If I were to do this again, what would I do the same or differently?

  • Invest in a cot or air-mattress to make sleep more effective.
  • When sleeping, sleep FULLY, not “just enough”.  You’re going to sleep the same amount in the end.
  • Nap after every good bit of work; but look ahead (preplan the next bit of code) before napping so subconscious can work on it.
  • Invest in fatty snacks rather than carby snacks.  Especially good for me this time was Dinty Moore Beef Stew.
  • Have minor things you can do for yourself in the middle so you don’t feel neglected, like going for a walk, taking care of an errand, etc.

Process with States

I implemented this again today, and realized it was a pattern that I fall back on regularly.

When dealing with a system with several states, and actions to be performed at each state, I usually break things up into a state diagram.  Inevitably, I end up with a “State” field, the the question becomes what to put in the state field.

Take an example of sending an invite to a user to come in and use an app.

What I do not do:

Alter Table Invitation

add state int not null default(1)

 

enum State { Start = 1, Email = 2, Consumed=3, Expired=4 }

What I do (approximately):

alter table Invitation add
	state varchar(25) null, 
	stateError bit(1) default(0) null, 
	stateTimestamp DateTime default(getdate()) not null

public static class InvitationState { 
   public const string SendEmail="SendEmail";
   public const string WaitInbound="WaitInbound"; 
   public const string InviteConsumed="InviteConsumed"; 
   public const string InviteExpired="InviteExpired";
}

Why?

  • It is my experience that for any flow, a future spec will come up with will add new states in the middle of that flow.  If you go with an int value, you end up with the flow being 1->9->5->6.   By going with a varchar, its much more obvious when doing a select from the db, and it allows for the addition of new states.
    • A previous employer loved using CHAR(4) and state names like “STRT”,”MAIL”,”CONS”,”EXPR” because Oracle stored the Char(4) like an int.   Very similar to Apple’s Resource Fork’s from back in the day.
    • I’m not so worried about the speed difference it makes.  I feel that the flexibility it gives makes up for any performance loss.
  • Either we have an action state, named with a “Verb Noun”, or we have and end state, named with “Noun Verb”.
  • The state names are based on what IS happening or SHOULD happen to the row, not what has already happened, except for the end states.
  • For any action state, if the attempt at performing that action fails, I set the stateError bit to 1.  This lets me know I need to do something to fix that; when its fixed, I can change the stateError back to 0.
    • In large batch systems, I write the console based action-taker with an override switch:  to work on a specific Id, even if the errorState=1; and to do it in a transaction but not commit the transaction.  
    • This lets me do test-things with rows that failed, while the main batch system processes all the other non-errored rows.   Once I get it to working, I tell it to go ahead and commit, and the system continues on its merry way.
  • The system only deals with the states that it knows.  This lets the technical OPS team (whoever that is) use the state field for its out-of band processes, stuff like setting the state to ‘Ken’, for example.   Because Ken is the man who knows what is up with those rows.
  • In really large critical systems, there’s an audit table and a trigger that auto-inserts any changes to the audit table. 

The result of this is, I get Christmas cards in the mail from former clients with phrases like “Still amazed by your code!!!”.   🙂

Hope this helps.