FNR – BubbleBoy Behaviour AI
This week and this Friday Night Robotics I was working on a behaviour AI for the newly refurbished BubbleBoy! It is much easier to design an AI that you know will be interactable with thew orld! Without the headbobbing capability of BubbleBoy, this effort would not be worth it.
BubbleBoy’s behaviour is primarily focused on food and water. BubbleBoy lives its anthropomorphized life just be be fed/watered! This means that BubbleBoy will want to know when it will expect to be fed, so that way it can headbob at the most optimal times. Being fed/watered is having a button pressed on BubbleBoy’s green stage area (the part with the blue and white LCD).
BubbleBoy will have three sensors, and a rudimentary measure time. The three sensors are the LDR, lid switch, and Xbee. All of these are onboard the robot (except for the Xbee which isn’t implemented yet).
Here’s a broad flowchart of the behaviour, which I will then explain below in detail.

-
Creating the Expectation
-
Pattern Finding
-
Determining the Sensor to Use
-
Calculating the Cost Adjustment
-
Following the Expectation
-
Real-World Behaviors
-
Last part of Following the Expectation
This is the observatory phase. BubbleBoy initially does not have any expectation of when to be fed, so it waits around. While it is waiting, its collecting data from all of the sensors and storing them to an array. There has to be 10 numbers in the array for each sensor before BubbleBoy can proceed to the next stage, pattern finding. Once this is fulfilled, and if BubbleBoy is fed/watered, then it goes on to find a pattern.
BubbleBoy is seen as a simple robot. Thereby, its pattern finding is relatively simple as well. The main idea is to check each sensor’s array and see if there is a pattern within the residuals. Meaning, if looking for a sequential pattern, the array would be iterated through (starting at i=0, stopping after i=8), and i+1 would be subtracted from i. An average of the residual change would be calculated at the same time. The array would be iterated through again, this time to count how many items are within +- 10% of the residual average. If the count is above 7, then it is said that there is a sequential pattern in there.
The same process is done for a secondary pattern, and a ‘thirdary’ pattern. Meaning, every 2nd number and 3rd number is checked to see if there is a pattern. It also goes through and checks with offsets, just incase the pattern is “even/odd/whatever”.
If there are no patterns, a random primary sensor is chosen for BubbleBoy to work with.
A problem exists in determining which pattern for which sensor to trust the most. A thirdary pattern for a photosensor is less dependable than a sequential pattern for a lid switch. This is handled in the next step.
The sensor with whatever pattern to follow is chosen through a Bayes Filter. This allows for a simple specification of confidence levels for a given sense resulting in a particular state through a table where all rows add up to 1.0. The sense columns are the sensor and pattern type. Meaning, there’s three sensors for every sensor, giving 9 senses in total. The states are confidence intervals. Anything >= 85 would be considered the most confident.

The numbers in bold are the ones that are more probable to be a result. A sensor in particular to look at is the Xbee for a thirdary pattern. The numbers are dispersed in such a way that it is almost a bimodal distribution. In order to understand why this is, imagine the scenario in real:
Xbee modems can communicate for up to a few meters. If BubbleBoy only receives a message every 3rd instance, it could either be a clever pattern, or it could be a miscommunication.
For this reason, the largest probability is given to the least confident state, and the second largest probability is given to the most confident state. It depends on the Bayes Filter and random roulette for what will actually be chosen.
This is just for determining what sensor is the most confident, that will provide the best result. This can mean that the chosen sensor will be followed, but it also may not. This will be explained in the next step.
The adjusted cost is determined by using the result from the previous step, and multiplying the probability by the inverse of whatever column it was situated in. In simpler terms, if the result was found in the best confidence interval state, then it would be multiplied by 5. If it was in ( 85, 70 ], it would be multiplied by 4…
This is then used as the sense for the next Bayes Filter. The state is how much of a cost to reduce the sense by.

Once the cost adjustment amount is determined, it is then subtracted from the cost of the particular sense’s cell. All of the senses are in a grid, with the most “primary” being the closest to BubbleBoy. An A* search is then used to choose the closest and least cost sensor. Once this is done, BubbleBoy can get on to entertaining its audience while waiting for food/water!
This is the main loop of the program. It’s where BubbleBoy is thinking in the present time about if it will be fed or not!
The key idea here is that BubbleBoy is thinking in the now. Meaning, it tracks the patterns differently than it does when it is reflecting back on them (in a “past” thought).
Sensor data is retrieved and placed into an array of size 10. The data at i is checked wither it is within +- 10% of the average in the pattern. The threshold percentage amount differs for the type of pattern, where secondary would be +- 20%, and thirdary would be +- 30%. If the data fits in to the check, then a “yes” counter is incremented.
Once the “yes” counter is >= 6, the food level will begin to decrease by (i/2)^2. At the same time, BubbleBoy will begin to show signs that he is excited to be fed/watered soon, by spinning its hat and bobbing its head.
If the “no” counter is >= 6, then it means that the expectation isn’t really working in the present thought. A flag is set to redo the expectation once BubbleBoy receives food and water.
i is then either incremented or reset to 0, depending if it hit 9 or not. (That’s a sort of obvious step)
When the time elapsed from not receiving food exceeds 150% of that of the observed elapsed time, BubbleBoy goes in to a “wallow” mode. When BubbleBoy is wallowing, it spins its hat slowly, and bobs rarely.
If the time elapsed is ( 150%, 100% ], BubbleBoy is “angry” because it did not receive its food exactly before the time elapsed. The hat will not spin, and BubbleBoy will bob side to side, and once (quickly) in the opposite axis to simulate a sort of “twitching” to all this anger!
If the time elapsed is ( 100%, 85% ], BubbleBoy is eager to please. Hat tricks will be common, same as delightful bobbing. Depending on how much food/water BubbleBoy has, it may also hoola hoop!
Depending on when BubbleBoy was fed, if it was in ( whatever, 100 ], the expectation will be done. Essentially, BubbleBoy is a positive/eager thinker that believes it should always be fed before the elapsed observed time. What an attitude!
If it is in [ 85, 100 ), then the expectation will be kept.
To reformulate the expectation, the previous steps are executed on the collected data. Then, everything repeats!
What will be super interesting to see, in my opinion, will be when the discrepancies occur from past thought to present thought. It will be interesting to see which sensors fare better through that transformation.
It will also be interesting to see if this actually can work on an Arduino, and not in simulation. I created a simulated version of BubbleBoy in Processing earlier in the week.

I’ll do the initial coding and testing through this simulation, mainly because I already coded the Bayes Filter Algorithm (with random roulette) in Processing from 2009 Honors Summer Research.
Plus, in Processing it is very simple to communicate to an Arduino through Firmata. I can read in the data from BubbleBoy through there.
Hopefully next Friday I will have devised a test sequence to test the soon-to-be-coded AI on. This will of course be Open Source, under the Attribution-NonCommercial-ShareAlike 3.0 Unported License (BY-NC-SA).
Let me know what you think of this AI in the comment section below! (And yes I know it is very linear, but BubbleBoy doesn’t have enough DOF in the real world to spend the effort making the AI more nonlinear, since the observed result will essentially be the same!)
KiloWhatt 1.1 on the App Store!

KiloWhatt, the energy management and cost calculator that I created, has been updated to version 1.1 and added to the App Store! This version includes an enhanced interface for the iPad, as well as support for iOS 4. =)
Be sure to check it out at
itunes.com/apps/kilowhatt
!
Mouser Chips Arrived! (FNR)
Hooray! I had a $50 prepaid credit card thanks to the Wolfram|Alpha “I want my money back!” program. Basically, I bought their iPhone App for $50, when I thought it was $4.99. Then they insanely dropped the price, too. I’m glad that they finally refunded us though, it is very kind and very modern of them!
I decided to buy 5 chips off of Mouser. 3 ATtiny85s, and 2 595-TLC5945PWPR 16-Ch LED Driver. The LED driver is a PWM shift out chip.
It came to $15 bucks. Not too bad, right? Well, the shipping was $20. I don’t understand what was so important about the shipping. $20, seriously? OH and, I selected to pay the shipping at the door, but instead they took it off of the credit card! ARRG! So this is what my $35 went to:
1 sheet of bubble wrap:

Another sheet of bubble wrap:

Two more sheets of bubble wrap, and the electronics:

Fire pit material:

An ugly box:

Obviously that was not worth $20 of shipping. At least Sparkfun gives you a nice box that you can hack with!!! >:(
So the chips. YES! I cannot wait to see what these LED driver DIPs look like. Only the bag is sepperating me from these wonderful things now…

I open the bag, and this film reel thing slides onto the desk. What? I didn’t order a film reel?!

There’s two tiny chips inside of the film reel. But they’re NOT DIPs! I ordered a DIP because I don’t have a Weller! On the product it even said “DIP”! ARRG!

At least they got the ATtiny85s right…

So here it is. Two $5 chips and they aren’t even DIPs. I am royally doomed now. :’(

So yeah. I have no idea how I’m going to use these tiny things. I don’t have a precise soldering iron to make it work. Also, I have nothing to solder these things to! What on earth! I don’t want to go and do something extravogent, that’s why I bought the chips! All I wanted to do was drive LEDs! GRR!
Anyway, I checked out BubbleBoy to see what was going on inside of it with regards to the servos. It appears as though the wires attaching the servo to the head broke.

BubbleBoy would probably bob its head a lot better if the servos were attached to the head via metal axels. They’re only $3 at the local hobby store, so might as well buy the ones that fit this time instead of trying to aimlessly sand down the larger axels. It will be interesting to see how well the axels fare compared to the wire! ^_^ This will be a good time to refurbish BubbleBoy.
KiloWhatt iPhone App!

An App that I’ve been working on for several months now has finally been released onto the App store! It’s called KiloWhatt! The purpose of KiloWhatt is to assist in the general understanding of the relationships between power, energy, usage and cost.

Once these relationships are understood, the ultimate goal is for people to observe which categories they consume the most energy. Decreasing our energy consumption to conserve as much as possible based off of this understanding will be very efficient and effective. As the Law of Conservation of Energy states:
“Energy cannot be created or destroyed, only converted from one form to another”. ^_^

Building this App was definitely a tribute to the incremental development approach. It started off from a simple SQLite3 todo list! I kept adding on more aspects once one thing was working. Though, at one point it did seem like there was more debugging going on than actual development. That’s learning, I suppose.

When I was finishing off the App, a lot of time was spent on the design. The table views have nice backgrounds and overlays, so that you don’t get that standard iPhone UI feel when you’re in the App. The App needed something nice so that people can show it off to their friends as something different!

Another thing- the Info tab on KiloWhatt does exactly what the name entails. It gives you more information! There’s sections in there to read about the various components about the App. The info section is definitely a vital part of any App, and I hope that this is more fulfilling than a simple version number and website info page.

Of course, there are still some improvements to be made. These will be coming with version releases. =) Oh yeah, and the little icon for the ‘Electronics’ category intentionally looks like an iMac G4 (haha)!
With that being said, go and check it out on the
App store
and let me know how you like it. =)
Finishing the RoboGlyphs Project
Just the fun stuff was left for this project! Here is a photo blog montage of the journey to the finish
The first thing to do was to put the black foam backing onto the RoboGlyph. I wasn’t really sure how the glue would look, so I placed a minimal amount on the corners. Next time I do this, I’m going to put glue all over the back since it created a neat effect with the sparkles on the foam. It sort of makes them more sparkly…

Cut the excess foam away with the Xacto knife. Cutting it on a slight inwards angle towards the glyph is much better than a 90 degree cut, I found.

To mount the RoboGlyphs to their board, I used toothpicks on the back. This is what it looks like from the front:

Zoomed in:

The toothpicks fit nicely in the holes of the perf board. I found that if you put glue in the perfboard hole, then put the toothpick in, it will stick better.

They’re all tilted forward because they don’t have a proper footing yet! =)

Again, from the back:

At first I was thinking about using some rubber feet to keep the RoboGlyphs standing, but I didn’t have any on hand. The next best thing: Lego! Plus, there is something else that I can add on to the Lego to make it even more interesting…

The “more interesting” part would be tinfoil! Tinfoil is a conductor, and therefore can have a charge running through it.

It’s quite a difficult task to manage to put the tinfoil onto the Lego bricks. This try was using hot glue. When another brick is placed on this one, the tinfoil splits.

I tried using a simple glue stick, and it actually works much better! The tinfoil does not split when another brick is placed on top of it.

Putting tinfoil inside the brick is much easier.

While the glue is setting for the tinfoil, it’s time to wire up the RoboGlyphs. Thanks to the super simple colour coded wires, the process took a matter of seconds. The Sanguino only has 6 PWM pins, and there are no PWM drivers in my pocket, so the green LEDs will not be controlled by PWM.

Green is probably the best default colour!

Red:

Blue:

The edge lighting is really cool, even though I didn’t really do it very precisely. You can’t really tell from this photograph, though.

The Lego 2x4s were glued on to the bottom of the boards. Then they’re placed onto the tinfoil-coated Lego brick. 5V is applied through an alligator clip!

The other end goes into an Analog In, where the Sanguino checks to see if there’s anything there. If nothing is there… The lights don’t turn on!

There’s a few finishing touches that I have to make. I’d like to connect it to Twitter via Processing, and have it as a permanent setup. I also have to fix the Lego connections, as right now it can only tell if the middle RoboGlyph is disconnected! =)