Difference between revisions of "Project adMIRE"
(→Project Files) |
|||
(8 intermediate revisions by 2 users not shown) | |||
Line 13: | Line 13: | ||
It can run and sing at the same time. When a black path crosses his way, he stops, then turns around and continues his journey. If he reaches the edge of a clif, don't worry, he won't fall, he will find the proper way to go :). | It can run and sing at the same time. When a black path crosses his way, he stops, then turns around and continues his journey. If he reaches the edge of a clif, don't worry, he won't fall, he will find the proper way to go :). | ||
− | '''Hardware Design''': Our robot consists of a basic ACROBot to which we have attached a light | + | '''Hardware Design''': Our robot consists of a basic ACROBot to which we have attached a light sensor and a piezoelectric speaker. |
− | '''Software Design''': There is a main loop on which the robot | + | '''Software Design''': There is a main loop on which the robot analizes its current state and decides whether to stop, turn around or to move forward. We also have auxiliar functions for creating the sounds. |
+ | |||
+ | '''Source code''' | ||
+ | <source lang="c"> | ||
+ | #include <Servo.h> | ||
+ | #define SerialSpeed 9600 | ||
+ | #define SampFrequency 10 | ||
+ | #define AnalogPIN 5 | ||
+ | #define SENSOR_1 1 | ||
+ | |||
+ | |||
+ | Servo LeftServo; | ||
+ | Servo RightServo; | ||
+ | |||
+ | |||
+ | #define FAST 50 | ||
+ | #define SLOW 5 | ||
+ | |||
+ | |||
+ | int speakerPin = 4; | ||
+ | int length = 15; | ||
+ | char notes[] = "ccggaagffeeddc "; | ||
+ | int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; | ||
+ | int tempo = 300; | ||
+ | |||
+ | void playTone(int tone, int duration) { | ||
+ | for (long i = 0; i < duration * 1000L; i += tone * 2) { | ||
+ | digitalWrite(speakerPin, HIGH); | ||
+ | delayMicroseconds(tone); | ||
+ | digitalWrite(speakerPin, LOW); | ||
+ | delayMicroseconds(tone); | ||
+ | if(analogRead(SENSOR_1)>=750) return; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void playNote(char note, int duration) { | ||
+ | char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' }; | ||
+ | int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 }; | ||
+ | |||
+ | |||
+ | for (int i = 0; i < 8; i++) { | ||
+ | if (names[i] == note) { | ||
+ | playTone(tones[i], duration); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void setup() { | ||
+ | pinMode(speakerPin, OUTPUT); | ||
+ | Serial.begin(SerialSpeed); | ||
+ | LeftServo.attach(9); | ||
+ | RightServo.attach(10); | ||
+ | LeftServo.write(90 + FAST); | ||
+ | RightServo.write(90 - FAST); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | for (int i = 0; i < length; i++) { | ||
+ | if (notes[i] == ' ') { | ||
+ | delay(beats[i] * tempo); | ||
+ | } else { | ||
+ | playNote(notes[i], beats[i] * tempo); | ||
+ | } | ||
+ | |||
+ | |||
+ | //Serial.println( analogRead(AnalogPIN)); | ||
+ | if(analogRead(SENSOR_1)<750) | ||
+ | { LeftServo.write(90 + FAST); | ||
+ | RightServo.write(90 - FAST); | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | LeftServo.write(90); | ||
+ | RightServo.write(90); | ||
+ | delay(1500); | ||
+ | noTone(speakerPin); | ||
+ | LeftServo.write(90 - FAST); | ||
+ | RightServo.write(90 + FAST); | ||
+ | delay(1000); | ||
+ | LeftServo.write(90 + FAST); | ||
+ | RightServo.write(90 + FAST); | ||
+ | delay(1000); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
== Project Files == | == Project Files == | ||
Line 24: | Line 109: | ||
| Project documentation || [[Media:MyDocumentation.pdf]] | | Project documentation || [[Media:MyDocumentation.pdf]] | ||
|- | |- | ||
− | | Project | + | | Project source code || [[Media:admire.c]] |
+ | |- | ||
+ | | Project movie || [http://robotika.sk/holls/2010/video/admire.avi AdMire.avi] (17 MB) | ||
|- | |- | ||
|} | |} | ||
Line 31: | Line 118: | ||
Go back to the [[Summer_School_2010#Projects|List of the projects]] | Go back to the [[Summer_School_2010#Projects|List of the projects]] | ||
− | [[Category:Projects]] | + | [[Category:Projects]][[Category:Robotic_Summer_School_2010]] |
__notoc__ | __notoc__ |
Latest revision as of 09:59, 24 July 2010
Overview
Authors: Adrian-Valentin MARINESCU/Mirela MOGA
Countries: Romania
Date: 11.07.2010
Activity: R.U.R. - Summer School 2010
Abstract
Welcome to adMIRE!
It can run and sing at the same time. When a black path crosses his way, he stops, then turns around and continues his journey. If he reaches the edge of a clif, don't worry, he won't fall, he will find the proper way to go :).
Hardware Design: Our robot consists of a basic ACROBot to which we have attached a light sensor and a piezoelectric speaker.
Software Design: There is a main loop on which the robot analizes its current state and decides whether to stop, turn around or to move forward. We also have auxiliar functions for creating the sounds.
Source code
#include <Servo.h>
#define SerialSpeed 9600
#define SampFrequency 10
#define AnalogPIN 5
#define SENSOR_1 1
Servo LeftServo;
Servo RightServo;
#define FAST 50
#define SLOW 5
int speakerPin = 4;
int length = 15;
char notes[] = "ccggaagffeeddc ";
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
if(analogRead(SENSOR_1)>=750) return;
}
}
void playNote(char note, int duration) {
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
for (int i = 0; i < 8; i++) {
if (names[i] == note) {
playTone(tones[i], duration);
}
}
}
void setup() {
pinMode(speakerPin, OUTPUT);
Serial.begin(SerialSpeed);
LeftServo.attach(9);
RightServo.attach(10);
LeftServo.write(90 + FAST);
RightServo.write(90 - FAST);
}
void loop() {
for (int i = 0; i < length; i++) {
if (notes[i] == ' ') {
delay(beats[i] * tempo);
} else {
playNote(notes[i], beats[i] * tempo);
}
//Serial.println( analogRead(AnalogPIN));
if(analogRead(SENSOR_1)<750)
{ LeftServo.write(90 + FAST);
RightServo.write(90 - FAST);
}
else
{
LeftServo.write(90);
RightServo.write(90);
delay(1500);
noTone(speakerPin);
LeftServo.write(90 - FAST);
RightServo.write(90 + FAST);
delay(1000);
LeftServo.write(90 + FAST);
RightServo.write(90 + FAST);
delay(1000);
}
}
}
Project Files
Description | Download |
Project documentation | Media:MyDocumentation.pdf |
Project source code | Media:admire.c |
Project movie | AdMire.avi (17 MB) |
Go back to the List of the projects