![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Dependencies: mbed Motor mbed-rtos
Useless Robot
Useless Robot Overview
Project by Austin Bartmess and Jeremy Deremer
This is a robot developed on an ARM Microcontroller (LPC 1768). It uses a servo, two DC motors both powered by an external power source, nine red LEDs, two RBG LEDs, a speaker, a toggle switch and a transistor.
The goal of this robot is to stay off. However, the user can turn it on without harm. It attempts to stay off via turning a toggle switch off with an arm attached to a servo. If the robot is turned on too much, it will progressively get angry. It starts by not smiling and changing eye colors. Following that, the robot will frown and yell at the user. Finally, the robot will drive around randomly while screaming and looking angry via its LEDs.
Required Parts
- mbed Microcontroller x1
- USB to mini USB cable x1
- Servo x1
- H-Bridge Breakout Board x1
- DC Motors x2
- DC Motor Wheels x4
- Red LEDs x9
- RGB LEDs x2
- 0.5W Speaker x1
- Toggle Switch x1
- BJTransistor x1
- Jumper Cables Kit x1
- Breadboard x2
Pinout and Connections
Mbed | H-Bridge | DC Motors | Servo | Transistor | Speaker | LEDs | Barrel Jack | Toggle Switch |
---|---|---|---|---|---|---|---|---|
GND | GND | (-) | Emitter | (-) | GND | (-) | (-) | |
Vu | ||||||||
Vin | Vm | (+) | (+) | |||||
Vout | Vcc, /STBY | (+) | ||||||
p5 | AIN1 | |||||||
p6 | AIN2 | |||||||
p10 | LED+ | |||||||
p11 | LED+ | |||||||
p12 | LED+ | |||||||
p15 | Control | |||||||
p21 | PWMA | |||||||
p22 | Collector | |||||||
p23 | Blue | |||||||
p24 | Green | |||||||
p25 | Red | |||||||
p26 | Control | |||||||
AO1 | (+) | |||||||
AO2 | (-) |
Demo Clip
Source Code
Diff: main.cpp
- Revision:
- 2:69a3683834c7
- Parent:
- 1:0402db7e91f5
- Child:
- 3:a7bd2f5946ed
diff -r 0402db7e91f5 -r 69a3683834c7 main.cpp --- a/main.cpp Wed Apr 26 21:14:28 2017 +0000 +++ b/main.cpp Thu Apr 27 03:53:55 2017 +0000 @@ -1,6 +1,10 @@ #include "mbed.h" #include "rtos.h" +#include "Servo.h" #include "RGBLed.h" +#include "wave_player.h" +#include "SDFileSystem.h" +#include "Motor.h" #include "uLCD_4DGL.h" DigitalOut led1(LED1); @@ -12,11 +16,25 @@ InterruptIn Switch(p15); +//SERVO for arm +Servo arm(p22); + +//LEDS PwmOut red(p21); PwmOut green(p22); PwmOut blue(p23); -uLCD_4DGL uLCD(p9, p10, p11); +//SD card/audio +PwmOut PWMout(p25); +AnalogOut DACout(p18); +SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board +wave_player waver(&DACout,&PWMout); +char buffer[20]; +FILE *wave_file; + +//motor for wheels +Motor wheelF(p21, p6, p5); // pwm, fwd, rev +Motor wheelB(p21, p6, p5); // pwm, fwd, rev Thread t1; // Arm Response Thread t2; // LED Color @@ -25,17 +43,29 @@ Mutex state; int angerlevel; - bool pushFlag = false; -void ArmThread() -{ +void ArmThread() { //basic if switch is toggled then use arm to turn it off + //TODO: setup angle/speed for reasonable opening according to angerlevel //Want to add delay depedning on anger level //Potentially need a queue system if (pushFlag) { //start servo + while (1) + { + for(float p=0; p<1.0; p += 0.1) + { + arm = p; + wait(0.4); + } + for(float p=1; p>0.0; p -= 0.1) + { + arm = p; + wait(0.4); + } + } state.lock(); //lock to update the anger level angerlevel++; state.unlock(); @@ -43,8 +73,9 @@ } void LEDThread() { + //TODO: Add colors according to angerlevel state.lock(); //lock to read the angerlevel - switch(angerlevel) + switch(angerlevel){ case 1: state.unlock(); //turn on leds @@ -61,17 +92,25 @@ state.unlock(); //case 0 do nothing break; + } state.unlock(); } void AudioThread() { //PWM/AMP? to play audio? - //need to get sd card & angry sounds for audio + //TODO: get sound on SD card and confirm this will work + //mabye multiple sounds according to what angerlevel state.lock(); //lock to read the angerlevel - switch(angerlevel) + switch(angerlevel){ case 2: state.unlock(); //AUDIO + for (int a=1;a<40; a++){ + sprintf(buffer,"/sd//voice%d.wav",a); + wave_file=fopen(buffer,"r"); + waver.play(wave_file); + fclose(wave_file); + } break; case 3: state.unlock(); @@ -81,21 +120,31 @@ state.unlock(); //Nothing to do here break; + } state.unlock(); } void WheelsThread() { //Drive around randomly + //TODO: add random driving for both motors(current:example for 1 motor) state.lock(); //lock to read the angerlevel - switch(angerlevel) + switch(angerlevel){ case 3: state.unlock(); - //MOTOR + for (float s= -1.0; s < 1.0 ; s += 0.01) { + wheelF.speed(s); + wait(0.04); + } + for (float s= 1.0; s > -1.0 ; s -= 0.01) { + wheelF.speed(s); + wait(0.04); + } break; default: state.unlock(); //nothing break; + } state.unlock(); } @@ -105,8 +154,13 @@ } void init(){ - interrupt.fall(&fallInterrupt); - interrupt.mode(PullUp); + Switch.fall(&fallInterrupt); + Switch.mode(PullUp); + + + //setup PWM hardware for a Class D style audio output + PWMout.period(1.0/400000.0); + }