Subject:
|
Re: Need help to put sound in Minerva Program.
|
Newsgroups:
|
lugnet.robotics.rcx.nqc
|
Date:
|
Mon, 1 May 2000 13:45:50 GMT
|
Viewed:
|
1972 times
|
| |
| |
Hi Bob,
I've attached a modified version of the Minerva program. It plays
different sounds for each of the following events:
1. Moving forward : ascending arpeggio
2. Turning around : descending arpeggio
3. Found something to pick up : deedle-deedle
I'm sure you'll be able to modify these as you see fit.
Regards,
Jonathan
-----
#define TURNAROUND_TIME 425
int i;
task main() {
// Arm limit sensor and grabber light sensor.
SetSensor(SENSOR_3, SENSOR_LIGHT);
SetPower(OUT_A + OUT_C, OUT_FULL);
calibrate();
i = 0;
while (i < 5) {
retrieve();
i += 1;
}
Off(OUT_A + OUT_C);
}
#define NUMBER_OF_SAMPLES 10
int runningTotal;
int threshold;
sub calibrate() {
// Take an average light reading.
i = 0;
runningTotal = 0;
while (i < NUMBER_OF_SAMPLES) {
runningTotal += SENSOR_3;
Wait(10);
i += 1;
}
threshold = runningTotal / NUMBER_OF_SAMPLES;
}
void grab() {
// Run the motor until we hit the limit switch.
OnFwd(OUT_A);
until (SENSOR_3 == 100);
// Back off from the switch.
OnRev(OUT_A);
until (SENSOR_3 != 100);
Off(OUT_A);
}
void release() {
// Run the motor until we hit the limit switch.
OnRev(OUT_A);
until (SENSOR_3 == 100);
// Back off from the switch.
OnFwd(OUT_A);
until (SENSOR_3 != 100);
Off(OUT_A);
}
int returnTime;
sub retrieve() {
// Drive forward until we see something.
OnFwd(OUT_C);
PlaySound(SOUND_UP);
ClearTimer(0);
until (SENSOR_3 < threshold - 3);
// Play a sound to signal we've found something.
PlayTone(660, 10);
PlayTone(494, 10);
PlayTone(660, 10);
PlayTone(494, 10);
PlayTone(660, 10);
PlayTone(494, 10);
Wait(20); // Move up on it a little.
returnTime = Timer(0);
Off(OUT_C);
grab();
// Turn around (roughly).
OnRev(OUT_C);
PlaySound(SOUND_DOWN);
Wait(TURNAROUND_TIME);
// Drive back.
OnFwd(OUT_C);
PlaySound(SOUND_UP);
ClearTimer(0);
until (Timer(0) >= returnTime);
Off(OUT_C);
release();
// Turn around.
OnRev(OUT_C);
PlaySound(SOUND_DOWN);
Wait(TURNAROUND_TIME);
}
-----
|
|
Message has 1 Reply:
Message is in Reply To:
4 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|