dinsdag 18 december 2012

IR communication on the self made controller

Dear readers


Stef Ingels and I managed to program the infra red communication today. After we programmed a bootloader onto the fourth contoller we made.
First of al we made sure that the led and TSOP were functioning fine we uploadet the complete program onto the microcontroller. with succes.

In the movie under this post you can see how the robot answers to the commands we give him. For an explanation how the infrared communication works see the posts below.

Your blogmeister
Giete

Our IR transmit/receive module

dear readers

to communicate whit the robot, we needed an ir module with an ir led and TSOP 2238 on it. The schedule is given below:



A picture of how it looks like:



It is not possible to place the module directly to our computer, we connect it to an arduino were the computerprogram is uploaded to. Trough the serial monitor of arduino we can communicate with our arduino and so send with the LED to our robot. To communicate with the arduino we use several abbreviations/codes. The list with codes and a short explanation:


Greets 

Stef



The final microcontroller bord

dear readers


Because our previous 3 microcontrollers were crached, we decided to make another board. This time with true hole components, because we had not the time to make another print. A picture of the print can you see below:


The schedule is lightly different then our PCB. This because the atmega328 PU we are using has 28 pins instead of 32 on the smd atmega328 we were using. On the smd atmega are 2 more analog channels, one more ground and one more VCC. Also we changed the clock to 16 MHz, this to avoid our problems with burning a boatloader on it. The rest of the schedule is the same as that of the prints we made before. 
the schedule for the microcontroller:


In the message that guillaime posted earlier, he explains how to burn a bootloader and configure the microcontroller.


greets

Stef


Testing the complete robot for the first time

Dear readers


Last night I managed to finetune my program in such a way that it reacts to a change of position.

How did I finetune?

After I wrote the final peace of the program (being the pid control an pwm output) I uploaded it into an arduino hooked up to the robot. I din't connect the engine's in the first stadium. I just tested my white calibration and black calibration. This worked out fine. You can see how it works in the first video below. After de white an black values were set I putted al the results of every calculation on the serial monitor with a delay at the end. This way I could monitor the programs every move. Check everything as well. I made modifications where needed.

After I tough that I figured it out I uploaded the program again an this time I connected the engines. I didn't put the wheels on the ground because my test set-up did not allow me to let it ride (to many cables attached to the computer). The first two or three attempts weren't good. I had a unforeseen problem. One of the engines gearboxes didn't function well. I tried to fix this by setting the standard pwm value a lot higher for this engine. This somewhat worked but every time the engine comes in lower rev areas is has the intention to stall. I will have to take a look at the gearbox later and hope that its fixable. My efforts weren't in vain tough because I managed to make al little film that shows you how the wheels react to the changing position.

All the talking is in Dutch because were from belgium (off course you already knew this).
So I tried to put subtitles in the film. I hope you guy's approve.


Yours sincerely
Giete

maandag 17 december 2012

Programming the microcontrollers

Dear readers


We managed to make upload programmes in our micro controller. It wasn't easy at all. And after we managed to do is I wrote a guide for you guys so you can do it yourselves. I hope you enjoy it.

Here it is!

1 The goal of this guide

After reading the short guide you should be capable to load up your own program(written in Arduino). To a atmega328 connected to a 20MHz cristal.
The longer guide explains how you can adjust the board.txt file and avrdude.conf file to a microchip of your choice. In this guide you will learn what to adjust an how. In the short guide this is already done for you. The long guide is an extension to the sort one.

2 Short guide

2.1 Getting started(prepare yourselves)

First make sure that you can connect the reset, MOSI, MISO and SCK pin easily to the Arduino and that you can supply the microcontroller with a 5V or 3,3V stabilized voltage.
Download WinAVR, you can use the link below or you can look for it yourself. http://winavr.sourceforge.net/download.html
After downloading WinAVR you may install this program. We will need this later on.

2.2 Checking for a signature(look if it is alive)

After you made sure all this is possible, you may open an empty Arduino file.
Go to ‘File’ -> ‘Examples’ -> ‘ArduinoISP’
(You can go ahead and read this file because some of this guide is based on the text above the program.)
After you did this you may connect the three leds as the text in the program asks you to do. After this you ma upload the program in your Arduino. (check your board en serial port first).
Once the uploading is done you should have one of the three leds (the one on pin9) glowing softly. This is your heartbeat. If this led ever burns constantly then you should reset the Arduino your working on. This may or may not be necessary later on. It depends on how lucky you are.
After all this is done you may change the settings of the Arduino software to:
- ‘Tools’ -> ‘Board’ -> ‘atmega duemilanove w/ATmega 328’ (it has to be this regardless of what board you’re using.)
- ‘Tools’ -> ‘Programmer’ -> ‘Arduino as ISP’
- ‘File’ -> ‘Preferences’ -> Mark the checkboxes ‘compilation’ and ‘upload’

This is all for the software. You already connected the three leds to pin 7,8 and 9 of the Arduino (except when you’re using a MEGA check the text above the Arduino ISP program to see which pins you should use).
Now, connect the MOSI, MISO, SCK and reset pin according to the following table (again this table is NOT for Arduino MEGA’s check the text above Arduino ISP for that!!):
Pin Controller                          Pin Arduino
Reset                                       10
Mosi                                        11
Miso                                        12
sck                                          13

NOTE: make sure the ground of the Arduino and the microcontroller are connected. It won’t work if these aren’t connected!!

Once this is done the hardware and software parts are all ready to check if the microcontroller is alive.
Go to ‘Tools’ then click ‘burn bootloader’. IT WONT WORK! So don’t panic. You’ll get (if everyting goes as planned) this error. The printscreen was taken at the bottom of the errorlist under the progrmcode of the arduino software. You can see (aproximately halfway this picture) ‘device signature = 0x1e9514’ this is a good sign. When a microcontroller answers with it’s signature it works just fine. Next step, we are going to adapt the software to our needs.


2.3 Adapting the software to our needs

You can find two files you need to download on our blog (http://auto-3am-gr9.blogspot.be/). It will be under the subject where you found this guide. (in these folder the changes have been made for a atemega 328 with a 20MHz crystal. The long guide learns you how to do this so you can do this for yourself and maybe other microcontrollers.)
Now I will tell you where these folders need to be replaced.

2.3.1 Board.txt

Go to the folder where you’re Arduino software is located. Once inside this folder go to ‘hardware’ -> ‘arduino’ you can see the board file there. Just copy the new one in this folder and replace it for the old one. Close this window.

2.3.2 Avrdude.conf

If you installed WinAVR correctly (like I asked in the beginning of this guide) the you sould find a folder named ‘WinAVR-20100110’ on your primary hard drive. Open this folder and go to ‘bin’. In this folder you will see the Avrdude.conf file (if you look hard enough or use Ctrl-f..). Now replace this folder with the one you downloaded from our blog. Close the window.

NOTE: close all windows of Arduino software so it can adapt to the new board file!
After you did this we are done adapting the software!

2.4 Adapt the Low fuse of the microcontroller

This is where the fun starts. We will now start controlling the controller.

Open cmd. Now type in the following command ‘avrdude –P com?? –b 19200 –c stk500V1 –p m328g -v -v’

Fill on the ?? the serial port which you’re Arduino is currently using.

This should sum up some facts of your microcontroller. You should get something like the picture below


On the bottom of this picture (and hopefully you cmd screen) you can see that the device signature is still there (lucky us, it’s still alive) and under the signature you van se ‘lfuse ready as 62’ this means (among other things) that the microcontroller is running on his internal clock of 1MHz. We don’t want this because is screws up all our programs. We want it to run on the 20MHz crystal. This is what we are going to do:

Type in the following command: ‘avrdude -P com?? -b 19200 stk500V1 -p m328g -U lfuse:w:0xFF:m’. Again, the question marks are to be replaced by your serial port. BEFORE YOU PRESS ‘ENTER’ MAKE SURE THAT I’TS lfuse AND NOT hfuse!!!!! If you write hfuse you will lock down the microswitch forever.

Now we are sure that things are correct, press enter. You should get a screen like the picture below.


The microcontroller is now ready for us to put a program on it.

2.5 Uploading the software

Open the software you want to upload. Do this with Arduino. If everything went according to plan (or guide..) then go to ‘Tools’ -> ‘Boards’ -> ‘ATmega328 van Glenn’. Set the programmer to ‘arduino as ISP’. Also check if the checkboxes in ‘file’ -> ‘preferences’ are still on.

Now click on COMPILE!! Not upload, you will ruin everything.

NOTE: If you did click upload than repeat ‘checking for a signature’ to check if everything is still working and repair the mistake you made.

After you clicked on compile, you should see a lot of stuff going on in the black screen below your program. After it is finished you should see something like the picture below on the bottom of that screen.


If we magnify it, it looks like this:


Now open cmd again. The file path you see highlighted in bleu is this guide is specific for our computer so don’t copy this file path, use the one you have on your screen.

You can go to a file by using the ‘cd’ command. Look at the pictures below to see how we did it.


Again, this is the file path for our computer, don’t copy this completely it won’t work.

Now, once you are in the correct build map you can check if your file is in this file. You can do this by using the command ‘ls’ as you can see in the picture below.


Once you made sure it’s there type in the following command: ‘avrdude –P com?? –b 19200 –c stk500V1 –p m328g –U flash:w:??.cpp.hex

For the first pair of questionmarks, fill in the serial port of your Arduino. For the second question marks check your compiled file on Arduino to see what the name of the file is and fill it in. (please use ‘.cpp.hex’ only once)

Press enter and if you obeyed this guide as you should have done then you should see the program uploading on your microcontroller.

3 The end

Thank you for using this guide I hope you’ll enjoy it!

I would like to thank the team that made most of this possible. So thank you Laurens, Glenn and Mathijs

I would also like to thank my team. Thank you Stef, Stef and Réné.

And finally I would like to thank the lector who helped us, thank you Mr. Lievens

NOTE: sorry for mistakes I may or may not have made against the English language, I’m from Belgium so English isn’t my native language.



Brought to you by
Giete

dinsdag 4 december 2012

Dear reader(s),

Yesterday we did some testing involving our sensor array and the program we use to calibrate/normalize the value's
We calibrated the sensors and put the feedback of our program in a graph at different hights
this is the graph we had at the best hight, 10mm between line and print.

Image and video hosting by TinyPic
As you can see the value's are pretty linear, a negative value means the program has to steer to the right.
A positive value means the program will have to steer to the left.