Monday, November 19, 2012

Client / Server Software

In this post, I'm going to do a brief sort of how it works explanation for client server software.

The reason that I'm doing this is that the next coding lesson will be about creating network sockets on Unix/Linux systems in order to create network software.

There is (as ever) a lot of theory that goes into exactly how network connections etc work.

Rather that try to show horn all that into a single project I thought it'd be easier to post some theory first.

So first, we'll define what is a client, and what's a server.

A server in the context of network software is a program that listens for connections, accepts connections and serves content to those connections, (or receives content from those connections).

A client in the context of network software is a program that connects to another piece of software.

The server listens on specified ports awaiting connections,
The client connects to software that it listening on specified ports.


The network model layers
There is a standard for connecting systems, this is a 7 layer stack called the OSI model, (OSI is Open Systems Interconnection)

Each layer serves the layer above it.

This means that no higher numbered level can exist without the layer below it also existing.
(but you can have lower levels existing withough higher levels in your communication.)

The layers of the OSI model are very well documented elsewhere on the internet, it's a pretty broad subject, and I would suggest reading about it by searching for OSI model, It's practically impossible to break down to a simple blog post.

What is important is that the lessons that I'll be posting now will be using Layer 5 -the session layer of the OSI model. we'll be creating sockets that can be either TCP or UDP, telling the sockets what port we want them to listen on or what port we want them to connect to.
On top of the session level is the presentation layer, this presentation layer sorts out how the data is passed to and from the application layer (your web browser using HTTP) to the session layer (where the IP address is applied) and from there passed down to the transmission layer where it goes off into the world. the presentation layer may not always be used, but when it is used, it generally is used for compression or encryption, or translating between different character sets.

Because we will be accessing the OSI model at level 5 what you do at level six is up to you.

for example you could produce a fairly simple encryption protocol by bit shifting characters such that they appear as gibberish to anybody looking at the packets.
hello world >> ifmmp vlsme
then at the other end, your socket receives gibberish, at layer 5, then your presentation layer (layer 6) sorts that gibberish into real text by bit shifting the other way. and then this data is passed up to your next layer.

The application layer.
The application layer is where many common protocols sit. in general these protocols implement a way for your applications to request data from servers.

A web browser for example uses the HyperText Transfer Protocol.
this is a protocol, (an agreed standard) for the transmission of hyper text.

In general it works a bit like this (very simplistic)
you write https://www.google.com in your address bar.
your application layer passes to your presentation layer.

access www.google.com on port 80 and GET ./ (get the default page at this address)

The presentation layer receives this command, and because it's https (secure) it encrypts your request (GET ./). and passes it to the session layer.

The session layer opens a socket connection to www.google.com on port 80, and passes the data, (which is now encrypted -though the session layer doesn't care all it sees it's a data stream).

If we hadn't encrypted the data then the presentation layer wouldn't have been used at all.


Another thing that is important in these upcoming lessons is that this code will not be portable.

That is that the code will be platform specific, for windows or Linux/Unix systems.

The Linux/Unix software should work on Macs, and will work on raspberry pi devices, but will not work on windows, and the windows software will work on windows, but nothing else.

However the general theory for each is the same.


How socket connections work.
A socket is basically like a data stream, in the same way that we could read or write files, or print to the console using a data stream, we can read and write data to a network socket.


Your server listens on a port, (for a web server this may be port 80).
Your client software creates a port with a random port number, and connects to the server on the service port, it sends information about the port it will be listening on, and it's address
The server accepts the connection on the service port and creates a new port to reply from,
The server send a response from the new port to the client on the port that it established communication to the server on.

The client may then send a message, and the server will respond.

This will be more obvious when I get into the code, but that's going to happen another time.



Monday, November 12, 2012

How to level the bed of a Solidoodle 3d Printer

I'm sure that there are plenty of other printers that can be managed in the same way, but these instructions are based on the process that I've used to figure out how to level the bed of the Solidoodle 2 printer.

To start with you can leave the printer on and you can use the software called Pronterface to move the extruder about, but I do think it's easier to just hit the button in pronterface labelled motors off, and then move the print head about by hand. you won't damage the printer this way, but still be careful!

The first thing to do I guess is describe how the bed it put together.

There is a flat platform on which the bed assembly is mounted, on the underside of this platform is a series of nuts. going into these nuts are bolts that obviously can move up and down in the nuts.

The bolts are threaded through the metal bed and into the bolts.
Between the bolts and the platform that the bed sits on are some springs, these ensure that the bed in pushed as high as it can go on the bolts, so when the bolts are adjusted in and out of the nuts, the bed moves.

There is 1 bolt at the back and 2 bolts at the front.

To start with push the extruder head to the centre and back of the platform.


This is where you're going to alter the front to back level, Adjust the screw that's in the centre at the back until the platform is about the width of a credit card away from the platform, (in fact use a credit card). turn the screw anti clockwise to make the bed higher and clockwise to make the bed lower.

On the Solidoodle 2 you need to use a 2.5mm hex wrench to alter the bed.

Once the level at the back of the bed has been set move the extruder head to the very front and right corner of the print head, this is where you'll set-up the left/right tilt of the print bed.

Once you've adjusted this screw so that the printer head is about 1 credit cards width from the printer move the extruder to the left most side of the front and adjust that side.


Why credit card.
I'm suggesting setting the print head about a credit cards width during the process of levelling the bed because if you aim straight for 0.3mm and the front is slightly higher the first thing you're going to do is scratch the kapton tape when you move the print head from the levelled back to the much higher front.

Having slightly more space between the head and the bed allows you to see that the head is getting closer before it's too late.

Setting the bed height.
Now that you have the bed level you need to set the bed height, to do this the Solidoodle company suggest using a thin piece of card, like a metro card.

However, I think that if you have a set of feeler gauges you should use them, use the 0.3mm gauge.

Home the head in the X and Y axis (which put the head slightly off the bed, now home the bed on the Z axis (this will raise the bed)

Hit the motors off button so that you can move the extruder around.

Carefully move the extruder towards the bed.

If the bed if much higher than the extruder (and trying to move the print head over the bed won't work as the print head will just hit the bed then you need to look to the Z-stop screw at the back, turn it clock wise to make the bed home to a lower height.

Ideally you should have the bed ship with a Z stop set that the extruder won't hit the bed when you hit Z-Home for the first time.

In this case you can move the extruder to the middle of the bed, hit Z home.
insert your gauge in the gap.

If the gap is to big, move the Z-stop screw on the back wall of the printer anticlockwise. then press home again until you have the correct gap between the print head and the print bed.


Monday, November 05, 2012

The solidoodle has landed

This is the 100th blog post, which I find a little surprising in a way first because I started this blog over 6 years ago, and it's taken me this long to write 100 things -surely I should have gotten here sooner!, but secondly because I never really imagined that I'd have so much to say. -surely I should never have gotten here!!

But a better cause for celebration is that my printer finally arrived. (that I ordered in JULY with a promise of 8 - 10 weeks shipping)

Given that I live in the UK and it's November 5th, that also means that my celebration blog post and Solidoodle arrival will be met with actual fireworks, (though technically not for celebrating the fact that I finally have a 3d printer!)

So I thought in the interests of anyone still waiting for theirs, (and anyone considering ordering) I thought I'd write something about my impressions of the printer.
I guess the first thing to do is get the biggest complaint out of the way first.

Ordering/Waiting/Shipping:
I ordered my printer on July 13th, and was told that there would be a 8-10 week wait.
16 weeks later I was still twiddling my thumbs...
It was November 3rd when I finally got my printer.
My printer appears to have shipped out of order, and there doesn't seem to be a reason for this, (support have said that the order was not expedited).
From my point of view, I was not an early-order-er. I ordered after the machine was in production and had started shipping.
I was made a promise that it would be 8-10 weeks, then was made more promises via the publicly released shipping updates time after time, that were also broken.

Support:
I only contacted support I believe 3 or 4 times, (and one of those times was to ask for a tracking number)
Generally, I found support to be quick to respond, (when contacted via email), but also fast to make promises. Initially their promises about shipping seemed completely at odds with what was being said publicly, (as in they were offering faster shipping times than the already seemingly unrealistically fast shipping notices that were being released), but they did come through on that promise.
my only two problems with contacting support were:
Queries made via the web form on the solidoodle site were completely ignored.
(I know that the queries are monitored as my pre-sales queries were answered using this form).
Secondly, one email was either lost, or ignored.

Thankfully, I've had no issues since I got my tracking number, but I do have to say I am not relishing the idea of having to contact support, not knowing if my emails have gone missing, I'm in a different time zone, (different continent even) so I don't expect instant replies. but that does also mean that if I send a message I won't know if it's lost or ignored for a few days.
So far as the whole experience those are my only two gripes.
and I can sum it up in just one word. COMMUNICATION,

I really hope that communication improves, that is, that communication about shipping becomes more accurate, that decisions that seemingly don't make sense are communicated more effectually. and really, I hope that if emails are going missing with such frequency, that you guys get a better email provider.
The facts are I'm happy with my machine, (as you'll find out as you read below), but given the communication issues, personally I wouldn't recommend buying this printer to a friend. Perhaps when things are settled and sorted, the back order is completely cleared etc, then I'd recommend a friend buys one, but I don't want to be the reason for someone getting caught up in the current fiasco! having to worry about if they are ever going to get their printer, worrying about if they can even believe what the support people are telling them about the printer.
To be honest an extra six weeks wait actually seems a bit trivial (now that I have the device) but it's the lack of communication that really irked me.
Import duties:
For anyone interested, import fees to the UK were £93.22 (~$148 USD) there is no duty to pay on the machine, the fees are made entirely of VAT (Sales Tax) and processing fees from the post office.

Now only the machine:
Packaging:
There have been a bunch of complaints about packaging, and people getting machines that have been broken, support said some time ago that they would be changing the packaging set-up, and I believe that what they have done has been a brilliant improvement.
Firstly, the outside box was a decent size of card, (about 1/4" corrugated) there was no damage to this
the inside of the box was packed about 3" deep in every direction with Styrofoam peanuts.
the printer was then wrapped in bubble wrap.



the plexi-glass door was covered in a brown plastic coating, (from the manufacturer) and so had absolutely no scratches.
unpon taking the machine out of the box...

the print head appeared to be centred, and bubble wrap had been rolled into little tubes which supported the print head, the bed and all the moving parts.
the roll of filament was inside the machine (under the bed which was raised to the top) and also held in place with rolls of bubble wrap.


Shipping the filament inside the box was a great thing for me, if only because it meant that not only did the filament arrive WITH the printer, - so I was ready to go, it also meant that there was no second box to worry about, no second duty fees, no second postal service fees for the import, and no second drive to the post office.
Considering that some machines couldn't get across the states without coming to pieces, and yet with this new packaging regime this printer has managed to get.
across the state, onto a boat, across the Atlantic, (on the storm front of a hurricane), then across Britain, through various depots, etc, this appears to be a huge improvement!)
So for packaging, I can only offer a ten out of ten!

What's in the box:
inside the box, there is a power supply cord. - it's got a European rather than UK plug on it, but that's not a problem the plug on the machine is a C5 connector and so I've plenty of spares laying around.
there is some paper, telling you what's in the box, your order inventory, a sheet saying welcome to the solidoodle family (a nice if not cheesy touch).
There was a small roll of starter filament.
when I say small roll.
there were reports that some people got a test length of a few inches...

like that.
approximately enough to fashion a new teste for a gnat.
however, there was a generous roll of starter filament,

There was no tool kit, (this was listed on the order form when I ordered that I'd get a printer and a free tool kit containing all the tools I'd need -small scrapper/hex wrench/little brush for cleaning the machine)- but I do have more than enough tools of my own.

tools I'd think that a person could want are
1x 2.m mm hex wrench
1x cross head screwdriver (for removing the case)
1x craft knife for cutting and trimming printed stuff
1 x craft knife with chisel blade for popping prints off the platform.
(for day to day use)
and if you have delicate fingers maybe some tweezers.
- I can't say what tools you're going to need to strip down and rebuild your machine because I haven't done that yet!
To set the machine up I used some regular auto mechanics type feeler gauges. these are really cheap.
as for the tweezers, I generally don't have a problem with touching hot things, - years of burning myself with soldering irons appears to have dulled my senses, so i've been pulling and seeped out or built up plastic off the hot end with my fingers.
Weirdly also in the box was a random m3 nut. it was stuck to the doors protective layer.
When I came to remove the case to install the filament, I found that there was an m3 bolt missing. -not an issue I have plenty of these, but does show a bit of a lack of detail.

Set Up:
The software install instructions are remarkably easy to follow. - I followed the ones on the solidoodle website.
They are literally step by step from opening the box to printing, the only thing that was missing was the instructions appeared to go straight from install this software, to this is how you print. ignoring details on how to level the bed.
Levelling the bed is however pretty straight forward. in fact so straight forward I just figured out how to do it myself.
First I moved the X motor forward and back, and hit X home. - it went the right way.
then I moved the Y forward and back then hit Y home, - it also went the correct way.
same approach with Z, when Z finally homed to seemed apparent that had I decided to start with this axis I'd have a hole in my kapton, and a bent extruder.
so I altered the z-stop.

Then we come to the actual bed levelling.
it's easy enough to level the bed, I use proper feeler gauges, (which I imagine made it easier.)
It took about two minutes to level all four corners.
but then I had the idea to run the extruder over the length of the build area, clearance ranged from a very tight 0.3mm to loose 0.4mm not a huge amount of deflection. (I could measure exactly, (either with feeler gauges, or using a dial gauge -which I bought especially for this machine! -but didn't [yet]).

Printing:
for my test print I decided that I should print something that would be easy to measure, have some height, involve a complex shape (round), and of course something that I could print to appease the missus for the large amount of money that I'd just spend on a toy.
I went with a heart shaped box smile
printing was pretty straight forward, I left everything on default settings, (so there is a raft), the printer zeros to the bed middle, and then prints in the top corner.
-weird, the y axis homing direction appears to be fixed, but not the start position co-ordinates.

printing happens exactly correctly first time.
and second time.
and third time.

and they fit together. smile

the print measures just fine.
default settings, out of the box, the solidoodle seems pretty well dialled in, the round parts seem round.
the width is the 40mm is should be, the wall thickness is 2mm over the whole shape.
the box lid is printed and is exactly the correct size, (a tolerance fit) to the box. and includes a 2mm overhang of 90degrees/0 degrees (depends where you measure from). - which the printer coped with very well.


further printing
printing more things however does show up some problems in this printer.
I don't need a raft for example, but when the raft is removed, I find that it is difficult to ensure that the first layer extrudes properly, a little more pre feed is needed from the default profile, (this also means a tiny section of the raft is also missing, but that never shows up as a problem).
the second problem is, whilst the bed deflection is pretty minute at a tenth of a millimetre, this does mean that printing can become problematic, the middle is raised high, so prints stick here very well, and yet have great trouble sticking at the edge.
Then there is the problem of heating.

Seriously, I feel I need to turn on the machine, then watch some tele, make a coffee, eat dinner then it might just be ready to heat. The bed has the 0 - 100 performance of my first car. (which was French, and shite).
Another issue, the heat does not spread evenly across the bed.
I printed a small round shape with a star shaped hole through it,
at the centre, the print was so warm on the bed that it was distorted. (-but glossy smooth)
at the edges, there was so little heat that it has trouble sticking and strands were clearly visible. -though bed height may have been an issue here also.

Machine Design:
Over all I think that the machine is designed exceptionally well, everything holds together neat and tidy, it's astonishingly quiet, I expected it to be about as loud as a standard ink jet printer, but can happily say it seems quieter, and the noise that it does make is not as monotonous as an inkjet printer either!!
It looks like it'll take some abuse, the steel frame is very well put together, I've not tried standing on it, but I believe the claim that it would support an adult standing on it!
The machine looks deceptively simple, and I imagine will be very easy to maintain.
I think that the strong frame really sets this machine apart from other machines but at the same time it looks like it really reduces the amount of space that there is to work inside the machine. - I mean there isn't a lot of space for bolt on modifications.

So all in all, I'm very happy with my machine.
There are a couple of snags:
The first is that the circuit board is very exposed, in shipping some of the components had bent, I've bent them back, but I obviously don't want to constantly be bending component legs cause they'll fatigue and snap.

A cover will fix this, and this will be high on my list of things to print.
(I'm also going to get some cable management to sort that lot out!!)
Second, the x stop switch leads rub against the side of the case, the case has a rough texture so eventually this will wear through the leads.
as a temporary fix I've put some parcel tape on the inside of the case. this doesn't stop the rubbing, but does at least provide a smooth surface so the rubbing should not be a problem. - though I may investigate some cable routing in the future.
Third, loading the filament is a bit of a mission with the case on. it's not a problem to remove the case, but I'm thinking of installing a hatch in the top for easy access.

Fourth the bed. as I said above, it's not level, does not heat at all evenly and takes ages to come up to temperature. I believe that the fix for this is going to involve.
A relay, a second power supply, nichrome wire, and a sheet of glass.
Fifth and finally.
Communication.
I'm not completely sure that the pretty sour taste of my first third of a year of being a part of "the solidoodle family" will ever truly leave me.

so all in all.
Is the machine perfect?
No, but it's pretty darn close, and for the money it's amazing...
If you want to print out generic tat -like the heart shaped box then it'll suit your purpose. if you want to try printing small parts with some intricate details you're going to need to fettle things.

Monday, October 29, 2012

Electronics lessons: Quine McCluskey

So I've looked at boolean algebra, and karnaugh maps.

What you may have realised is, first, binary systems become very big very fast.

But second, Boolean algebra, while useful has some pretty head churning limitations, feasibly there are no limitations, practically it's extraordinarily hard to be able to see what reductions may be created when dealing with more than three or four terms.

Karnaugh maps were a lot easier, yes they did require you to keep your wits about you whilst filling them in, the four by four map was filled logically as row 1 column1, row2 column1, row4 column 1, row 3 column 1. this carried on, but you filled column 1, then 2 then 4 then 3. so you sort of feel like you're jumping all over the place, and the logically last filled cell is at the middle of the table.

On top of that there is also the problem that karnaugh maps have a limitation on the amount of inputs that you can deal with practically, (it's difficult to use with a large number of inputs)

Now I'm going to briefly cover a algorithm called Quine McCluskey.

What makes this different is that it's expressed in a tabular formation. except rather than drawing boxes around the table we look for the number of ones in a given row where the output is true.

In order to demonstrate this I'm going to go back to the seven segment display. remember that first table that showed for each state 0 -15 what the 7 output segments on the 7 segment display needed to show;

0 = 0000 = 1 2 3    5 6 7
1 = 0001 =       3          7
2 = 0010 = 1    3 4 5 6
3 = 0011 = 1    3 4    6 7
4 = 0100 =    2 3 4       7
5 = 0101 = 1 2    4    6 7
6 = 0110 = 1 2    4 5 6 7
7 = 0111 = 1    3          7
8 = 1000 = 1 2 3 4 5 6 7
9 = 1001 = 1 2 3 4    6 7
a = 1010 = 1 2 3 4 5    7
b = 1011 = 1 2    4 5 6 7
c = 1100 = 1 2       5 6
d = 1101 =       3 4 5 6 7
e = 1110 = 1 2    4 5 6
f =  1111 = 1 2    4 5

We'll start the demonstration of Quine McCluskey by looking at the table of outputs for segment 1 of the seven segment display.

Then we draw a new table.
This table looks at the number of 1's in a state,
then the name of the state, (which is called a minterm)
and the binary representation of the state.

Now we look at the minterms and see which ones differ by only one bit.
Then we re-write these terms, using a dash to signify the bit that does not matter.

Look at minterms m14 (1110) and m15 (1111)
These are re-written as m(14 15) 111-

So you add these into that first table now, just a column along.
Mark any min term that cannot be combined, in this first case all minterms can be reduced.

OK, so now we have a table that has our first reduced minterms
It looks like we've got more work to do, yes it does look more complex than when we started, but honestly this is reducing the table!!

Now we need to combine our combined minterms.

To combine the minterms first we looked at where the states were just one bit out like m6[0110] and m14[1110]. became m(6, 14) [-110]
also m15[1111] and m7[0111] became m(7,15) [-111]

now we need to look at the conbined minterms where the dashes are in the same place and that only differ by one bit.

so:
m(6, 14) [-110]
m(7,15) [-111]

becomes
m(6, 7, 14, 15) [-11-]

We can conbine -010 and -110 or -011 or -000, as the dash is in the same place and they only differ by one bit
we can't combine -010 with -111 or -001 or -100 as there are two bits different, and we certainly can't combine -010 with -101 as that's three bit different.

We can't combine -010 with 001- as teh dash is in the wrong place for conbination

To start with just read down the chart and fill in ALL possibilities, we'll remove the repeated values later.

Now we can delete duplicates.

So the table has gotten a little smaller, and we can also see that m(5,7) is reduced as it's going to get. so we but an X next to this.

Now we start looking at the table to see where two dashes match but terms differ by only one value.

m(2,6,10,14) = [- - 1    0]
m(3,7,11,15) = [- - 1 1]

becomes m(2, 3, 6, 7, 10, 11, 14, 15) [ - - 1 - ]

In other words all of these terms can be reduced to the expression C

When you've finished matching the pairs your table should look like this:

now you can see that

m(2,3,6,7,10,11,14,15) - - 1 -
m(2,3,10,11,6,7,14,15) - - 1 - =>m(2,3,6,7,10,11,14,15) - - 1 -
m(2,6,10,14,3,7,11,15) - - 1 - =>m(2,3,6,7,10,11,14,15) - - 1 -

When we organise the minterms in numerical order

I highlighted the none combinable terms, and you can see that since we only have one term left there are no more combinations that can be made.

m(5,7)
m(8,10,12,14)
m(0,2,8,10)
m(2,3,6,7,10,11,14,15)

These minterms represent our prime implicants.
So now we draw a table listing the reduced/combined minterms from the table above.
The states, and their representations
This is called a prime implicant chart.

What this chart represents is the states that must be true.

This example doesn't lead well to what needs to happen next so for a moment pretend that the chart looks like this:

Now we can see that there is minterm2 that is common to two different outputs,
the 8 in the second statement can also be covered by one of the other statements, and the 10 can be covered too.

(so the statement relating to m(2,8,10) [-0-0]{/b./d} could be ignored as it would be covered in other statements.)

In this case where we have a statement that cannot be covered then it's an essential prime implicant, statements where the output states are covered by other statements are non-essential and can be left out.

Back in the real world we do have a minterm 0 on that second statement.

So it looks like they are ALL essential prime implicants.

so our output is m(5,7) OR m(0,2,8,10) OR m(8,10,12,14) + m(2,3,6,7,10,11,14,15)
looking at the values at the end this makes

m(5,7) = (/A . B .D) (the dash in C means C or NOT C, and as we know, A . B + A . /B = A

So we can write out the expression for the gates as:
Q1 = /A . B . D + /B . /D + A . /D + C