Robot Project Day 7 – Testing Your Robot

Previous: Day 6 – Arduino Sketch

To recap our connections will roughly look like this:

Your client PC -> Your Raspbery Pi (which contains Arduino Sketch)  -> Motor Controller via USB cable -> 4 Servo Motors 

First, you need to know if you get a response from your Pi. Log into your Pi via SSH, and use your favourite application to test your connection to the Arduino Sketch via serial console.

One of the following popular commands / applications can be used to connect to your serial console:

  1. cu command
  2. screen command
  3. minicom command
  4. putty command
  5. tip command

We installed minicom on the Pi.

sudo apt-get install minicom

To check which port available, run the following:

 dmesg | egrep --color 'serial|ttyS'

Set up  minicom, and follow the options to send some input to the serial.

sudo minicom -s
  • Select “serial port setup”
  • Change option A (device) to “/dev/ttyUSB0″ (case sensitive!)
  • And make sure that both hardware & software flow control are set to “NO”
  • Go back to main menu and select “save as dfl” (saves as default setting)
  • Select “exit” – and minicom should now launch.

Screenshot - 08102014 - 04:03:18 PMThis basically shows that /dev/ttyUSB0 is ready for connection. You should see some text output from your Arduino device that you have set up in the device’s sketch.

In our Arduino sketch (from Day 6 tutorial) we have a serial listener that would respond to the following key strokes:

  • a = left
  • w = forward
  • d = right
  • s = stop
  • x = backward

Try keying in the above characters. If the program in you controller device responds, it would forward  the corresponding signals to the motor controller to move the wheels accordingly. You may have to do some debugging if the connection does not work.

Raspberry Pi Model B+ New Features

2014-07-14-11-17-59-am-620x226

What changes from Model B:

  • 4 USB ports in B+ as opposed to 2 in Model B.
  • MicroSD card slot, instead of the normal SD card slot.
  • 40 GPIO pins. Additional of 14 pins.
  • Reduced power consumption, which is 30% more efficient.
  • New form factor, which means you would need a new enclosure.
  • Improved audio, low noise power supply.

What did not change:

  • The RAM is still 512MB.
  • Processor 700MHz low-power ARM1176JZ-F is retained.
  • Based on Broadcom BCM2835 SoC chipsets.
  • Cheap price around $40.
  • It still takes 5V 1A power supply.
  • It still runs Raspbian, RaspBMC, and other Linux goodness.

 

0 A.D. Real Time Strategy Game for Linux

If you liked Age of Empire series from old PC days, a group of open-source developers came up with brilliant game that has similar looks and gameplay. It is free to download and you can play single mode or go against other human / A.I. opponents in multiplayer setting. This game can run on multi-platform machines, so you can play those who run Operating Systems other than Linux.

Install the game on Ubuntu / Mint with the following command:

sudo apt-get install 0ad

To play select 0ad from the menu or via command line:

0ad

0ad

Civilizations

0 A.D. will allow the player to control any of eleven ancient civilisations from antiquity.

  • The Carthaginians will have the strongest navy in the game, as well as the best trade. Units include the war elephant and the Sacred Band. Most of their troop roster, however, is made up of expensive mercenaries.carthaginian-land-units
  • The two Celtic factions excel in hand-to-hand combat. They have minimal navy and siege. They construct mostly wooden buildings, which are fast and inexpensive to construct, though far less robust than their stone counterparts.
    • The Britons use war dogs and chariots in battle and construct crannogs. They also have the longswordsmen and powerful melee soldiers.
    • The Gauls possess the first rotary flour mill and field the heaviest infantry and cavalry among the Celtic civilisations.
  • The three Hellenic factions share a number of attributes including strong buildings, strong triremes, cheaper technologies, and the phalanx formation, which makes their Hoplites nearly invulnerable when attacked from the front.
    • The Athenians possess strong culture, exemplified in a number of unique structures including the theatre and gymnasium. Additionally, the Athenian navy is the most powerful among the Hellenic civilisations.
    • The Macedonians field a varied and well-rounded military with the unique syntagma formation available to its infantry. Their siege capabilities are considerable, including their unique siege towers, immense, mobile wooden constructs able to garrison large numbers of archers.
    • The Spartans field a less-varied military than that of the other Hellenistic civilizations, but are able to use their melee infantry to deadly effect in the phalanx formation.
  • The Iberians’ foot units are some of the fastest and most rapid-firing in the game, particularly their Balearic Slingers. A number of their ranged units also have the unique ability to fire flaming missiles. Toledo steel grants them superior metal weaponry.
  • The Mauryan Indians represent the Maurya Empire in India. While they have no siege units, they do have access to three different elephant units including the Worker Elephant, a mobile dropsite that can also repair buildings.
  • The Persians are the most cosmopolitan civilization, levying a wide variety of troops from their vassal satrapies. Their infantry are weak and poorly-equipped, but can be massed in vast numbers. They have the strongest (though most expensive) cavalry in the game, and are the only civilisation that features all forms of cavalry, including cavalry archers in the form of scythe chariots. Their buildings are also the strongest in the game.
  • The Romans train the strongest swordsman (the Hastatus) in the game as well as construct the most powerful siege equipment. Other bonuses include the ability to construct siege walls to circumvallate enemy cities in enemy territory.
  • The Ptolemies have a strong farming abilities. This along with their great prowess on the water makes them great warriors and great allies.

Gameplay

You started off by gathering resources, creating economic and military buildings, workers and armies, and advancing to the next age. You can upgrade weapons, multiply the units, and send them to battle-fields.

The whole point of the game is getting your opponent to vanish by destroying their buildings and killing off their units.

In multi-player mode, it is a lot of fun to group up in 2 teams and collaborate with each other to beat the opponents.

Minimum Requirements

To run this game you would need a half-decent spec such as the following:

  • Processor: Dual Core 2Ghz+
  • RAM: 4GB
  • Video Card: 1GB Radeon / Nvidia
  • Hard Disk: 150GB
  • Sound Card: On-board sound card and speakers will be ok
  • Internet Connection: 5Mbps downlink and 1Mbps uplink
  • OS: Linux, Windows, or Mac iOS

Go to http://play0ad.com/ for more information about the game.

Playing “Mission Impossible” Tune on a Arduino with 2 Voices

Dear Arduinoists,

Inspired by Dipto’s version of the Super Mario tune with two voice, I wanted to make my own tune. I had the notations of the MI-Theme for the easy piano lessons laying around, and I thought to myself, lets convert it. It was needed for a little game I was developing on Arduino.

Dipto’s approach was good, but it lacked the function to do other stuff while the melody was playing. It took me some time to figure it out, how to handle that. Maybe my approach is hacky, but it did the job.

I didn’t try to  copy and paste the notations into the other code, but it should work. Here I´ll provide  the whole code needed. I took out the functions needed, added a blinking LED for audio/visual experience, and compiled it on my Arduino mini.  Please make sure you use the piezo/buzzer/speaker on the PINS 7+8, and make sure you downloaded the right tone library (google: “rogue tone library”).  In order to make it compile, please change the #includes in the tone.cpp like stated in the code below and have the frequenzen.h // notes.h or whereever the frequencies are defined included in the project directory. The “frequenzen.h” is the very common file provided with the tone library demos.

If you´d like to download the code: http://www.xlr8.at/downloads/Mission_Impossible.zip

Inspired by these articles here:
http://www.linuxcircle.com/2013/03/31/playing-mario-bros-tune-with-arduino-and-piezo-buzzer/

and

http://www.linuxcircle.com/2013/04/03/play-mario-bros-harmonies-on-arduino-and-2-speakers/

Have fun, and happy compiling !

Cheers André

And here goes the code:

 

/*MISSION IMPOSSIBLE

Done by: André Thomas
24.01.2014

Taken out from a poker program I have written last year.
Idea for the 2-Tone same Speaker didn´t came from me.

“Mission Impossible” theme made for Arduino by me, note by note.
——————————————————————
For compiling you need Tone() from here

http://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation

Go into the Tone Directory and change tone.cpp header (includes) to this:

#include <avr/interrupt.h>
//#include <avr/pgmspace.h>
//#include <wiring.h>
#include <Arduino.h>

so it will compile.
——————————————————————

*/

#include <Tone.h>
#include “frequenzen.h”
#include <avr/pgmspace.h>

#define OUT1 7
#define OUT2 8

//Sound Vars
Tone notePlayer[2];
unsigned int Counts[] = { 0, 0};
unsigned long stopTimeNote1 = 0;
unsigned long stopTimeNote2 = 0;
int value;
int value2;
int dur;
int dur2;

//Mission Impossible // Game Finale Melodie
int mimp[]  PROGMEM = {
NOTE_DS5,
NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,
NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,
NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,
NOTE_D5,NOTE_DS5,NOTE_D5,NOTE_DS5,
NOTE_D5,NOTE_DS5,NOTE_F5,NOTE_FS5,NOTE_G5, // Upswing 5

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0,NOTE_G2,0,NOTE_AS2,0,NOTE_C3,0,
NOTE_G2,0,NOTE_G2,0,NOTE_F2,0,NOTE_FS2,0,

NOTE_G2,0

,-1
};

int mimpDur [] PROGMEM = {

50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,50,50,50,50,50,50,
50,50,50,50,
50,50,50,50,50,50,

200,400,200,400,200,200,200,200,              //2000
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,              //2000
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

400,-1
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_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,0    ,
NOTE_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,0    ,
NOTE_CS5,NOTE_F5,NOTE_AS5,NOTE_CS5,NOTE_F5,NOTE_AS5,NOTE_CS5,NOTE_F5,0    ,
NOTE_DS5,NOTE_G5,NOTE_C6,NOTE_DS5,NOTE_G5,NOTE_C6,NOTE_DS5,NOTE_G5,0,
NOTE_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,0    ,
NOTE_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,0    ,
NOTE_GS4,NOTE_C5,NOTE_F5,NOTE_GS4,NOTE_C5,NOTE_F5,NOTE_GS4,NOTE_C5,0     ,
NOTE_A4,NOTE_CS5,NOTE_FS5,NOTE_A4,NOTE_CS5,NOTE_FS5,NOTE_A4,NOTE_CS5,0,

NOTE_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,NOTE_G5,NOTE_AS4,NOTE_D5,0,-1

};

int mimp2Dur [] PROGMEM  = {

2025,    //+25 for the delayed melody

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

200,400,200,400,200,200,200,200,
200,400,200,400,200,200,200,200,

150,50,150,50,800,800,
150,50,150,50,800,800,
150,50,150,50,800,800,
150,50,400,1400,

200,200,600,1000,
200,200,600,1000,
200,200,600,1000,
200,400,1400,

25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,191,
25,25,25,25,25,25,25,25,191,
25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,191,
25,25,25,25,25,25,25,25,191,

25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,191,
25,25,25,25,25,25,25,25,191,
25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,391,
25,25,25,25,25,25,25,25,191,
25,25,25,25,25,25,25,25,191,

25,25,25,25,25,25,25,25,300, 0
};

int led = 13;   //Just a LED

void setup()
{
pinMode(led, OUTPUT);                         // Set pinmode
notePlayer[0].begin(OUT1);                    // Voice 1
notePlayer[1].begin(OUT2);                    // Voice 2
digitalWrite(led, LOW);                       // Turn off LED
}

void loop() {

playTune(mimp, mimpDur, mimp2 , mimp2Dur ,0);  //Play the tune

}

void playTune(int melody[],  int melDurations[], int harmony[],  int harmDurations[], boolean repeat )
{
value    = pgm_read_word(&melody[Counts[0]]);
value2   = pgm_read_word(&harmony[Counts[1]]);
dur      = pgm_read_word(&melDurations[Counts[0]]);
dur2     = pgm_read_word(&harmDurations[Counts[1]]);

if(value == -1 || value2 == -1) {
notePlayer[0].stop();
notePlayer[1].stop();
digitalWrite(led, LOW); // Just a visual check if it´s doin something
if(repeat == 1) {
value=0;value2=0;dur=0;dur2=0;Counts[0]=0;Counts[1]=0;
}
return;
}

if ( millis()>stopTimeNote1 ) {
if(value==0) {
if(notePlayer[0].isPlaying()) notePlayer[0].stop();
digitalWrite(led, LOW); // Just a visual check if it´s doin something
}
else{
notePlayer[0].play(value);
digitalWrite(led, HIGH); // Just a visual check if it´s doin something
}
stopTimeNote1 = millis() + dur;
if(value != -1 ) {Counts[0]++;}

}

if ( millis()>stopTimeNote2 ) {
if(value2==0) { if(notePlayer[1].isPlaying()) notePlayer[1].stop();    }
else{
notePlayer[1].play(value2);
}
stopTimeNote2 = millis() + dur2;
if(value2 != -1 ) {Counts[1]++;}

}
return;
}

void resetTone() {
Counts[0] = 0;
Counts[1] = 0;
stopTimeNote1 = 0;
stopTimeNote2 = 0;
notePlayer[0].stop();
notePlayer[1].stop();
value=0;
value2=0;
dur=0;
dur2=0;
}

 

 

 

Creative computing with Linux and Open Source Software, focusing on Raspberry Pi & Arduino technology