Advertisement

Friday, January 22, 2016

Uncanny Movie

I just finished watching the movie Uncanny on Netflix.  It's a science fiction movie about a guy working on artificial intelligence.  He created an android and made it as lifelike as possible.  He calls himself an illusionist.  The android is incredibly lifelike and creepy.

This movie appeals to me as someone who is into robotics, AI, making, and science in general.  It's an intellectual thriller.  I enjoyed watching it and would like to watch it again.  The ending was a surprise but more because of how unlikely it seems when you think about how the android and the maker acted during the week.

I am left with feeling confused and a bit creeped out at the same time.




Friday, January 1, 2016

Setting up Multiple WAP Routers on a Home Network

I have a main WAP / router (Netgear WNDR3700v4) in my house that connects to the cable modem (Motorola Surfboard SB6141) and the outside world.  I also have a second WAP (Cisco RV220W) and a wired-only router (D-Link EBR-2310) on my home network that extend the network.  Only the main router provides DHCP functionality.  The other devices connect to the main router through a LAN port.  This works fine but the secondary devices do not connect to an NTP time server.  They also will not look for firmware upgrades.  Both of these functions go through the WAN port.  Since the WAN port is not used, the device will not automatically update its time nor firmware.

Today, I figured out how to fix that problem.  I found some good information at this web site.  Basically, the way to setup a secondary router on a home network is to give the WAN port a static IP address on the main network and put the LAN ports on a different network.  The LAN ports can give out IP addresses using DHCP.  The secondary router will use NAT to route traffic from the LAN ports to the WAN port.  The router thinks the WAN port is connected to the internet and will use it to connect to the NTP time servers.

It is a good idea to turn on the feature to return a ping on the WAN port on the secondary router.  Also, turn on remote management so you can get to the router from the home network.

My devices are configured like this.

Netgear (main router)

  • WAN IP: DHCP from ISP
  • LAN IP: 192.168.0.1
  • DHCP: On
Cisco
  • WAN IP: 192.168.0.1
  • LAN IP: 192.168.1.1
  • Remote management: 192.168.1.1:443
  • DHCP: On
D-Link
  • WAN IP: 192.168.0.11
  • LAN IP: 192.168.2.1
  • Remote management: 192.168.2.1:8080
  • DHCP: On



Electric Toothbrush Storage

I have an electronic toothbrush.  There is no good way to store it.  The toothbrush is too big to fit in a normal toothbrush holder.  Having the toothbrush standup on the sink is not good because the water builds up on the bottom and creates slime.

I saw an article in a Family Handyman magazine about how to store an electronic toothbrush on a wall using a strip of metal and a magnet.  The article mentioned connecting a strip of metal to a wall, then using a neodymium magnet to attach to the metal.   The toothbrush simply clings to the magnet because it has metal in it.

I happen to have a bunch of neodymium magnets from computer hard drives in my stash of junk.  Those magnets are very strong and are attached to pieces of metal that have built-in mounting holes.  I attached one of those magnets to the wall in my bathroom using drywall screws.

One added benefit is that the magnet appears to charge the battery in the toothbrush.



Friday, December 18, 2015

Simple Basement Storage Platform

I was at the Milwaukee Makerspace for the last time this year and possibly for the next few months.  Tonight, I spent my time making some simple basement storage platforms in the woodshop.  Altogether, I made four platforms.  The materials needed was:

  • Two (2) eight foot long 2x6 boards
  • Two (2) two foot by four foot, 1/8 inch thick sheets of hardboard
  • A handful of nails
The Makerspace has several great woodcutting tools that made the job go very quickly.  In about an hour, I had four pretty nice looking platforms.  The plan is to give them to a friend of ours from our weekly Bible Study group.




Merry Christmas!

Friday, November 20, 2015

Injection Molding Machine Simulator

For the last month or so, I have been spending my weekly Makerspace time working on simulating an injection molding machine on a microprocessor.  This is a project for work.  I want to setup a test environment to work with Mattec, our MES software used to control injection molding machines in our plastic parts plants.  To make a proper test system, I would like to send signals from a simulated injection molding machine into the system.

Beaglebone Black Fail
I first started working with a Beaglebone Black.  I was able to write a simple python program to turn LEDs on an off at random times.  However, that program only worked once.  After the first time, I could not get it to work.  Not sure what went wrong.  I may have fried the BBB somehow.  It still boots, I can connect to it.  I can execute BoneScript code.  I just can't get any python code to work.

At some point, (may have been before I tried the python code but also certainly after) I tried to upgrade the OS on the BBB to the latest version of Debian dates 2015-03-01.  I followed the same instructions from the last time I did this.  I did not get any errors creating the SD card.  When I bootup the BBB in install mode, the lights start flashing.  All three LEDs are supposed to light solid when the install is done.  However, this never happens.  I've tried several times with no success.

Raspberry Pi and Basic Simulation Definition
So, I moved on to the Raspberry Pi.  I wrote a program to randomly turn LEDs on an off.  If I ever actually get to use this on my test system, rather then turning on the LEDs, the Pi will send an electrical signal to an interface unit.  There will be a signal to say that the fill process is complete, one to say a cycle is complete, and one to indicate that the last piece produced was scrap.

Classes
A part of functionfunctionfunctionthe process, I learned how to use a Class to store data.  I wish I would have learned about this earlier.  I love using arrays in other languages.  There is nothing really like an array in Python.  However, a class is even better than an array.  I made a class that represents a molding machine with sub-classes for the sensors on the machine.  If I want to access the cycle time for the machine, I simply access the data at IMM10.Cycle.AvgTime.  Very cool!

Down Event Probability Using a Poisson Distribution
The machine class has a function that will calculate the probability that a machine will go down during a given cycle.  It uses the poisson distribution function to determine this.  Just input the average number of cycles per month and the average number of down events that machine per month.  The poisson distribution function uses these numbers to determine the probability.  Excellent!

General Python Program Functionality
Multiple machines can be defined with different fill rates, cycle times, scrap probabilities, and down probabilities.  The program continuously simulates cycles for each machine.  It will send a signal when the fill part ends, then another signal when the complete cycle ends.  Next, it decides if the machine functionfunctionproduced scrap during that cycle.  If so, it sends that signal.  Finally, it determines if the machine when down at the end of the cycle.  If so, it sets a timer and waits for the down event to end before resetting the fill and cycle timers.

Determining Times Randomly Using a Normal Distribution and scipy
The time for the fill and cycle are randomly determined based on the average times for that machine. The probability calculation is not a simply random number generator.  It gets a random time that is within one standard deviation of the average, assuming that the probability has a normal distribution.  This is better than a purely random number between the minimum and maximum range.  The probability could be outside of that range but should be normally close to the average.  In a future release, I'd like to add in some kind of randomality to generate outliers.

In order to generate this kind of random number, I had to install a Python library called scipy (www.scipy.org). That library has a function called "percent point function" that will compute the inverse of the cumulative distribution function of a standard normal distribution.

I'm not exactly how the function works, but if I send it a random number between 0 and 1, and tell it to use a mean of 40 and 3 standard deviations, its sends back numbers that appear to be distributed around 40.

Here is one helpful link that explains more about using scipy in this way:

scipy can be installed on the Raspberry Pi simply by typing  
sudo apt-get install python-scipy
Future Enhancements
For now, when a machine goes down, the duration of the down event is a purely random number between 5 seconds and 4 hours.  In reality, most down time events last less than five minutes, but some can last for days or weeks.  I'd like to have a formula that will mostly pick down event durations that are short but could pick longer ones.  I can't figure that out just yet.

Another future enhancement would be read in machine and sensor definitions from a text file or some other source.  It would be cool if the source data could be managed with a web page.  Then, I could control the parameters of the device remotely.

Also, the Raspberry Pi outputs about 3 volts.  If I need to generate more volts or a higher current, I might have to make a circuit board with transistors.

This brings us up to date.  I'll add more about generating random downtime durations later.

Friday, October 9, 2015

FBI Exit Problem Fixed

I finished the first prototype for the MMS Photo-inator Xsi a few months back.  It will take a picture when someone presses the button.  Then, it displays the picture on the screen for a few seconds.  Next, it flashes the lights on the green and red buttons and waits for the person to press one.  If the person presses the red button, the program deletes the picture and resets.  If the person presses the green button, the program keeps the picture and resets.



One thing that I need the Photo-inator to do is stop displaying the picture if the person presses either the red or green button.  I have not been able to figure that out, until now.  

I tried sending a keystroke to the session but that did not work.  I also tried killing the process but that did not work.  I tried other software and solutions but could not find one.  I spent the last few months trying to figure this out.  It has been extremely frustrating.  Here is how I finally resolved the problem.

I heard that the uinput module for python will allow me to send keystrokes to a session.  I downloaded the source code from here: https://pypi.python.org/pypi/python-uinput

Before I could install the source code, I had to install a supporting program by typing
sudo apt-get install libudev.so

Next, I installed the source code by running
sudo python setup.py buildsudo python setup.py install
I could not get fbi to work in the python program.  Tried it from the terminal and it will not work either.  I keep getting an error message that says, "ioctl VT_GETSTATE: Inappropriate ioctl for device (not a linux console?)"

Used Ctrl-Alt-F1 to switch to tty1 .  Executing fbi on tty1 works perfectly.

If I have the python program execute this: "fbi -a -T 1 -t 1 BBB.jpeg", fbi will display the image.  The -T 1 tells fbi to display the program on tty1.  I need to specify this on my PC but it apparently did that by default when I ran the program on the Raspberry Pi. 

Next, I wrote a small python program to display a picture with fbi, wait a few seconds, then send a q to the uinput subsystem on Linux to simulate a user pressing the letter q.  This worked perfectly.

The test code looked like this:

#!/usr/bin/python
import subprocessimport psutilimport timeimport uinput

subprocess.call("fbi -a -T 1 -1 /home/ken/Pictures/BBB.jpeg", shell=True)time.sleep(3)
#Uinput testsevents = (    uinput.KEY_Q,    uinput.KEY_H,    uinput.KEY_L,    uinput.KEY_O,    )

device = uinput.Device(events)time.sleep(1)
device.emit_click(uinput.KEY_Q)
Finally, I modified the photo-inator program to use the uinput code.  I need to fire up the whole system to test it out.  I'll do that some other day.

Friday, August 7, 2015

I want to display a picture on the screen for at most 30 seconds.  If the user presses a button, the picture should no longer be displayed and the program should move on to the next step.

There are several options to do this.
  1. Display a picture in a gui user interface like xwindows
  2. Display the picture on a smaller monitor but use an LED screen as the user interface.
  3. Display a picture as part of another document from the command prompt
  4. Display a picture from the command prompt
I played around with some of the options.  Here are my notes from working on this.  They are not well organized.

Display a picture as part of another document from the command prompt
PDF
Need to make a PDF file.
Display a PDF file.
Close the PDF file on demand.

The Python Imaging Library or PIL might work.  It will display an image but it looks like it uses the computer's default image display program.  Might only work in windows.

Display a picture from the command prompt.
Some people said you could use fbi in another tty session.  fbi does have an option -T to display the image in a different tty.  That does work but it enters the commands at the current prompt on that session.

I can use fbi -t 5 -1 -a -T 2 <image.jpg> to display an image on the second tty and then exit.

Starting the fbi process does not make fbi the "session leader".  The shell is the session leader.  fbi is the process group leader for a process group containing only itself.  See this page for more details.

I started the fbi process on tty1. Then, went to tty2 and killed the process in tty1.  That worked.

I started the fbi process on tty1.  Then, killed it from a ssh session on my laptop.  That worked.  So, if I can just find the session number of the fbi session, I should be able to kill it.

Tried running this command to kill the fbi session:

ps axf | grep <process name> | grep -v grep | awk '{print "kill -9 " $1}' | sh

It locked up the tty sessions.  I could still access the pi using ssh but not with the keyboard.  Had to cycle power on the pi.

After rebooting, did the same thing several more times.  It worked every time.  Not sure what this means.

The psutil code has a function that will get a list of all the processes and put them in a dictionary.  I can use that function to find the process running fbi.  However, fbi just seems to mess up the process when it is kicked off from python.

Tried eog.  It only works with x windows.  Same with evince.

It looks like PDF files can only be viewed in x windows.

Maybe the tty idea will work without killing the process.  The idea would be to display the image in tty2 but switch back to tty1 when the user presses a button.

Googling this topic makes it look too complicated.