Friday, December 25, 2015

Robot Christmas

AVA Disco Mode


The robot received a set of Ikea Dioder LED strips for Christmas. Below is a quick video of AVA in disco mode. There will be a separate post on controlling these strips using an Arduino at some stage.




AVA Christmas


In keeping with the Christmas theme here is AVA singing a Christmas Carol using the EMIC 2 Speech Synthesizer. The Emic 2 Text-to-Speech Module is a multi-language voice synthesizer that converts a stream of digital text into speech. You can select either the Epson (default) or DECtalk parsers.


Note that the Emic 2 uses DECtalk version 5.0.E1. The Flame of Hope web site has a heap of DECtalk songs but they are for earlier versions of the DECtalk parser and require tweaking to work with the EMIC 2. Thanks to Ron on the Parallax forum for these tips on converting the text files:

  • you often have to change an "L" to "LL"
  • sometimes you need a space between any character preceding the "ey" phonetic symbol.

The following is the string used to produce the song in the video above, should you wish to try out your EMIC 2's singing ability.


"[:phone arpa speak on][:rate 190][:n2][:dv ap 200 sm 100 ri 100][R EY<200,17>N<100>DRAO<200,24>PS<100>AO<200>N<100>ROW<300,19>ZIX<200,17>Z<100>AE<150>N<100>D<50>WIH<300,12>SKRR<200,17>Z<100>AO<200>N<100>KIH<300,19>TAH<150,17>N<100>Z<50>_<300>BRAY<200>T<100>KAO<300,24>PRR<300>K EH<300,19>TEL<200,17>Z<100>AE<150>N<100>D<50>War<200,12>M<100>WUH<300,17>LL EH<200>N<100>MIH<300,19>TAH<150,17>N<100>Z<50>_<300>BRAW<200>N<100>PEY<300,24>PRR<300,22>PAE<300,17>KIH<300,19>JHIX<200,15>Z<100>TAY<200>D<100>AH<200,22>P<100>WIH<200,20>TH<100>STRIH<300,13>NX<200>Z<100>_<300>DHIY<200,12>Z<100>AR<300,13>AX<300,15>FYU<300,17>AH<200,18>V<100>MAY<300,20>FEY<300,22>VRR<300,24>EH<200,22>T<100>THIH<500,16>NX<300>Z<100>][:n0]"


Arduino Code



To make it easy for our Arduino Mega 2650 to communicate with the EMIC2 we created a library called synthesizer.h. As you can see the Arduino connects to the EMIC 2 via one of its serial ports.



To use this class, I have created a robot class which looks like:



Then in the main.ino file all you need to do is:



You don't have to use C++ classes like I did but it makes it easier to maintain your code. You can also ignore the bits which refer to the motors and other sensors, I just leave it in here for completeness.


Wednesday, December 23, 2015

Moving to embedXcode...

The Problem


We have been using the Arduino IDE to develop on. Which is fine (and free) but it does have some limitations. In particular, we ran into the problem of having too many tabs (files) in our main controller sketch. This came about as a result of another issue, which is not unrelated.

As with most people we started developing our robot code organically using mostly straight c with c++ functionality reserved for included libraries. By the time you add 13 sensors, speech synthesis, speech recognition, 2 motor controllers, serial comms for the Bluetooth remote (which will be described in a subsequent post) and an I2C bus connecting the real time clock, pressure / altitude module and 2 auxiliary Arduino's used for display and logging, the code gets messy and hard to maintain. A simplified schematic of the robot so far is shown below. The schematic was produced using Fritzing which I have mentioned previously and strongly recommend.



As an aside, we are using SPI for the logging Arduino to communicate with its OLED shield, so we have all the available communication options covered (with the possible exceptions of WiFi and RF - stay tuned)!

To fix the messy, unmaintainable code issue, we started to translate our c code into c++ classes where it made sense. This made the code much more modular but each class requires a new tab which brings us back to the first issue mentioned above. Once the number of tabs fill up the top row of the IDE, it becomes a bit of a pain to move to the tabs not displayed. There is a keyboard shortcut to go to the next and previous tab, but that is a bit clunky and was the straw that sent me on a search for a better IDE to develop Arduino code on.


The other short comings of the Arduino IDE are:
  1. No code completion; and
  2. The syntax highlighting is a bit hit and miss. You could fix a particular issue by editing the keywords.txt file in the appropriate library but that is pretty fragile.

The Solution


A quick google search will turn up LOTS of different options for programming the Arduino. Our preferred solution would incorporate the following:
  1. Minimal learning curve;
  2. Preferably free;
  3. Works on a Mac;
  4. Can upload a sketch from within the IDE;
  5. Includes a serial terminal similar to the serial monitor provided by the Arduino IDE; 
  6. Has code completion and syntax highlighting; and
  7. Handles multiple files well; and
  8. Doesn't create any new issues.
With this shopping list in mind, the field quickly narrows to a plug in for Xcode called embedXcode. This ticks all our requirements and has (almost) no learning curve since we use Xcode for our App Development work.



The other IDE we considered was Eclipse which is the basis of Android Studio that we use for Android Development. What swayed or decision was that the setup looked a lot easier for Xcode and we were more familiar with this IDE as well. Have a look at this blog by a chap in the US, he had the same issues but decided on Eclipse. Going with what you are already familiar with makes a lot of sense.

Setting up embedXcode


This is straight forward and described in detail in the (large) user manual. In summary:
  1. Install Xcode if you don't have it already.
  2. Download embedXcode. We went for the free version to evaluate how good the plug in is. Should it work out we will either upgrade to embedXcode+ or pay a donation. We want to encourage ongoing development of the plugin. We know that Xcode changes frequently and with each new release normally breaks legacy code.
  3. Install the plug in and open up Xcode. That's it! You should now have the option to open a new embedXcode AVR project (see below).

Importing Sketches


Unfortunately you can't just import sketches that you have done with the Arduino IDE. There is a process that you need to follow:
  1. Open a new project in Xcode. You can call it the same name as your sketch. Make sure you select the correct board type (e.g. Uno) in the new project options. The scope options are sketch or library and this also sets the extension of the main file (.ino for sketches and .cpp for libraries).
  2. Open your sketch in the Arduino IDE and copy the contents into the ino file in your Xcode project. There is some pre-processor definitions used for code sensing at the top of the ino template file in Xcode. Don't overwrite these unless you know what you are doing (e.g. if you are using a recent Arduino you can replace the lot with #include "Arduino.h".
  3. The next step is to find your Arduino libraries folder in Finder and drag it across to the Sketchbook group. When the choose options for adding these files dialog comes up, don't select "copy items if needed" (unless you want multiple copies of your library files), select index in "add to targets" (see below). You also need to change the type from plain text to "c++ source". This option is found in the right hand pane of Xcode after selecting the main sketch (shown in the second screenshot below).
  4. The thing I stuffed up initially was not also listing the libraries used in the makefile. If you get an error saying a library can't be found, this may be the answer To fix it, select the makefile in the left hand pane and add the names of the libraries used.  There are two types of libraries you will use most often, application libraries and user defined libraries. Generally, the application libraries are the ones defined using <> (e.g.  #define <SoftwareSerial>) and the user libraries are defined using"" (e.g. #define "blunoAccessory"). However the <TimerOne> library was an exception to this rule and needed to be defined as a user library (e.g. "APP_LIBS_LIST = SoftwareSerial" and "USER_LIBS_LIST = U8glib blunoAccessory TimerOne". Different libraries are separated by a space and don't show the file extension. Read the user manual if you are still confused, it covers this topic in some detail.



Once you have completed the four steps above, you should be able to build (compile) your project, but only if your board is connected.

New Issues?


The only issues which have arisen so far are fairly minor apart from the speed of compilation and uploading. This is significantly slower than the Arduino IDE. If you purchased  embedXcode+ then you have two options:

  1. Build -> All targets which builds and links everything, and is slow.
  2. Make -> Fast -> additional targets only, which builds the main sketch and the libraries in the local folder, so it is much faster (up to 10x according to the developer).

If you only downloaded the free version then you are stuck with option 1. Other areas to be aware of are:
  1. You can't Build (compile) a project unless you are connected to your board via USB. This is a bit of a pain as you could just compile using the Arduino IDE without being connected to the board. Solved this. From the Product menu item select Scheme -> Build.
  2. Instead of Serial Monitor in the Arduino IDE you use Terminal on the Mac. The default baud rate for terminal is 9600. Which is ok if that is the baud rate you want to use on the serial port but I have a sketch which communicates with a BlueTooth LE shield on the same comm port that needs 115200 baud. Theoretically you can change the baud rate in Terminal using stty (e.g. stty 115200), but this doesn't seem to work. I have also tried "screen /dev/tty.usbmodemfd121 115200", but no cigar. I will keep working on this but the work around for now is to use 9600 baud if you can or use the old Arduino Serial Monitor if all else fails. Other solutions are welcome, so feel free to comment below. I have found the answer to this as well. There is an option in the makefile that you can use to set the baud rate, namely:  "SERIAL_BAUDRATE = 115200".
  3. Getting code sense to work for me took a bit of tweaking. First make sure that the sketch (ino file) has index selected for Target Membership (click on this file to check). Save the file and close the project. A small update is required to the user manual instructions. In the current version of Xcode (v7.2), projects is now a separate dialogue to Organiser but it is still found under the Windows menu in Xcode. Delete your derived data for your project and then reopen your project. After indexing, code sense for the Arduino specific definitions should work. You can change the syntax colouring in preferences, fonts and color.

If anything else comes up, I will add it here. All in all I am pretty happy with this solution. We will still use the Arduino IDE for simple sketches but for something as complicated as a robot, an IDE like Xcode is essential. Well done embedXcode!

Update 27th December 2015


I was so impressed with embedXcode that I upgraded to embedXcode+. This is worth doing if you use the plugin regularly. It also encourages the developer to keep supporting the product which is important given the frequent updates to Xcode.

Error: Serial port not available (Step2.mk)




If you come across this error (I did), there is a simple fix. First open up terminal and find out the name of your serial port. Type the following command: ls /dev/tty.usb*


This will provide the name of your serial port. Copy this and then open the main Makefile in Xcode uncomment the line:

#BOARD_PORT = /dev/tty.usbmodem*

and specify either a more general name:  e.g. BOARD_PORT = /dev/tty.usbmodem*

or the specific USB port name of the board that you got from Terminal e.g. in my case:

BOARD_PORT = /dev/tty.usbmodemfd121









Wednesday, December 9, 2015

Parallax HB-25 Motor Control Library for Arduino

Moving AVA


We are using the Arlo robotics platform from Parallax to build up AVA. As you can see in the schematic below, this incorporates two HB-25 motor controllers (Part Number: #29144) which look after the left and right wheels.


After an exhaustive search we were not able to find an existing Arduino library for the HB25, so we were forced to write our own. This involved delving into the incomplete version of C++ which Arduino uses. Before getting to this, let's look at how you can control the HB25 just treating it as a servo, which will be fine for most folks.

Wiring the HB-25




If you are using the Parallax Motor Mount and wheel kits (part numbers #28962 - aluminium or #28963 - plastic) then the red cable should be connected to M1 on the HB-25 and the blue cable should be connected to M2. If these are reversed then the FORWARD and REVERSE commands will be reversed.



Make sure that the jumper is in place for mode 1 operation. In this mode, you need a separate digital output on your Arduino for each HB-25 that you want to control.

Controlling the HB-25


From the HB-25 data sheet, we can establish the following:

  1. The HB-25 operates like a servo. You only need to send a single pulse (in mode 1) to change direction or speed. Pulse width determines the HB-25 output.
  2. Valid pulse widths are 0.8 ms to 2.2 ms. If the HB-25 receives a pulse width which is outside this range, the motor will be stopped until it receives a valid pulse.
  3. The minimum time between pulses (HOLD_OFF_TIME) is 5.25 ms + pulse time (max 2.2 ms). Thus the worst case hold off time needs to be 7.45 ms. We have used 8 ms.
  4. The maximum time between pulses is unlimited, since a single pulse will be latched by the HB-25. An exception to this would be if the Communication Timeout feature of the HB-25 has been enabled. You can read more about this on the HB-25 data sheet (https://www.parallax.com/downloads/hb-25-motor-controller-product-documentation).
  5. Regardless of the mode, the HB-25 signal pin should be brought low immediately upon power up. The Library does this when you instantiate a HB25MotorControl object.
  6. Pulse width (1 ms = 1000 microseconds) will control the HB-25 as follows:

                        - 1.0 ms Full Reverse
                        - 1.5 ms Neutral (STOP)
                        - 2.0 ms Full Forward

Arduino Code


So making use of the above, we can control a HB-25 using the following Arduino code. Note that you will need to set controlPin to whatever digital output pin is connected to your HB-25. After you have initialised your HB-25 you can control it by writing a value between 1000 and 2000 to it using the servo.writeMicroseconds() method. You need to ensure that two commands are not sent within the minimum hold off time. This is taken care of for you in the library below.

#include <Servo.h>

#define REVERSE       1000
#define STOP          1500
#define FORWARD       2000
#define HOLD_OFF_TIME 8

Servo servo;

// HB-25 initialisation time (5ms)
delay(5);                                           
pinMode(controlPin, OUTPUT);
// Set control pin low on power up
digitalWrite(controlPin, LOW);  
// Attach HB-25 to the control pin & set valid range                    
servo.attach(controlPin, 800, 2200);
servo.writeMicroseconds(STOP);

Arduino Library


To make using the HB-25 a bit easier and to hide some of the complexity we wrote an Arduino library for it. This consists of four files (click to download):

1. HB25MotorControl.h;
2. HB25MotorControl.cpp;
3. Keywords.txt; and
4. HB-25_Test.ino

To use this library, you need to create a new folder in your Arduino libraries folder called HB25MotorControl. Copy HB25MotorControl.h, HB25MotorControl.cpp and keywords.txt into this folder. Then create a sub-folder called examples and place HB-25_Test.ino into that.

You need to restart the Arduino IDE (if it is already open) to be able to see and use this library.

The example sketch should demonstrate how you use the library, but at its simplest:

#include <Servo.h>
#include <HB25MotorControl.h>

const byte controlPin = 9;              //  Pin Definition

HB25MotorControl motorControl(controlPin);

void setup() {
  motorControl.begin();
  motorControl.moveAtSpeed(500);
}

void loop() {
  
}

Valid speed ranges for the forwardAtSpeed and reverseAtSpeed methods are 0 (stop) to 500 (maximum speed). For rampToSpeed and moveAtSpeed you can use from -500 (full reverse) to 500 (full forward). As before, a speed of 0 will stop the motor.

Feel free to modify and reuse the library as you like. If you do improve it, then let us know. Attribution is nice but not necessary, and as usual this library comes with no warranties, so use at your own risk.

Tuesday, November 24, 2015

Voice Display Board Completed

1.0 Recap


In a couple of earlier posts we described the design and construction of a voice display and driver board which would emulate that used by Kitt in the Knight Rider TV show. This has now been completed and mounted on AVA.



When we connected the voice display unit to the EMIC 2 Speech Synthesizer which AVA uses to talk, we discovered a problem. The display was driven hard on, even when AVA was silent. A quick measure with the multimeter showed that the EMIC 2 has a constant 2.4 VDC offset. As discussed in the earlier post, the LM3915 displays full scale at 1.25 V, so that was why all the LED's were on.

This is not unusual and a lot of the Arduino MP3 shields do the same thing. Unfortunately when we were testing the prototype, the EMIC 2 hadn't arrived from the USA so I tested using the piezo analog output on the Arduino (which doesn't have a DC offset).

2.0 High Pass Filter


There are a number of ways that you can remove the DC component of a signal, so that you are just left with the AC component. You could use an isolation transformer, but we didn't have one in the spare parts bucket. We did have a heap of resistors and capacitors so we decided to try a high pass filter.

A high pass filter, as the name suggests, passes signals above a selected cut-off point, ƒc eliminating any low frequency signals from the waveform. The circuit for a first order high pass filter looks like the following.

It delivers a response curve (courtesy of http://www.electronics-tutorials.ws/filter/filter_3.html):


It is generally accepted that the range of frequencies audible to humans is 20Hz to 20kHz. Consequently we will design our HP filter with an fc of 20Hz. The formula to calculate fc for a first order high pass filter is:


You can pick two variables and solve for the third, or you can go to an online filter design calculator, and let it do the hard work for you.

We selected an fc of 20Hz and a capacitor of 0.01uF (because we had one of this value), and the design site spat out a resistor value of 820k. If you plug in these values into the formula above you will get an fc of 19.4 Hz which is fine. The filter design site will even plot frequency and transient analysis graphs for you.



3.0 Conclusion


Adding the high pass filter between the EMIC 2 Speech Synthesizer and the voice display module did the trick. It removed the DC bias and allowed the speech signal to pass through. Here is a video of AVA speaking with the voice display module installed.


Saturday, October 31, 2015

Sharp GP2Y0A02YK0F IR Distance Sensor (20-150 cm) Arduino Library

Distance Measuring Options


If you are building an autonomous robot then you need to have some sort of obstacle avoiding sensors. I have attached a Parallax PING ultrasonic sensor to the front of AVA using a servo (so that I can scan 180 degrees). Ultrasonic sensors are generally pretty accurate but since they use reflected sound to calculate distance, they don't perform well if the obstacle is sound absorbing. Ultrasonic sensors can also miss thin objects or objects that reflect the sound away from the sensor. However, the range of ultrasonic sensors is much better than IR. For the PING, the available sensing range is 2 cm to 3 m.

To address the ultrasonic issues, I also mounted a Sharp IR Distance Sensor (GP2Y0A02YK0F) above the PING. The IR sensors don't perform well outside but indoors there accuracy is good enough as long as you stay within the quoted detection limits. IR sensors are generally cheaper than ultrasonic, their beams are more directional (narrower) and reflectivity of the surface is more important than the sound absorbing properties of potential obstacles.

Putting the two sensors together is complementary and allows the short comings of both sensors to be addressed (to an extent).

Sharp GP2Y0A02YK0F IR Distance Sensor (20-150 cm) 



Sharp manufactures a range of IR Distance Sensors. For the front sensor I selected the GP2Y0A02YK0F, which has a usable detection range of 20 to 150 cm's.

The Sharp GP2Y0A02YK0F measures distances in the 20–150 cm range using a reflected beam of infrared light.  By using triangulation to calculate the distance measured, this sensor can provide consistent readings that are less influenced by surface reflectivity, operating time, or environmental temperature.  The Sharp GP2Y0A02YK0F outputs an analog voltage corresponding to the distance to the reflecting object.

If you have a look at the GP2Y0A02YK0F datasheet, you will see that the analog voltage output does not have a linear relationship to distance. You can also see that the values go crazy below about 20 cm.


Noah over at the Arduino Mega Blog has reversed engineered this plot to work out the relationship between distance and the output voltage.

distance = 10650.08 * sensorValue ^ (-0.935) - 10 cm

Sharp GP2Y0A02YK0F IR Distance Sensor Arduino Library


To connect to an Arduino and get a distance you could just use Noah's formula above, but sometimes it is easier to wrap the complexity up in a library. I did a search and didn't find an existing library, so I decided to do one myself. Partly because I haven't done one before.

I did find a library for the GP2Y0A21YK IR Distance sensor (10 - 80 cm), but the characteristics must be different to the GP2Y0A02YK0F as the distances provided by the library are way off. Noah's formula on the other hand, provides very good correlation with the distances measured by the PING. For consistency, I based my library on what jeroendoggen did for his.

You can download the Sharp GP2Y0A02YK0F IR Distance Sensor (20-150 cm) Arduino Library files, and then follow these instructions to use it:

Instructions:

  • Create a directory called GP2Y0A02YK0F within the libraries sub directory where your Arduino sketches are saved.
  • Copy GP2Y0A02YK0F.h, GP2Y0A02YK0F.cpp and keywords.txt into the GP2Y0A02YK0F directory.
  • Within the GP2Y0A02YK0F directory, create a sub directory called examples.
  • Copy DisplayCM.ino into the examples sub directory.
  • Restart the Arduino IDE to see the new library.

Sharp GP2Y0A02YK0F Mounted on AVA


The following photo shows the Sharp IR sensor mounted above the front PING on AVA. I have fitted a sensor shield to the Arduino Mega which makes it very easy to connect the various sensors to the micro controller.



Friday, October 23, 2015

Connecting the Duinotech 3 Axis Compass to an Arduino

1. Duinotech 3 Axis Compass Magnetometer Module


At a recent mini maker faire, I purchased the duinotech 3 Axis Compass Magnetometer Module (Part Number: XC-4496) from the Jaycar Electronics stand. I thought this would be handy for calculating heading information for AVA the robot.

Unfortunately, the module comes with no instructions and just these very brief specifications:
  • Operating Voltage: 5VDC (or 3.3 VDC)
  • Resolution: 12 bits
  • Interface: I2C
  • Includes: 5V to 3.3V level shifter (so you can operate it from 5 VDC)
  • Dimensions: 20(L) x 16(W) x 5(H) mm
We know that the module communicates via I2C but without knowing the module address or the available instructions, this isn't much use. No problem, I'll head over to the Jaycar website and look up the technical specs. Bzzzzzzzt! If you click on the link above, you will see the only information provided is the specifications printed on the packaging. It appears that Jaycar are moving away from Freetronics for their Arduino compatible boards, shields and sensors to duinotech a Chinese manufacturer. I assume they are doing this based on cost, the Freetronics stuff is good quality and very well documented. 

2. Honeywell HMC5883L 3-Axis Digital Compass IC


If you have good eye sight you will see HMC5883L printed on the PCB. A quick google will determine that this is a 3-Axis Digital Compass IC produced by Honeywell. The HMC5883L Data Sheet is very comprehensive and requires everything that you need to interface the chip to an Arduino via I2C. The duinotech module is apparently a break out board for the HMC5883L, similar to the one produced by SparkFun. It is in fact an improvement on the SparkFun version in that it can be driven from 5VDC and the interrupt line is also broken out.

3. HMC5883L Arduino Library


Armed with the data sheet you could work out how to get the module talking to an Arduino but as usual, a number of people have already done the hard work for you. I ended up using a library written by Korneliusz Jarzebski, a Polish chap. The HMC5883L Arduino Library is accompanied by a tutorial, which is in Polish but google translate does a pretty good job of converting this to English.

One thing that the library is missing is the keyword definition file which the Arduino IDE uses to colour highlight defined library names and methods. I have produced a keywords.txt file for the Jarzebski HMC5883L Library which you are free to download and use. It includes all of the public methods exposed by the HMC5883L class.

To use the library, create a folder called HMC5883L in the Arduino libraries folder. Within this copy the HMC5883L.h and HMC5883L.cpp files from the Jarzebski Github repository and the keywords.txt file. Also create a sub folder called examples and copy the HMC5883L_calibrate,  HMC5883L_compass, and HMC5883L_simple files into it. You will need to restart the Arduino IDE to see the new library. The HMC5883L_simple sketch example shows how to use the library and test your module.

Here is a quick video which shows the HMC5883L mounted on my robot AVA. On the OLED screen you can see when the compass is connected and the observed heading when the text scrolls up.


Tuesday, August 11, 2015

Importing Robot Parts from the USA - How not to do it!

1. How Not to Do It


As mentioned previously, we are using the Arlo robotics platform as the base for AVA. We placed an order with Parallax for the bottom and top decks, power distribution board, motors, wheels and a bunch of sensors on the 14th July. The total cost was USD939.67 and shipping cost USD 119.10. So far so good.

What I didn't know (or more likely had forgotten) was that importing anything worth over AUD1,000 attracts the attention of Australian Customs. To summarise the current situation:
  • For goods that are worth equal to or under AUD1,000, there are no duties, taxes or charges to pay.
  • For goods that are worth more than AUD1,000, you will need to fill out a special form called an Import Declaration, and pay duties, taxes and charges.
  • You will need to pay duties and taxes on some goods (like tobacco or alcohol) regardless of their value
  • Certain types of goods are not allowed to be brought into Australia, or else need special permits.
So stupidly, we placed an order for just over $1K Aussie. This is where you disappear down the rabbit hole.

2. Then Things get Difficult


On the 31st July, I got notice from Parallax that they had shipped the order. Woo Hoo! Parallax provide a helpful link which allows you to track the package as it wings it way to you. On August 4th, the package landed in Australia and then I started seeing the dreaded "Held in Customs" message. No problem we thought, there must be some sort of clearance process, a day or so and the package will be on its way. Nope. On the 10th August we receive a formal letter from Australia Post stating that "the goods you are importing are being held, pending completion of Customs formalities". What's more if you don't sort this out promptly you will start being charged a daily storage charge (called Demurrage - because storage charge would be too obvious) and after a month, the goods will be returned to the sender.

3. Exiting the Rabbit Hole


Mental note - don't order goods worth over $1k on the internet again! Ok, how do we sort this mess out? Australia Post helpfully provides another 2 pages of instructions of where to from here. The process is as follows:
  1. Download and complete import Declaration (N10) - Post (Form number 8374) Including Tariff Classification.
  2. Submit an Import Declaration  to Department of Immigration and Border Protection (DIBP).
  3. Your import declaration is assessed for Duty and GST. Allow 5 working days for this, unless additional documentation is required (of course it will be). There is also a manual processing charge of $48.85 on top of the Duty and GST.
  4. You then receive a payment advice. After payment processing which takes up to 3 days, Australia Post is notified that they can dispatch your goods. Expect delivery in 1 - 7 days.
When I stopped crying and the alcohol therapy had done its job, I pulled myself together and said "we can do this!"

4. I was wrong...


I did manage to download "Import Declaration (N10) - Post (Form B374)". This electronic form has a helpful feature that prevents copying and pasting so you need to type it all in. No problems, the bureaucracy and their 13 digit identification codes won't beat me! Then you get to the tariff classification and statistical code section. The first bead of sweat appears. Perhaps Dr Google can assist. Apparently there are 13,000 customs tariffs and 4,000 concessions. You read on, you have to provide the tariff classification and statistical code for every line item in your order. We have 16 items in the order and are starting to feel sick. Then there is Section 243T, which means that Customs can hit you with a Strict Liability Penalty of $2,550 should you get the declaration wrong (even unintentionally).

5. Plan B


We quickly came to the conclusion that we were out of our league. Difficult as it is to believe you are better of hiring a licensed customs broker to manage this process for you. We used eCustoms Broker (for no other reason than they came up first on the search list) but have been very happy with the results. They process the form in one day (3 hours if you are really impatient and want to pay a bit more) and charge $77. There is an electronic processing fee of $40.20, which is cheaper than the manual fee if you do it yourself. I had to pay the GST of $144.39 but because Australia has a Free Trade Agreement (FTA) with the US you don't have to pay duty if the goods are manufactured in the US. I'm not sure how difficult this concession would have been to get if you did it yourself but it would add at least add another 5 days as there is another form to fill in. For the speed and not having to wade through 13,000 tariff codes I'm happy to pay $77. The only difficult part was explaining what the parts were for and what the robot would do...

6. Changes from 2017


At a recent meeting of State and Federal Treasurers it was agreed that from 2017, there will no longer be a $1000 threshold for the GST for online purchases.

That means, in 2017, everything you buy online, no matter the cost, will be at least ten per cent more expensive. This will come into effect from July 1st of that year - so buy up now!

Wednesday, July 29, 2015

Voice Driver Board - Kitt Display

1. Overview


In our last post we described the display board which consisted of the six DIL LED bar graph displays and their associated current limiting resistors. The input to the LED Driver Board is a 10 pin header and +12V (which will come from AVA's power distribution board powered by two 12V SLA batteries in parallel). The purpose of the driver board is to take in an audio input signal, feed it to a LM3915 Dot/Bar Display driver chip, which then sinks the current from the display board LEDs via transistors, when they need to turn on. It does this using the 10 pin header which connects the two boards.

2. Header Connections


The 10 pin header is labelled A to J. On the display board, pins A, B and C connect to the first 3 LEDs on the middle bar graphs. Note that the lower bar graph connections are the mirror image to the top bar graphs. Pin D connects to the first LED of the outer bar graphs and LED 4 of the inner ones. Pin E then connects to the 2nd LED of the outer bar graphs and LED 5 of the inner ones. This pattern continues for the rest of the pins. The last 3 LED's on each of the outer bar graphs remain unconnected. By connecting the LED's in this fashion we get a display which simulates a mouth moving based on the audio level of the sound.



On the driver board, pin A of the header is driven by the LED 1 input on the LM3915. B is controlled by LED 2 and so on. The LM3915 senses analogue voltage levels and drives the ten LED inputs to produce a logarithmic 3 dB/step display. Consequently (from the data sheet), the LEDs will turn on at the following approximate audio power levels:

A - 0.2W
B - 0.4W
C - 0.8W
D - 1.6W
E - 3W
F - 6W
G - 13W
H - 25W
I - 50W
J - 100W

3. LM3915 Display Driver Setup


Using the LM3915 is fairly straight forward. Pin 1 and pins 10 to 18 are the LED driver inputs (see schematic above). Pin 2 goes to ground. Pin 3 (V+) goes to the 12V supply (max 25V). Pin 4 goes to ground if that is your bottom voltage range (which it is for us).

Pin 5 is the signal input. We want a maximum of 1.2V, so we use a voltage divider to step this input down. The input at pin 5 can withstand voltages of +/- 35V and an input current of +/- 3mA without damage. The audio output from the Arduino will be at most 5V (but less than this in practise as we are using PWM to drive the piezo). The formula for a voltage divider is:

Vout = Vin (R2 / (R1 + R2)
         = 5V x (10k / (18k + 10k)
         = 1.8V

Note that full scale has been set to 1.25V (see below), so we are overdriving this a tad theoretically but in practise that turns out not to be the case. We are nowhere near levels which would damage the chip.

Pin 9 selects the mode of the display driver. Leave it floating for dot mode, connect it to the supply voltage (pin 3) for bar mode. We added a switch so that you can select the mode.

Pin 6 is the full scale voltage level. We have connected this to pin 7 which is the LM3915 internal voltage reference which delivers a nominal 1.25V between pin 7 (REF OUT) and pin 8 (REF ADJ). To calculate the current which will be sunk at each LED input pin, we refer to the data sheet formulas:

Vref = 1.25V (1 + R2/R1) + R2 x 80uA
        = 1.25V (1 + 0) + 0
        = 1.25V

ILED    = 12.5V/R1 + Vref/2.2k
          = 12.5/1000 + 1.25/2200
          = 13 mA

This would be fine if we were connecting an LED directly to the LM3915, but we can't do that because we need to drive up to 6 LEDs per input (have a look at pin D on the display board). We want the current through our LEDs to be 10 to 15 mA, so we need to be able to sink up to 90 mA. Note that from the data sheet, the max LED current is 13 mA (from the electrical characteristics table). This explains why we need the transistors.

Capacitor C1 (2.2uF tantalum) is required if leads to the LED supply are 15 cm (6 inches) or longer.

4. Transistor Switches


In order to sink sufficient current for up to 6 LEDs we will use transistors to switch them on and off. We have selected the BC 557 which is a general purpose PNP transistor. This transistor can handle a max current (Ic) of 100 mA and a max voltage (Vce) of 65V. It has a DC current gain between 125 and 800.

We use a PNP transistor rather than the more common NPN variety because we need the current to flow out of the base and into the LM3915 LED input to turn the transistor on. In a NPN transistor the current flows into the base.

PNP Transistors can be thought of as being normally OFF but a small output current and negative voltage at its Base ( B ) relative to its Emitter ( E ) will turn it ON allowing a much large Emitter-Collector current to flow. PNP transistors conduct when Ve is much greater than Vc.

To cause the Base current to flow in a PNP transistor the Base needs to be more negative than the Emitter (current must leave the base) by approximately 0.7 volts for a silicon device.

The voltage drop across the current limiting resistor on the display board is the supply voltage (12V) minus the LED forward drop (2V from the data sheet), which gives us 10V. Thus,

ILED = 10V/180 = 55.5mA

However, this current is distributed among 7 LED's, and so typically will be more like 8 mA per LED.

The LM3915 LED inputs are at V+ (i.e. 12V) when off and close to ground when on.

We know that:

Ie = Ib + Ic; and

DC Current Gain (Hfe or Beta) = Ic/Ib (= 125 to 800 for a BC 557)

Consequently, when the LM3915 input is ON, the corresponding transistor is also turned hard on (saturated) and the LEDs associated with that pin are also turned on. The voltage at the base when turned on is 10V - 0.6V = 9.4V. Based on this voltage across the 1k base resistor we can calculate the base current:

Ib = 9.4V/1000 = 9.4 mA

Based on a typical gain of over 300 this may suggest an Ic above the maximum 100mA but this wont happen because the transistor is saturated and at most will draw the ILED of 55.5 mA calculated above. It is not a bad idea to overdrive the base current (within the limitations of the transistor) as this makes the design conservative and beta drops off with high speed switching (MHz so not really a consideration for audio frequencies).

When turned the LM3915 inputs are OFF, the transistor is also OFF, there is no base current and hence no collector current and the LEDs are OFF.

5. Main Driver PCB


The image below shows the final main driver printed circuit board. When connecting to the display board, note that the order of the header (A-J) is reversed.



Wednesday, July 22, 2015

Voice Display Board - Based on Kitt from Knight Rider

1. Overview


While waiting for the mobility platform parts to arrive from the US, I decided to start a side project. I liked the idea of having some sort of visual indication for when AVA was communicating and coincidently came across a voice display board advertised by Think Geek (which says it all really). This display is a simulation of that used by Kitt the robot car in the TV show Knight Rider.


Following a quick internet search it became apparent that there were two main approaches to developing a display like this, analogue or digital. Given that the rest of AVA was largely digital I thought I would go old school and try the analogue path.

The Kitt display is basically a VU (Audio Power) meter reflected horizontally. To make things simple, Texas Instruments produce a chip called the LM3915 Dot/Bar Display Driver which does most of the hard work and is designed for exactly this application. The LM3915 senses analogue voltage levels and drives ten LEDs to produce a logarithmic 3 dB/step display. The LM3915 even provides a regulated LED current supply, eliminating the need for current limiting resistors.


The logarithmic output is suited to signal inputs with wide dynamic range (like audio levels, power, light intensity and vibration). There is also a linear version of the chip which could be used for things like battery level and I may incorporate one of these in a later project.

2. Prototype Design


To ensure that this design works as advertised and to identify any design issues, I built a quick prototype and hooked it up to AVA's logging Arduino (which is the only thing which makes a noise currently). Eventually the robot will have a voice synthesizer, but one step at a time.

Based on the audio power meter design from the LM3915 Data Sheet, I built a version on a breadboard. Note that the LED bar graph doesn't have it's polarity marked (that I could see), a quick check with a multimeter indicated that the anode is the side with the writing.


This works ok, but highlighted a few issues:
  1. The PWM digital output on the Arduino which drives the piezo to make the robot sounding beeps, has sufficient residual voltage when making no noise to light a couple of the LEDs.
  2. The voltage output from the Arduino is low enough that it doesn't need the voltage divider formed by R1 (18k) and R2 (10k). Consequently the audio signal can plug straight into pin 5 of the LM3915. This pin can handle +/- 35V without damage so we are pretty save with our 5V Arduino.
  3. The LM3915 can only sink a maximum of 13mA of LED current (see data sheet electrical characteristics table). To produce the Kitt display we will need 6 of the LED bar graph displays, so in the worst case we need to be able to provide enough current to drive 6 LEDs. Checking out the data sheet for the LED bar graph display, we find that each LED typically draws 20mA (forward current). In practise, as little as 1 mA will light the LEDs, but they are fairly dim. 
  4. As can be seen from the breadboard photo, even one 10 LED bar graph needs a heap of interconnecting wire. Six times this would be a mess, which suggests that a Veroboard solution is not the go. We will need to layout a PCB or two.

3.0 Final Design


Addressing the issues raised by the prototype, I created a design which utilises two PCB's on top of each other (display on top). The display board schematic looks like this:


The associated double sided PCB layout is below. I used Fritzing to do the schematic and PCB layout. It is FREE and I highly recommend it for simple to medium level designs. They have an associated PCB fabrication service (in Berlin) which is fairly expensive, but for a double sided board like this with a number of via's, it was a good option.


We will cover the display driver board in the next article. Finally, a quick video of the prototype connected to AVA.



Thursday, June 25, 2015

Possible Approaches to Robot or Artificial Intelligence

With an engineering not scientific mindset, I am about to vastly simplify an extremely complex subject. With that qualification, there are two main ways we can tackle the problem of creating robot intelligence:
  1. Cognitive Robotics or Symbolic Modelling - attempts to create a model of the world in which everything can be represented by symbols. The robot controller can then parse these symbols in a manner similar to the way that a compiler creates machine code from a high level programming language. This approach suits computers, however reducing the world to symbols is a non-trivial task.
  2. Behavioural Robotics - creates emergent behaviours by having a number of prioritised responses to various situations. For example, a robot could have a behaviour which avoids walls and drops this would be a higher priority than performing a task like following a line or heading towards the brightest light. By layering behaviours on top of each other we create a system which can respond to a changing environment without having to specify what to do in exactly every circumstance.
Symbolic Modelling takes significant computing resources and isn't suited to a cheap micro-controller application. Given our constraints, this makes our choice of approach easy. Behavioural robotics is also the approach which is currently preferred by the academics (for what that is worth). More importantly, a behavioural robot can be built in stages and each behaviour debugged separately. This makes life easier and models how organisms evolve over time with increasing complexity.

The ultimate expression of behavioural robotics is to create artificial neurons which are not intrinsically intelligent but with enough connections create a neural network with emergent intelligence. We wont be attempting to crack that nut.

To design our robot intelligence we will use a behaviour diagram (from the book: Robot Programming : A Practical Guide to Behavior-Based Robotics by  Joe Jones), which looks something like the following diagram. This is a simple way to represent the robot control scheme. Input from sensors are shown on the left, these trigger behaviours which are manifested by the robot doing something (e.g. moving). The correct behaviour will be chosen by the "arbiter" based on priority.


We will develop AVA's behaviour diagram in a subsequent post.

Saturday, June 20, 2015

Introduction & Objectives

Overview

I have always been fascinated by robots and robotics. This blog will document the building of AVA. AVA is intended to be a fully autonomous robot which can react based on a number of layered behavioural patterns. I will go into the philosophy of behavioural based robotics in a subsequent post.

AVA's brains will be built using networked Arduino's. Arduino is an open-source electronics platform based on hardware which comes in a number of configurations based on your requirements and a free Integrated Development Environment (IDE) which allows you to program the microcontroller in C++.

The initial state of my robot prototype is shown in the following (overly dramatic) video.



Because I am using a behavioural approach to controlling the robot, Arduino's should give me sufficient computing power, relatively cheaply. Should I need more processing grunt the design will scale through the addition of a Raspberry Pi or PCDuino.

Even though the Arduino's have a pretty miserable clock speed (usually 16 MHz) compared to modern computer gear (e.g. even an iPhone 6 has a clock speed of 1.4 GHz), they are much better at controlling quickly changing inputs and outputs because that is all that they are doing.

Keeping with the spirit of the Arduino community, any software developed will be provided here with the appropriate permissive licences required for you to use within your own project.

Objectives

  1. Autonomous
  2. Has Voice Recognition and Voice Synthesis
  3. Knows - time, date, temperature, humidity, light level and battery charge.
  4. Will be able to perform the following tasks within a behavioural hierarchy (I will explain this):
  • Find Station and Recharge
  • Follow designated target
  • Remote control (telemetry) via WiFi
  • Patrol (challenge and video)

Micro Controllers

Master Controller



The Arduino's communicate using an I2C bus which requires only 2 wires. The master controller will be an Arduino Mega 2560 (Rev 3). Most of the sensors will connect to the Mega as will the motor control lines, quadrature encoders, voice recognition, voice synthesis and battery monitoring. I have actually used the Freetronics version of the Mega 2560 which is called the EtherMega. The EtherMega is a souped up version of the original design which includes ethernet functionality (which I'm not currently using but hey there is never such a thing as too much functionality and no doubt I will come up with some way to use it in the future). I have used Freetronics versions of the Arduino hardware where I can because of the additional functionality of their designs and to support a local Aussie company. I am going to use the Freetronic version names and official Arduino names interchangeably.

Logging, Sound Output and Input Controller



The next controller on the bus is a Freetronics "Eleven". This is a version of the Arduino Uno and controls the 128 x 128 pixel OLED Shield via the Shield Adapter. This shield includes a micro SD card, piezo buzzer and joystick controller which uses most of the digital input/outputs of the Eleven. The I2C bus connects to two of the analogue pins (A4 and A5) and the joystick position is monitored by two other (A2 and A3).

Interestingly (to me at least), the Eleven communicates with the OLED using a Serial Peripheral Interface (SPI) bus. So this Arduino is using two communication protocols at the same time, not to mention the serial interface used to program the chip via my Mac. The SPI is a 4 wire bus.

This controller will log status to the screen and microSD card, provide audio feedback via the piezo (until voice synthesis is added) and allow me to provide input via the joystick and button.



LCD and Temperature Sensor Controller


I have another Eleven connected on the I2C bus which controls a 2 x 16 character LCD via a LCD and Keypad Shield. This has a DS18B20 temperature sensor connected which uses the LCD to display the current temp. I only added this because I already had one built, but the temperature will come in handy when I add the sonar sensors since the speed of sound is effected by temperature (and barometric pressure). More on this in due course.



Real Time Clock (RTC) Module



To allow behaviours based on the time and date, the robot needs to know what the current date and time is. It is also useful for time stamping log entries. To allow this, there is a Freetronics  RTC module connected to the I2C bus.

I will do a separate post about each of the micro controllers and go into the hardware and setup configurations in depth.

Robot Platform

A robot is not much of a robot if it can't move. For AVA, movement will be provided courtesy of the Arlo Robotic Platform System from Parallax. The Arlo platform can carry up to 27kg so that should be sufficient for what I have planned.

Constructing the platform will be documented here.