Friday, September 23, 2016

Calculating Dihedral Angles

Just a quick one today.  Up until recently I had never heard of the term dihedral angle.  It sounds complicated but it's something you already know.  If you have two surfaces in spaces that meet, they will form a line. The angle between the two surfaces at this intersection is called the dihedral angle.

I had recently been wondering about how to calculate the angle between two surfaces and decided to work through the problem myself.  First of all you need to describe the surfaces and I thought that the best way to do this was by supplying vectors normal to each surface, v1 and v2.
Angle between two surfaces

By simplifying the geometry and extending the normal vectors until they intersect you can start to see how to solve the problem.
Extended surface normal vectors

You can also derive the following formula from the geometry.
Relation between alpha and beta

From this you can see that the cosine of beta is equal to the negative cosine of alpha.
Simplified cosine term

By taking the dot product of the vectors v1 and v2 you can quickly derive an expression for the angle alpha.
Expression for alpha

Great!  Problem solved.  Or is it?  The inverse cosine function only returns values between 0 and 180. This means you will never get an answer greater than 180 degrees, meaning you can't have convex angles.  The image below demonstrates why.  Given the vectors v1 and v2 to define the surfaces in the first part of the image below you would quickly run into trouble.  You can see in the lower part of the image that the same two vectors can be used to define a different geometry with a concave angle.
Ambiguity between vectors

As the equation for alpha above doesn't change if the vectors v1 and v2 are swapped the two geometries above will give the same angle.  There are ways to work around this problem, you just need to be aware of the geometry you're working with.  I'm still having trouble getting my head around this.  The order the angles are given is important and would allow you to work out if the angle is concave or convex, but when generalising this to 3 dimensions you have trouble depending on what angle you look at joint.  I'm falling asleep typing this with pictures of vectors dancing around my head.  Maybe a fresh set of eyes will help.

Monday, September 12, 2016

Compound Mitre Cuts

It's funny how the seemingly easy can be ridiculously hard.  A relative wanted a replica of a serving tray that belonged to a family member, and I was asked to work out the mitre angles because I'm the math guy.  "Sure, no problem" I naively said.  All that was required was to tilt the tops of all the sides outward so that the timber was 25 degrees from vertical.

Mitred Wood
Angled Frame
Before going too far it seemed prudent to cut a test using some scrap wood.  The first step was to cut a 25 degree taper on the edge of the moulding that's in contact with the base.  That was easy.  I then came unstuck trying to calculate the angles required to make the corners fit together at 90 degrees.  I ended up using an awesome online calculator to calculate the angles for convenience.  It may seem easy, but in this case the mitre angle needed to be cut at about 22.9 degrees, while at the same time the head of the saw needs to be tilted at 39.9 degrees.  It took me a while to figure out where those numbers come from, but suffice to say it's not the simplest of maths.

Mitred Wood
Undercut Mitre
The moulding wasn't to easy to work with as it doesn't have many flat surfaces.

Mitred Wood
Undercut Mitre
Mitred Wood
The corners don't fit together that well as I didn't take extremely accurate measurements.  It also doesn't help that the parallel edges aren't exactly the same length.

Mitred Wood
Frame Corner
One problem I currently have is that I don't have a good way to measure angles.  That should be solved soon.  Combining the results so far with a little more accuracy should make the job a lot easier.

Mitred Wood
Mitre Corner
In the image below you can see the complex shape of the wood I'm using for the test.  The actual serving tray will be made out of plain rectangular material making things a lot easier.

Mitred Wood
Profile Shape
I do have a method to calculate all the angles needed to make compound mitre cuts.  It makes use of vectors and exploits some of their abilities, but I'll leave that for another time.

Thursday, September 1, 2016

Custom Storage Box Prototypes

In my last post I played around with an idea for mass producible boxes that can be manufactured with laser cutting and routing.  Before going too far down this path I wanted to test the form factor of the box, discovering what works and what doesn't.  Besides, I actually need some storage.

I started with a cheap 1.2 meter long piece of pine from Bunnings.  The external dimensions of the box (350mm x 275mm) were selected to minimise waste from a single board.  The timber is 184 mm wide and is close enough to the desired final height of the boxes, it therefore didn't make sense to change it.  Ideally I think 10 mm plywood is optimum for the box sides, but 19 mm pine will be fine for this test.  As the sides are thicker it also allows them to be joined with a dowels instead of cutting time consuming box joints.

Wooden Box
Box With Sliding Lid
The construction is very simple, with two side panels placed between a front and rear panel.  All contain a rebate at the bottom to retain a piece of 7mm ply for the base.  The front and sides are also rebated at the top to hold a 7mm ply sliding lid.  The back panel is cut lower to allow the insertion and removal of the lid.  In the final design the groove for the sliding lid would also continue into the back panel, but it's quicker and easier to just cut it straight across.  Remember, the point of these boxes isn't for demonstrating my jointing prowess (still a beginner, but getting better) it's to quickly produce a box to use and test.  You'll also notice I wasn't too concerned about router tearout either.

Wooden Box
Rear of Box with Smaller Back Panel
When inserted, the lid prevents dust entering the box and items falling out.  However, in this rudimentary test the main problem is that if the box is picked up from the front the lid slides out the back.  It definitely needs some sort of retention mechanism and it also needs a handle.  Both of these flaws were obvious from the start, but I haven't really settled on how I want that to work.

Wooden Box
Top of Box
This is my favourite part of the design.  They're brass drawer pulls I bought on Aliexpress for about one Australian dollar each.  They allow small labels to be inserted and removed as needed.  The viewable area of the labels they hold are about 40mm by 20mm and you can fit a decent amount of text in there, but it's not that readable at a distance.  Unfortunately the proportions of the front panel look weird too.  As these boxes are designed to fit a specific location I had to make the long side the front, ideally the short side would be the front and these drawer pulls would be more suitable.  Luckily there are larger ones available, so next time I'll buy those.

Wooden Box
Brass Pull with Label Insert
I also decided to experiment with interlocking removable dividers.  There theory was to split the box up into 9 equal compartments to allow better separation of small items.  Due to tool and jig issues, I had to make the centre compartment on the long side larger than the others.

Wooden Box
Front to Back Dividers
With all the dividers in place you may notice a lot of space around some of the joints.  I was allowing a lot of clearance in this part of the job as I wanted everything to go together easily the first time.

Wooden Box
Side to Side Dividers
The big problem I discovered is that there's a minimum usable compartment size.  I can get my hand in the smaller ones but I can't see what I'm trying to grab.  If the box was only 25 mm tall that wouldn't be a problem, but as each compartment is about 150 mm deep it isn't going to work.  I think if the box was divided into 6 (3 x 2) roughly equal square compartments the result would be more usable.

Wooden Box
Compartments are too small
I cut the divider guides all the way across the board but they only need to extend to the top edge.

Wooden Box
Guide at Top of Box For Lid
I think this next detail is the most important thing I learnt that'll help make a more enjoyable design.  When the lid is inserted it's in contact with all four side panels and any misalignment during assembly or even expansion and contraction of the wood will cause the lid to catch on edges when inserted.  You can see in the image below that when inserting the panel in the back slot there's a small lip due to assembly misalignment.

Wooden Box
Misalignment of Back and Side Panels
This can also occur at the front.  To fix this, ideally the rebated guides in the sides should be tapered.  Let's say you have a 7 mm board for the lid and you're happy leaving 0.5 mm of clearance.  Instead of just routing a 7.5 mm slot, make it 8.5 mm at the back to allow for misalignment and then reduce it to 7.5 mm after an inch or two.  Then make the rebate in the front 8.5 mm wide.  By doing this the lid should slide in and out without hitting anything.

Wooden Box
Misalignment of Front and Side Panels
The top lid won't be perfectly flat either, it could bow up or down.  So you may want to make the front slot a little larger in the centre where it will bow the most.  You could also taper the sides of the front rebate to allow the lid to locate into the front slot smoothly.

Wooden Box
Curved Lid Not fitting into Front Slot
Dimensionwise, I was flying by the seat of my pants on this project and just making it up as I went.  Most of my rebates were 6 mm but that introduces a tiny problem.  You want the rebate for the dividers to be a small as possible.  If they're too deep, you leave a small hole that dust or insects can get into.  Just a minor thing.

Wooden Box
Divider Guide as Seen From the Top
While I was at it I made 8 of them. :-)  It took about three days of work and the the total price for each box comes to around $20.  The funny thing is that making 8 boxes takes about as long as making 6 boxes.  Most of the time was spent setting up tools, measuring and marking things.  That's partly why I'd like to use CNC equipment to cut out the parts for the boxes.  In the time it took me to make 8 boxes I could assemble 50 pre-cut boxes.

Wooden Box
Usage Example

Monday, August 22, 2016

Idea For A Mass Producible Wooden Storage Box

I like things to be organised.  Over time, I've found the best way to accomplish this is to store similar things in labelled boxes.  It looks neat and tidy and makes it easy to find exactly what you want when you want it.

The exact form factor of the boxes has so far been an iterative process where I learn the pros and cons of each design as I use it.  I currently use cardboard boxes, but the long term goal was always move to wooden boxes.  I have only a few requirements.  They need to be big enough to hold a sheet of A4 paper (297mm x 210mm), and they need to have a lid to prevent dust covering the items I want to store.

The title of this post mentions the term "Mass Producible".  I should clarify that I mean making about 100 boxes, not millions.  With that in mind, I also want to be able to use automated manufacturing methods like CNC routing and laser cutting to make the parts of the boxes.  It would be great if I could get some furniture grade plywood delivered to a workshop, have them cut the pieces, and all that was left was a bit of assembly.  I haven't been able to find that capability yet, but it'll happen one day.

So what have I come up with?  Nothing too ground breaking.  In the image below you can see that there are standard box joints in the corners.  For this job, box joints are pretty much the only way to go.  Although the image below has been rendered with a plain piece of timber, I actually want to use plywood and making the thickness of the ply as small as practical is important as it reduces the weight of and size of the box.  With thin pieces of ply, nailing or screwing into the ends can cause problems with splitting, the box joint eliminates this as an issue.  It also make assembly easy.  Glue and clamp.

Wooden Box
Storage Box with Sliding Lid

With the lid removed you can see the rebate that allows it to slide in and out.

Wooden Box
Rear View of Box with Lid Removed

With the back and side removed you can now see a couple of extra features.  There are grooves cut into the sides that allow removable dividers to be added and removed as needed.  The shape of the base is now visible as well.  Traditionally you would just cut a rebate all around the bottom for the base.  So why have I gone for the convoluted tabs?  Once again, plywood.  Depending on the depth of any rebate and the direction of the grain in that layer of the ply, there is a risk that when a heavy item is placed in the box, the ply could fail.  This stitches the base and sides together for greater strength.

Wooden Box
Rear view of Box with Back and Side Removed

Of course this creates some problems.  If you're laser cutting the tab holes and they go all the way through, everything is fine, but if they only go half way, they need to be routed and need t-bone fillets added to allow the tabs to be inserted.  This is because you can't cut an internal square corner with a router bit.

Wooden Box
Box with Base Removed

I don't have the capability to manufacture these at the moment.  Ideally I'd start off by routing all the features that don't go all the way through on a 1200mm x 2400mm sheet of plywood.  At this point it's still one sheet that's easy to move.  It would then be laser cut to produce the final pieces.  I don't even know if this is something that's done commonly.  The reason for this is that you need the nice square internal corners that a laser produces for nice box joints.  I might be able to play around with the joints to make it a one step process by routing though.

So what's next?  Like I said, I can't manufacture them they way I want yet.  That doesn't mean I can't play around with the form factor though.  Stay tuned.

Wednesday, August 10, 2016

"The directory name is invalid" on the NXP LPC19459 in USB mode

Note - If you've arrived at this page because you're trying to get data off an SD card or USB drive that gives the "The directory name is invalid" error, I suggest trying to access the file via a Linux virtual machine.

Nearly every device you buy now seems to have an ARM core processor in it somewhere.  They're affordable, powerful, and when surrounded by peripherals they make some pretty impressive microcontrollers.  Traditionally I've always been an AVR and PIC person, and they still have their place, but I'd be stupid to ignore such a massive section of the market.  For those reasons I thought it was time to start learning about ARM processors.  

For various reasons I decided to start with the OM13056 evaluation board from NXP that contains an LPC1549 ARM cortex-M3 micro.  I chose this particular device because it has an onboard CAN bus controller and flexible methods for updating the firmware.

ISP Modes

Depending on the state of the the ISP_0 and ISP_1 pins at boot time, the device can be programmed via the CAN controller, USART, or USB.  The USB mode is the one that interests me the most.  By booting into USB mode the device presents itself as a mass storage device to the computer that when mounted contains a file named firmware.bin that contains the firmware.  You can read this file or drag and drop a new file to the drive to overwrite it to load new firmware.  It's fairly common now, but this was new to me.  In the past I've built PIC and AVR programmers by hand to get my code onto a device and I hated it.  It always got in the way of the task I was actually trying to perform. So this was brilliant.  It would also allow me to make a device that a user could update without extra hardware.

Then reality set in.  I plugged it into my Windows 10 computer, rebooted it in USB mode and was faced with an error message stating that "The directory name is invalid".  I tried everything I could find online to try and fix it but got nowhere.  I didn't know if it was the device or my computer causing the problem, so I tried it in my old laptop.  This time it worked.  So the most you could say at this point is that there's something about the way the device presents itself as a USB drive that allows one computer to read it and not the other.  My desktop was a fresh install of windows 10 64-bit while my laptop is an 32-bit upgrade to windows 10 from windows 7, so maybe there's a driver issue.  Who knows?

error message
Error Message

I still didn't know if my desktop had a driver or hardware issue so I opened the drive in raw mode with a program called HxD.  It hasn't been upgraded in ages, but it's awesome.  Straight away you can see from a cursory glance that the first sector kind of looks what you'd expect the master boot record of a FAT file system to look like.  This tells me that the hardware is at least working to this level.  You could sit there and decode it by hand, but there are better ways to attack this.  "TO LINUX!!!" **Puts on cape and slides down pole into a secret cavern**

Hex data
Accessing the raw data on the USB with HxD

I installed a quick Ubuntu VM in virtual box and passed the "NXP LPC1XXX IFLASH" USB device to it.  This is just here in case anyone doesn't know how to do that.

USB pass through to VM
Pass the USB to the Virtual Machine

Success.  The drive mounts and I can access the file.  From this I surmised that the problem is probably a combination of things.  In some way, the MBR of the flash drive doesn't conform with the FAT standard 100% and the fresh install of Windows 10 is enforcing that rigorously, while the other systems are able to deal with what ever is wrong with it.

Ubuntu file explorer
USB drive mounts in the virtual machine

What else can we find out about the drive?  It's FAT-12 and the size of 264,192 bytes is as expected.  It may seem wrong as the LPC1549 has 256 kiB of memory and this is 258 kiB, but you need to realise that the first 2 kiB of the device is dynamically generated when the computer accesses it.  It's the MBR and FAT and doesn't really exist.  The on board USB boot loader wraps the flash memory up as a file named firmware.bin and presents it to the computer.

disk properties
Disk tool show that the dev board shows up as a FAT-12 partition

We can find out more info by imaging the drive with the dd command and running the file command on the image.  Warning! dd can do bad things, be careful when you use it.

dd if=/dev/sdb bs=512 count=1 of=mbr_usb.bin
file mbr_usb.bin

disk properties
Inspecting the master boot record

The next step was to run the testdisk utility over the drive.  I'm not able to say for certain that this is the problem, but it did show a couple of things as unusual.  Maybe one of these issues is causing my Windows problems.

disk properties
Inspecting the drive with testdisk

Unless this is just a random edge case I don't feel comfortable letting an end user use this method of firmware updating.  I'd much rather try my luck with the USART.