Making Machines Listen

A place to discuss the science of computers and programs, from algorithms to computability.

Formal proofs preferred.

Moderators: phlip, Larson, Moderators General, Prelates

Making Machines Listen

Postby Ventanator » Wed Apr 27, 2011 2:47 am UTC

I had an assignment recently that tasked me with designing a "vending machine". I had to go through make my program have the ability to do everything that a typical vending machine would do, without an actual vending machine. Instead of pressing a button with a coke on it, I had the user press the number one.

About halfway through it struck me that I have no idea how we go from making something like my program to making an actual vending machine.

What makes that transition? Is there some sort of magic that only luminous grandmasters know of that allows a machine to understand my code?
User avatar
Ventanator
 
Posts: 158
Joined: Thu Mar 26, 2009 10:22 pm UTC

Re: Making Machines Listen

Postby scarecrovv » Wed Apr 27, 2011 3:20 am UTC

Any computer has some inputs and outputs. Your computer has a keyboard, and a screen, among other things. In a vending machine, there's a little keypad, a little LED display, and some motors to dispense food and drink. In your program, I imagine that when you want to dispense a coke, you call a function to print something on the screen, like "you get a coke!". In a real vending machine, your program would call a function that runs the motors in the appropriate order. It's just different peripherals on the computer.

The construction of those peripherals is the job of electrical engineers and mechanical engineers.
User avatar
scarecrovv
 
Posts: 588
Joined: Wed Jul 30, 2008 4:09 pm UTC
Location: Massachusetts

Re: Making Machines Listen

Postby Ankit1010 » Wed Apr 27, 2011 4:18 am UTC

I think you're talking about the whole transition between how some code you write can actually make the whole machine work at the level of circuits and stuff. In some sense, you can always kind of go deeper into that subject, its what Electrical and Computer Engineering is all about.
Ankit1010
 
Posts: 135
Joined: Fri Feb 11, 2011 11:32 am UTC

Re: Making Machines Listen

Postby scarecrovv » Wed Apr 27, 2011 7:30 am UTC

If you want some more detail, there are several schemes for computer programs to access IO devices. One of the most common is Memory Mapped IO. In this scheme, there are some fake memory addresses. When the CPU tries to write or read from these addresses, the hardware says "Ha ha ha! There's no memory here! You're gonna talk to an IO device instead!" At this point, the IO device can give the program some input if the CPU read from the fake memory location, or the IO device can take some output if the CPU wrote to that location.
User avatar
scarecrovv
 
Posts: 588
Joined: Wed Jul 30, 2008 4:09 pm UTC
Location: Massachusetts

Re: Making Machines Listen

Postby Ventanator » Wed Apr 27, 2011 2:03 pm UTC

scarecrovv wrote:Any computer has some inputs and outputs. Your computer has a keyboard, and a screen, among other things. In a vending machine, there's a little keypad, a little LED display, and some motors to dispense food and drink. In your program, I imagine that when you want to dispense a coke, you call a function to print something on the screen, like "you get a coke!". In a real vending machine, your program would call a function that runs the motors in the appropriate order. It's just different peripherals on the computer.

The construction of those peripherals is the job of electrical engineers and mechanical engineers.


I'd honestly never thought of that...psh.

How is the programming done for these little computers? I assume it's the same. And if I wanted to say...build a vending machine (I don't want a vending machine, I just want an example) how would I do it?
User avatar
Ventanator
 
Posts: 158
Joined: Thu Mar 26, 2009 10:22 pm UTC

Re: Making Machines Listen

Postby Xanthir » Wed Apr 27, 2011 4:47 pm UTC

Ventanator wrote:How is the programming done for these little computers? I assume it's the same. And if I wanted to say...build a vending machine (I don't want a vending machine, I just want an example) how would I do it?

The programming depends on the exact machine, and what your goals are. Some microcontrollers can run proper machine code, so you can just write C or whatever and load it into the machine's memory. Some are complex enough to run Java bytecode or similar. Others are so simple that they only support a specialized machine-code dialect that you have to program in directly (or use a specialized compiler). Finally, some are trivial and the "programming" is done by building circuitry directly, rather than storing instructions in memory.

I'm not big on microcontroller programming, but using stuff like an Arduino microcontroller seems to be the popular way to do hardware programming.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))
User avatar
Xanthir
My HERO!!!
 
Posts: 4023
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex

Re: Making Machines Listen

Postby Yakk » Wed Apr 27, 2011 7:02 pm UTC

What tends to happen today is that an honest-to-goodness computer is put in those machines. A computer with more processing power than the entire world had in 1940.

It then waits for someone to push a button, and turns on some motors, as its primary function.

It also tends to have diagnostic modes, keeps track of inventory and cash levels, possibly communicates back to a home office via telephone to request service calls (I'm low on coke! I have too much money! Someone knocked me over!) -- but that is just bonus.

And that coke machine works much like the one you wrote up, with input from some source (quite possibly that looks JUST LIKE your keyboard to your program, simply because it makes it easier to debug without the hardware!), and a "magic function" that sends signals to hardware (which on a development machine, would probably be emulated somehow).

...

An "old fashioned" hardware coke machine with transistors is not that different than writing a computer program, at the logic level. There are extra details that are annoying.

An electronics course at the high school level might cover this. As an example, they might have you build a traffic light intersection, where lights turn on and off by some logic.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.
User avatar
Yakk
 
Posts: 10064
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Making Machines Listen

Postby Moose Hole » Thu Apr 28, 2011 4:49 pm UTC

Looking at a coke machine from the hardware perspective, a motor needs a decent amount of power in order to operate. This power is turned on by switches (transistors). The switch is flipped by logic gates, which run at relatively low power. The logic gates are very similar to those found in a computer, so transitioning from a program running on a computer to those switches is fairly simple.
Moose Hole
 
Posts: 400
Joined: Fri Jul 09, 2010 1:34 pm UTC


Return to Computer Science

Who is online

Users browsing this forum: No registered users and 1 guest