Introducing GANce

This post is one in a series about GANce

In collaboration with Won Pound for his forthcoming album release via minaret records I was recently commissioned to lead an expedition into latent space, encountering intelligences of my own haphazard creation.

A word of warning:

This and subsequent posts as well as the GitHub etc. should be considered toy projects. Development thus far has been results-oriented, with my git HEAD following the confusing and exciting. The goal was to make interesting artistic assets for Won’s release, with as little bandwidth as possible devoted to overthinking the engineering side. This is a fun role-reversal, typically the things that leave my studio look more like brushes than paintings. In publishing this work, the expected outcome is also inverted from my typical desire to share engineering techniques and methods; I hope my sharing the results shifts your perspective on the possible ways to bushwhack through latent space.

So, with that out of the way the following post is a summary of development progress thus far. Here’s a demo:

There are a few repositories associated with this work:

  • GANce, the tool that creates the output images seen throughout this post.
  • Pitraiture, the utility to capture portraits for training.

If you’re uninterested in the hardware/software configurations for image capture and GPU work, you should skip to Synthesizing Images.

Continue reading →

Creature Capture | Variable Video Capture Length Code & Testing, Frame Rate Issues

So I’ve been working a lot in the past day in ironing out part of the night side loop (loop 3 in this diagram). Basically, it starts recording based on an input from a sensor and continues to record until these inputs stop occurring.

My test code looks like this

The interesting functions at work here are the following:

FilmDurationTrigger() Takes the period of time that will be filmed, in this example, it’s 5 seconds just to conserve time, but in application it will be 20 seconds. This code will pause for the input time, and continue to be paused upon inputs from GetContinueTrigger(). This delay allows the code to continue filming until there are no inputs.

In this example, GetContinueTrigger() returns a Boolean if a random event occurs, but in application it will return a Boolean based on the status of a motion detector.

I ran two tests, both of them produced separate results. The first one created a 10 second long video:

And the second created a 15 second long video:

These two test shows that variable capture length functionality works! As a note, the actual times on the output video varies from the amount of time that it’s designed to record for. This is because the variable frame rate nature of the video coming out of the camera module, it causes the videos to come out a little short, but they still contain all the frames of the amount of time desired to record, just scaled slightly by frame rate error.

Creature Capture | Stopping Raspivid After a Non-Predetermined Time

One of the biggest problems with the built in commands for using the Raspberry Pi Camera module is that you can’t stop a recording after an unknown time. You can record for a given number of seconds and that’s it. I have attempted to solve this problem by backgrounding the initial record process with a time of 27777.8 hours (99999999 seconds) when it’s time to stop recording, the process is manually killed using pkill.

Here is a test of my code, which I’ve called CameraModulePlus (written in python) which takes two videos, one for five seconds, and one for ten seconds, with a 10 second delay in between.

Here is a result of the 5 second duration test:

Here is a result of the 10 second duration test:

As you can see, it works pretty good for how barbaric it is. The full class for CameraModuleVideo can be found here. In the future, I’d like to encode a lot more data into the CameraModuleVideo class, things about time etc. Also I would like to monitor available space on the device to make sure there is enough space to record.

Creature Capture | Project Declaration & Top Level Flowchart

I’ve decided to embark on a video surveillance project! My family lives in a very rural part of the US, and constantly hear and see evidence of animals going crazy outside of my home at night. The goal of this project is to hopefully provide some kind of insight as to what animals actually live in my backyard.

Ideally, I want to monitor the yard using some kind if infrared motion detector. Upon a motion detection, an IR camera assisted by some IR spotlights would begin filming until it has been determined that there isn’t any more movement going on in yard. These clips would then be filed into a directory, and at the end of the night, they would be compiled and uploaded to YouTube. This video would then be sent to the user via email.

I’ve created the following flowchart to develop against as I begin implementing this idea.

I’ll be using a Raspberry Pi to implement this idea, a few months back I bought the IR camera module and haven’t used it for anything, this would be a good project to test it out.

There are a few hurtles that I’ll have to cross in order to make this project a success, like most groups of problems I deal with, they can be separated into hardware and software components.

Hardware

  1. Minimize false positives by strategically arranging motion detectors
  2. Make sure IR Spotlights are powerful enough to illuminate area
  3. Enclosure must be weatherproof & blend in with environment, Maine winters are brutal.

Software

  1. The Pi doesn’t have any built in software to take undetermined lengths of video.
  2. Must have a lot of error catching and other good OO concepts in order to ensure a long runtime.

I’ve actually come up with a routine for solving the first software problem I’ve listed, hopefully I’ll have an example of my solution in action later tonight.

Ideally, this project will have a working implementation completed by May 21, which is 7 days from now.

PiPlanter 2 | Plant Update and Daughter Board Migration

First, a video:

I’ve worked very hard since my last update to move all of the hardware that interfaces the Raspberry Pi with the plants (GPIO, ADC etc) from on board the Raspberry Pi using the GIPO to a daughterboard based around an Arduino.

This has been a lot of work to accomplish, but as of about a week ago, the transition was completed in it’s entirety and everything is operating totally normally without using any GIPO on the Pi.

This provides a portability for the platform that I haven’t been able to achieve so far. As the name of the project suggests, I’ve only used a Raspberry Pi to drive all of the hardware so far as well as do everything with the software. This transition opens up the possibility of using any computer running linux to be able to drive a PiPlanter if they have the board.

I’ve outlined the “PiPlanter Hardware Specification” in the current block diagram for the project. So if you have these parts, you can make a PiPlanter. The protocol for communicating between host computer and the Arduino is outlined here. I’ve decided to go with plain text serial using a rudimentary handshake to handle the communication. Pretty much all computers have a serial port, and the Arduino is very good at dealing with it as well.

One of the next steps that I take in this project would to be to design and fabricate PCB’s for specifically for this. This is certainly going to be a challenge for me, but it’s nothing I can’t handle. This also gives me the opportunity to maybe start selling PiPlanters which is exciting. I might need to change the name for obvious reasons…

Here are some nice photos of the updated setup:


All of the code and documentation for this version of the PiPlanter can be found here.

I am going on break from school from today, December 18th 2014 to on or around January 14th 2015. Now that the PiPlanter isn’t at my house, I can’t access the network remotely and make changes to the code. The next month will be a good stress test of the new daughterboard infrastructure. Hopefully it all goes well.

Thanks for reading!

PiPlanter 2 | Python Modules & Text Overlays

So in my last posting of the PiPlanter source code, the python script alone was 500 lines long. The intent with was to make things more modular and generic compared to the original version of the code that ran two years ago. Since the project has expanded a considerable amount since two summers ago, my goal of keeping everything short and concise isn’t really valid anymore so I’ve decided to split the code up into modules.

This improves a number of things, but it makes it kind of inconvenient to simply paste the full version of the source into a blog post. To remedy this, I’ll be utilizing www.esologic.com/source, something I made years ago to host things like fritzing schematics.

The newest publicly available source version can be found here: https://esologic.com/source/PiPlanter_2/ along with some documentation and schematics for each version to make sure everything can get set up properly. What do you think of this change? Will you miss the code updates in the body text of a blog post?

With all that out of the way, let’s talk about the actual changes I’ve made since the last post.

The first and foremost is that using Pillow, I’ve added a way to overlay text onto the timelapse frames like so:

Before

After

 

This was prompted by some strange behavior by the plants I noticed recently seen here:

I thought it was strange how the chive seemed to wilt and then stand back up and then wilt again, it would have been nice to be able to see the conditions in the room to try and determine what caused this. Hopefully I can catch some more behavior like this in the future.

Here is the new Image function with the text overly part included if you’re curious:

Now that I’ve got the PIL as part of this project, I’ll most likely start doing other manipulations / evaluations to the images in the future.

Okay! Thanks for reading.

PiPlanter 2 | Installing a 3rd Instance of the PiPlanter

Ten days ago I finished installing the third ever instance of the PiPlanter in a lab in the physics department at my college! I went with the the rack mounted design as I did this past summer, and am going to be growing Basil, Cilantro and Parsley as opposed to tomatoes. Here are some photos of the new setup:


There are a few major changes that come with this new instance. The first and foremost being the addition of LED grow lights. I’ll post a new version of the code with LED routines included when I think it’s polished enough. The second difference is that a tray of soil is being used as the growth medium for the plants as opposed to pots of soil. This will more than likely be the configuration I use moving forward. The final difference is the actual type of plants being grown. I’m moving away from tomatoes because there will be nothing to pollinate the flowers in the winter as well as the fact that I cook a lot and it will be neat to have spices that I can use on a day to day basis.

The first 10 days of growth has gone well. Here’s a video of them growing so far:

Thanks for reading!

PiPlanter 2 | Interfacing a Mikroelektronika CANSPI and an Arduino

The CANSPI board is a nice integration of the MCP2515 CAN Bus Controller and the MCP2551 CAN Bus Transceiver. To interface with these boards I’m using an Arduino Nano and the Seeed Studio CAN Bus Shield Library.

Here are some photos of the configuration, including the switch position on the CANSPI being used:

The wiring diagram goes as follows:

There are two parts of Arduino code, the sender and the receiver. The following code sends a sample piece of CAN data. Attach a potentiometer to A0, and twist it to see the differences in data in the receive code:

The following prints all CAN data received to the serial monitor:

Twist the potentiometer and see the change in data to see that it’s all working:

Thanks for reading!

PiPlanter 2 | DIY Lite Version Release!

Since I returned to college the PiPlanter has been running without me having to do any maintenance on it at all. The plants are still alive and growing and all processes associated with the PiPlanter are still going. I figure now is a good a time as any to bring together all of the work I’ve done to till this point in one concise post.

This does NOT mean I’m done working on future versions of the PiPlanter. I’ll hopefully write another post stating goals for the future sometime soon. Now onto the build tutorial.


 

The Hardware

 

First, the hardware of the project. A good place to start would be the parts list:

In the previous version of the PiPlanter, I didn’t have a concrete parts list for the project. Hopefully I’ll be able to keep this spreadsheet updated if the project changes. A lot of these components are mix and match, you could use pretty much any pump (The math for volumetric pumping is done with this pump) or any tubing or any power supply that can do 12v and 5v. A computer PSU would work great as well.

This is the hookup guide for the system:

(Thanks to tamps for the help!)

The two sets of header blocks are to be replaced by the moisture sensors, and the motor replaced with the pump.

For a physical configuration, I’ve found through multiple times doing this that mounting it on a wire rack works the best as seen here:

Edit (10/19/2014) Here is the same group of plants two months later without any direct human interaction. They grew from the light in the window and used up all of the water in the reservoir which was totally filled before I left.

To distribute the water to the plants, attach the vinyl tubing to the outflow of the pump and seal off the other end of the outflow tube. Run the tubing along the plants and drill holes wherever you’d like the water to exit.

You’ll also need to install the camera module in the Pi and point it wherever you’d like the frame of the photo to be.

 

The Software

As a preface, I’d like to at first say that this software was written entirely by me. I’ve never had any formal training in programming of any kind, so if there are obvious flaws with my code please let me know. That being said, I’ve found that this system is very effective and has worked for me and kept my plants alive for months.

All of this runs off of a base install of raspian on a raspberry pi model b.

There three major parts to the software. First, the prerequisites:

You’ll need to enable SPI on your Pi in order to use the MCP3008 ADC. Do this by running the following commands:

Comment out the spi-bcm2708 line so it looks like this:

Then run this to make it more permanent.

And finally reboot your Pi with:

Then the php code that renders the pChart graph. More details for installing pChart here and officially here.

And now the star of the show, the python script:

Before running, make sure you make the following changes to the script:

You’ll need set up access to twitter API’s, seen here. You’ll need to input your information about your twitter app into into 331-334 of this script.

You’ll need to input information about your YouTube account on line 429

On line 473 you’ll need to input your mysql information.

 

Output Demos

The PiPlanter is very connected. It renders graphs of data, takes images and renders timelapse videos.

Here’s a standard tweet showing the plants:

Here’s a tweet showing a day’s worth of data in  a  graph render:

Here’s a tweet showing a week’s worth of data in a graph render:

Here’s a timelapse video of three days:

Follow @PiPlanter_Bot for updates on my plants.

That’s pretty much it! Please feel free to modify this code for any use you’d like.

All of my research on this project can be found here.

Thanks for reading, and please leave a comment if you like my work!

PiPlanter 2 | Updating Dependencies

In addition to the directions in this post on getting the ADC working, the following must be run to get the current version of the PiPlanter up and running.