This is the third part of our Transfiguration Bustle from Americas Greatest Makers we were eliminated first on the show, but we always felt the maker community would appreciate our effort and thought that went into our project.
Unlike the earlier two instructables Color and Length this is more a work in progress. We will add videos and update the code for all instructables as we verify that everything works and we want to clarify how to make these devices and make amazing presentations. I used to have a friend who said "Perfect is the worst enemy of the good" which I interpreted as you could try to make things bettter and better heading for perfection but you run the risk of getting nothing even good.
One key concept in Control is that of a Finite State Machine or FSM. Usually this is described as a diagram where circles represent states and arrows show edges how you go from one state to another. This is a very powerful programming concept, but with the compilers we usually use this is a bit of work to implement. Experience programmers can code them quickly, but really we need to use the idea and then hide many details of controlling the Color and Length components.
We are going to change the language used for Finite State Machines a bit to suit our purposes but the concept is identical. And a rose by any other name would smell as sweet. Maybe sweeter in this case.
Instead of State we are going to use Look. It is the Look of the dress/scarf and it can only look one way at any point in time so it intuitively matches the idea of state from FSM.
Instead of Edge we are going to use Situation. While you are wearing your dress/scarf there are situations that can occur. You took 3 steps forward. You spun twice. It is after 9:00pm. These situations will cause the dress/scarf to change from one look to another.
So the diagram for this step is a design of the dress/scarf that includes 1 length mechanism tied to I2C of the Arduino 101 and 1 Color tied to pin 3 of the Arduino 101. You can probably conclude it starts in the Long Blue look then transfigures to the Spring Tea dress when you Spin, goes back to Long Blue if you take 3 steps. At 9:00pm it turns off.
It is a simple example but really all you need to get going on building much more complex interactions.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: What You Will Need
You will need
- Arduino 101, Other Arduino's could be used but we are using the Real Time Clock and the Accelerometers that just part of the Arduino 101. We will probably add BlueTooth so the clothing could react to situations from your phone. Also the Arduino compiler does not have the vector template class available to it always so you may need to paste in the minimal vector implementation that can be found.
- Length Mechanism See Previous Instructable
- Color Mechanism See Previous Instructable
- Patients for the authors
The Length mechanism is connect to the I2C bus and the Color is connected to pin 3. The Vin to the Arduino 101 and +Power wire of the Color and the Length are connected together. Similarly the Gnd from Arduino 101, Length and Color are connected together. Essentially 3 wires connects a Color and 3 wires connects a Length, and those wires can be then fed to the next Color or Lenght mechanism.
The picture is of an early prototype and is using a hobby servo. The code from this could be modified to use standard hobby servos but there are two issues with them. 1) They consume power to hold a position, that means bigger batteries and 2) if hold a position they will get hot and if they are not given a rest they will destroy themselves.
Our Length mechanism is "Non-Backdriveable" meaning that it can hold a position without power. It also means you cannot force the device back to a starting position you have to spin the device to the position you want. Part of the reason the Length have a "Nut" on the end of the screw that turns is so you can turn by hand when needed.
Step 2: The Code You Need You Understand
Lets jump into the code.
FiniteStateMachine is an example a FSM for the 1 Color and 1 Length example. It implements the FSM in the diagram in step 1. It needs to be compiled in the Arduino environment but you will have to add the Transfiguration.h file from the next step. You will also need to be using and Arduino environment that has the "Intel Curie Boards" based modules loaded through the board manager. Experimenting with the CurieIMU->StepCount, and CurieTime-> ReadTest would be great additional activities to make sure everything is working on the Arduino 101 and your environment can compile this code.
All the data associated with the Looks and Situations are part of an Occasion. In this code example we are saying the Ocassion is prom.
We need to define our colors for quick reference later. We define Black, Blue and Green. The colors are defined as how much Red, Green and Blue you want. Where 0 is the no Red for example and 255 is maximum Red.
We next define two Lengths we would like to quick reference. This is the length the mechanism will go to when requested.
Next we define some Situations we care about at prom. Spinning twice, taking 3 steps, or getting late. In the future it could be you get a text from the parents that turns the dress off.
We define 3 looks. Off, longBlue, and teaSpring.
As in all Ardiuno programs it is time to perform the setup activities. In our case we need to just connect ideas together.
The "off" look sets the Color to black and the Length to Long. LongBlue sets the color to blue and the Length to Long. Lastly the teaSpring is set to Color Green and Tea Short (ooops typo looks like it is Long)
Add the looks to the prom occasion, add the situations to the prom occasion.
Start with the LongBlue dress.
Now for the real heart of the interaction. Add the transitions from one Look to another based on the occurrence of a situation. prom.when(spin2,longBlue,teaSpring); is just describing the arrow from Long Blue Look to the Spring Tea look in the diagram.
Now give prom a chance to do its setup.
As in all Arduino programs it is time to give the loop instructions. The instructions the Arduino will do forever. In this case, run the prom.loop() function.
More details on that in the next step.
Step 3: The "magic" Behind Transfiguration Bustle Control
Most of the magic is just good programming. The names of the classes are chosen to make the FiniteStateMachine code readable by anybody. We could have given State for Look and Edge for Situation, but the code is just harder to understand. Transfiguration.h is just that same idea. You need to download the Transfiguration.h file and add it into your project files. This is usually the same folder as your .ino file. You will have to stop and restart the Arduino environment before it allow you to edit the file in the Arduino environment.
You don't need to do the items below it is just for those interested in what is in the Transfiguration.h file
Pragma once is just helping the compiler to know only use this file once.
Includes at the top bring in the NeoPixel, CurieIMU, CurieTime and the I2C functions.
The vector include is special. It is a set of routines that allow you to keep a collection of things. In our case it is a collection of Lengths, or Colors, or Looks. Basically every time you see vector you can read as a collection of BlahBlah.
Color class is really the software side of keeping the Red, Green and Blueness of the colors in your palette.
Colors is really a collection of colors for a Look. It has one magical function called transfigure which calculates a color between your last color and your current color over time. So the transitions from one color to another is not abrupt.
Length is just storing the length palette of options.
Lengths like Colors is a collection of Length and has a transfiguration function that is not as complicated as Colors.
A Look as you might expect has Colors and Lengths. So even though the demo code for the Finite State Machine only uses one Color and Length. This code is ready for as many as the Arduino 101 can handle.
#defines are just a way of making constants that take up no space on your Arduino.
Situation is the general idea of a situation that may occur. The key function is hasOccurred will be true if the situation has occurred.
Step, Spin and Time are just special versions of Situation. Some advanced programmers may wonder why the Situation, Step, Spin, and Time are done this way and the simple answer is readability. Happy to discuss further in an email.
Transition is a class that keeps the current look, the next look and what situation occurred that causes the transition.
updateStepCount and eventCallback are right from the CurieIMU->stepCount demo, minus some Serial Outptut.
Finally the Occasion class. A collection of Looks, A collection of Situations, and a collection of transition rule for going from one state to another.
getPeg, setPeg are just a way of noting a time when something occurred. We think of it as setting a peg in the ground in time and then seeing how far away from that peg are you.
Loop just goes through the situations looking to see if any have occurred and then checking that the Look matches a transition.
Setup does all the setup for the IMU, Time, Wire and NeoPixel
Amazingly that is it. It is 256 lines of code but really just implementation of ideas that each makes sense.
Step 4: Have Fun
The entire point of these 3 projects is to encourage people to explore programming in a new way. If you looked into the Infinity of Fractal Leaves on thingiverse you saw that 10 lines of code can generate amazingly natural shapes.
This project shows you that you can define your own way of getting a computer to do something that may not look like what you have seen before. Maybe it makes more sense, to you. This is how very early machines defined how they would behave. There is no reason to not still show its value to make something awe inspiring.
Why not a drawing tool for the programming?
You may wonder why a source code approach instead of a drawing approach. While I could go off into the weeds about composabiliy, or other esoteric ideas, the answer is much simpler. Writing text documents that then become the software we use every day is just the way it is done a very significant amount of time. And I personally believe it will not be replaced.
Step 5: Final Words From Transfiguration Bustle
This project is meant to get some people who do not think of themselves as a Computer Science person to start considering it. Computers are a infinitely flexible tool. The computer can become almost anything, and it can certainly emulate anything.
When I write computer programs I see myself as a creative person who is doing something that solves a problem for someone. If you need a robot to go into a failing nuclear facility that is a great endeavor. If you want a magical dress that changes shape, length and color that is no different.
But the endeavor for this set of instructables is to get a new group of people to consider Computer Science.
Specifically caring creative people.
Caring and creative are sometimes noted as traits that girls have that boys don't but that is just too simple. It is much more about making the spaces where computers are in schools and homes a creative space. A space where creating something is more valued than destroying something, even if the destruction is virtual. When I was growing up girls and boys did creative things on a computer. The computers did not do much so if the computer was going to do something interesting it was up to us. But it has changed. This set of instructables was created from an effort to change that back.
Feedback is always welcome.