Thursday, September 17, 2015

How to add intelligence to our homes? - Part 2

This is the long overdue update of the house project conceptualized a while back with my kids.  In this project, a model house was wired for simple lighting using LED's.
The USB home
Each part or room in the model house will be lit by a dedicated LED and each LED will be directly connected to the pins of the microcontroller, in this case, the Arduino Uno.
The Arduino Uno wired using a recycled IDE cable

The Arduino being wired
The Arduino will act as a hardware controller/driver to power up the LED's but commands will come from a PC.  This whole architecture can be ported to a real, full sized house and control is not limited to lighting only but for the purposes of demonstration, the model house should be sufficient to illustrate.
The GUI in a Windows PC

The GUI showing the check boxes and sliders as control inputs

The model home is connected to the PC via the USB port.  The Uno will function as a slave unit with the PC as the master.  If a user clicks on the GUI, the corresponding LED will light up (or toggle off) in the actual model home.  This therefore illustrates how a real USB controlled home can be made possible.

The power through

Power lines
High tension power wires bring electrical energy across vast distances for distribution to the end users.  They play as the major energy conduits of today's civilizations.  With the advent of information technology, the world's hunger for electrical power became even more resounding.  So what makes this system work?

1.  AC is used instead of DC.  AC allows voltage transformation.  This means that the voltage can be varied with the use of a device called a transformer.  A higher voltage is used for transmission versus the lower voltage used in distribution.  Why is this so?  This leads us to point number 2.

2.  As power (P) is the product of voltage (E) and current (I), for the same power transmitted, the current can be lower by using higher voltage (P= IE).  A lower current means smaller diameter transmission cables.  This translates to lower investment costs for the cables.

3.  The consequence of higher voltage however is the difficulty of isolation or insulation.  If the cables are too near each other, it can cause arcing much like a lightning bolt.  Thus the cables are raised high above ground and are spaced far apart enough.

Modern electrical transmission systems are more complex than it seems.  There is normallty a grid designed to take in power from many source generators and distribute the power across multiple load points.  All these complications are taken cared of by engineers so that we can live our lives comfortably and with all the power we need.

Wednesday, December 25, 2013

Line tracking truck upgraded

Well, it's Christmas and the kids and I have more time together.  We exchanged gifts and I got this gift below.  This is a collection of comics pages from newspapers!  :-)  This is probably the funniest I got so far so I can really look forward to the next year and be excited about what to expect again next.

After the gift giving part was through and the funny talk has subsided, we were back to the line tracking truck project.  After the code was tested and optimized for actual runs (considering motor speeds and sensor feedback triggering, etc), it was time for some UPGRADE.   One interesting upgrade is how to incorporate a reasonable degree of recovery in cases of overshooting the line.  Thus, a "recovery" routine must be integrated into the code so that the truck will try to "look for" the line back once an overshoot is encountered.  Several code modifications were needed to make this workable.

1.  The overshoot should be minimum.  Thus a quick stop code is to be designed to react quickly once overshooting is detected.
2.  Overshoot must be defined.  The idea is to try to recover from a turning overshoot.  If the line/tape ends in a straight line, the assumption is that the end of the line is reached and no need to "recover."  However, if the overshoot happens in a turn, the truck should try to get back into the path.
3.  There must be a limit to the recovery procedure.  If after a certain number of tries, success is still not achieved, the truck should stop trying in the end.

In this upgrade, the truck was already provided with an auto-detect function.  In the previous run, the tape was white and the floor was dark.  This time, black "tape" is used against a white floor.  The truck will auto-detect a bright or dark floor and then use that information to sense the line/tape.  If it cannot calibrate, it will flash an LED so the user will know that a calibration error occurred.  A manual reset is needed (so it can try to calibrate again)

Looking for a black tape however was not as easy as I thought.  I cannot find a black tape at home wide enough for the sensor spacing design and stores are closed for the holidays so some improvisation was required.  So finally, some scrap black strip and a laptop bag strap were used for the testing.  A bend was introduced into the path so that the truck will overshoot on purpose during the execution of the turn.  If you remember, the minimum turn radius of the truck is only 2 feet.  The bend below is definitely with a much smaller radius than the supposed smooth turn of 2 feet. 

To come up with the logic of the recovery, the assumption was that there must be first a "detected" turn event.  This will be the basis for action.  The recovery will involve a reverse move with a matching steer to the opposite direction.  (the steering for this reverse motion is currently set at 10degrees only)  The truck then will stop at an instant of tape/line detection.  This is the desired success criteria for the recovery procedure so that the truck can go back into tracking the line.  If the truck cannot find anything after a certain number of search cycles (this time it is set to 5), the failure will be acknowledged and the search will stop.

After several erroneous codes and some funny truck behavior, the serial monitor was used (and abused) to understand where the erroneous values came from.  Then it was found that the sensor values in the "recovery" routines were conflicting with the initial calibration logic and modifications were made for consistency.  The timings for the quick stop motion was also not right.  In the end, for the truck to stop, I have to introduce a reverse motion at full motor power for 500ms.  This is enough to "kill" the momentum but not enough to cause much reverse movement.

Finally, below is the video of the truck overshooting and trying to recover.  Notice how it stops and reverses in the bend, then recovering back to tracking the line.  Then, it makes a quick stop after the line ends (this time in a straight line fashion). 


Merry Christmas to all.  May God richly bless everyone and more projects to come for 2014!

Saturday, December 21, 2013

Line tracking truck update

This is a sequel to the line tracking truck project previously posted.

Calculating minimum turning radius:

By design, the steering front wheels can turn by as much as 18 degrees.  The wheelbase is measured at 185mm.  Based on design geometry, we calculate "r" as the minimum turning radius of the truck.  At maximum steering angle of 18 degrees on a wheelbase of 185mm, the minimum turn radius is calculated as per below to be around 600mm (2 feet). 

Thus, by mechanical design, the minimum turn radius that the tape can be laid out so that the truck can follow without overshoot is at 600mm.  A bigger radius or curvature will of course ensure that the truck will not overshoot in the turn.

This seems to be a reasonable design limit so the project can proceed to reality.  Using the same electronics already built into the truck in the light seeking truck project, we just modify the software inside the microcontroller to make this work.  This time, we will make use of the 4-channel IR sensor that was previously installed in the front bumper of the truck.

The first prototype of code made a lot of overshooting.  The steering cannot cope up with the forward motion thus causing overshoots.  As there are four sensors in the front of the truck, the logic was programmed to be as follows: (values were made by initial performance estimates)

To make sure the steering can compensate, the code was optimized for minimum cycle time.  The faster the code can run, the more that the truck can stay on the tape.  After corrections, the prototype code was ready to run.


The next development to this project is overshoot correction and recovery.  That can be a little tricky but that will be available soon.  Watch out for the next sequel...

Fishbone diagram

The fishbone diagram:

The fishbone diagram is one of the easiest mind mapping / problem solving tools available.  It is so simple and straightforward that anyone with the knowledge about a certain topic can generate a diagram to show its cause / effect conditions.  Below is a generic representation of a fishbone diagram.

In illustrating a problem root cause analysis, a diagram as above can be generated.  During its generation, ideas must be poured out without much thought or evaluation yet.  Start from the effect (PROB) which is the "head" of the fishbone, and then proceed to ask why-why questions so as to generate ideas for possible root causes.  A probable cause must be evaluated for further probable causes.  So based on the above, there are four major possible root causes, A, B, C, and D.  Each of them have their own possible root causes as well.  the yellow color boxes are examples of root causes as they are the ones without further identifiable causes (thus, root).  Each root cause can appear in one or more instance.

After generating the fishbone, an evaluation of the probable root causes must be designed by experimentation so as to rule out the non-contributing causes.  A simple table is normally generated to summarize the results.  An example is shown below:


With this exercise therefore, we are able to determine that the root cause of the problem is "M" and therefore, correcting this root cause will solve our problem under study.

For better results, a team approach to this discipline is a good option.  More minds can lead to a wider fishbone and thus can capture more possible root causes.  As the saying goes, "more heads are better than one."

Saturday, December 14, 2013

Cruise control for an old truck

Cruise control is to maintain a car's speed at a certain number during long drives.  The system is designed so that the throttle is electronically controlled to adjust and respond to the load demand.  As the car cruises along a gentle climbing road, the throttle should open up to maintain speed.  Inversely, as the road gently slopes down, cruise control will close the throttle to still maintain set speed.  The key is proportional throttle control as well as closed loop speed sensing.  

I happen to own an old truck with a manual throttle control as shown below.  For this project, this manual throttle control is the perfect candidate for automation.

To make it work:

1.  High torque servo motor drive mechanism
2.  Hall effect speed sensing
3.  Lots of speed calibration values
4.  Mechanical system to link the throttle to the control servo
5.  Stepping on the brakes to immediately disengage the system

For safety, the project will not tamper with existing electrical circuits and mechanical systems but will be a full piggy back system.  The servo mechanical drive will be fully override capable in case of abnormal behavior.  Power failure will also put all mechanisms back to manual default.

Project milestone:
Completion by end Q2, 2013

Ideas are welcome if contributed for free. :-)

Friday, December 13, 2013

Light seeking truck project

This project is a demonstration of how to create a light seeking system that is relatively low cost to make and execute. This involves an Arduino microcontroller as the heart of the whole project.  The target system is a truck that is a broken down RC, bought from a second hand store on an "as is" basis as referred to previously in the older posts. 

The building blocks:

Below is the video of the first building block of code and electronics.  It involves two light dependent resistors (LDR), a servo motor and a light source to test the responses.  As light is focused on any one of the LDR's, the servo moves accordingly.  The design thought of is that the servo movement should be relative to the difference in intensities read by the LDR's.  The bigger the delta, the greater the angular rotation.  This system will be the basis of the steering system for the truck.


From the above, the design was copied into the truck body itself using a prototype breadboard as seen below.  The servo motor is already installed in the steering mechanism replacing the original DC steering motor installed.  We would be interested to control the steering in incremental fashion and not only in fixed angles, left or right.  Aside from the LDR's, a 4-channel IR sensor is also being put in place to be used for another project later on (the line follower project).

This is the first prototype of the hardware and software together in the truck body.  The original electronics of the truck were removed (PCB at the tip of the screw driver) and will be disposed of.  The software was tested using an Arduino Leonardo (mini format) compatible board.  This was chosen because of the thin layout fitting the thin breadboard.  The program will be ported later on to the Arduino Uno to be installed into the truck body.

Below is the truck with the LDR's already in place.  Two placed in the front and two at the back.  All placed on the corners of the truck body.  The Arduino board is also installed as can be seen under the deck of the truck.  The power to the drive motor will be provided by the L293D H-driver IC.  All the IR sensors are placed under the front bumper for the later project.

Almost all set.  Now, it's time to close the truck, upload the software and test run the system.  Below is the first steering test.  Using a laser pointer to trigger the LDR's, the front wheels steer toward the light input.  This is our first taste of success.


For the full functional test, power must now be from batteries because we have been using the USB port to power the system yet.  The final step was to connect the Arduino to battery power as well as connect the H-driver to the battery as well.  The drive motor will be powered from the battery without going through the Arduino. 

Running the prototype:

Below is the first ever test run of the light seeking truck.  Obviously, the sensors and steering need to be optimized further but the demonstration unit is already a success story.