Mr. Boomba BT

ECE 4180 Project

Dave Patel (Section B), Max Rudolph (Section A), Edward Stevens (Section B)

A Bluetooth controlled robot with drive and aim/fire controls. The robot takes button and accelerometer inputs from the "Adafruit Bluefruit BLE" app installed on a companion iOS or Android device. We originally intended on mounting a nerf gun on top of the pan and tilt servos, but due to COVID-19, designing a custom mount was not feasible. Instead, the nerf gun can be replaced by any digital output device. In our case, we settled on a laser or LED, but with two strokes of bad luck, both the LED and laser happened to be dead and nonfunctional. Given our limited hardware, we finally decided to alarm a buzzer upon "firing".

Intended Final Product

https://os.mbed.com/media/uploads/dpatel344/49c940c7098d456b9e3aad5888082ce3.jpeg

Actual Result

https://os.mbed.com/media/uploads/dpatel344/16e1cc6ee78349029c3dc0e12b69a9da.jpeg


Presentation


Parts

Wiring

Power Supplies

mbedBarrel Jack from 6v Battery Pack5v Battery Pack (USB)
GNDGND
VIN (4.5v to 6v)+DC Out (6v)
USB supplyUSB power out

H-Bridge

mbedTB6612FNG H-BridgeBarrel Jack from 6v Battery PackLeft MotorRight Motor
GNDGNDGND
Pin 5AIN1
Pin 6AIN2
Pin 21PWMA
VMOT+DC Out (6v)
VOUTVCC & /STBY
Pin 11BIN1
Pin 12BIN2
Pin 22PWMB
AO1+LEAD
AO2-LEAD
BO1+LEAD
BO2-LEAD

Bluetooth Module

mbedAdafruit Bluefruit LE UART
GNDGND
VU (5v)VIN (3.3v to 16v)
DISCONNECTED (IGNORE)RTS
GNDCTS
Pin 27 (Serial RX)TXO
Pin 28 (Serial TX)RXI

Servos

mbedPanTiltBarrel Jack from 6v Battery Pack
GNDGNDGNDGND
Pin 23PWM Control
Pin 24PWM Control
POWERPOWER+DC Out (6v)

Software

Setup is rather simple. First, the companion "Adafruit Bluefruit BLE" app must be installed on the user's phone. After launching the app, pair with the Bluetooth module on the robot. Then, tap "controller" and enable the accelerometer. The control pad will then take you the screen shown below.

https://os.mbed.com/media/uploads/dpatel344/blecontrol.png

Source (Dr. Hamblen): https://os.mbed.com/users/4180_1/notebook/adafruit-bluefruit-le-uart-friend---bluetooth-low-/

Our code reads in the button data and X/Y gravity vectors from the phone's accelerometer then proceeds to issue commands to the motors and servos to execute the desired behavior. Button inputs are used to pan, tilt, and fire the laser (or any mounted digital output device), while the phone's tilt drives the actual robot. The arrow keys aim the laser in the respective direction, the '1' button toggles the laser (or other digital output device on pin 7), and the '2' button recenters the pan/tilt servos. Data is transferred through serial using the Adafruit Bluefruit LE UART module. Rather than use the available Motor class to control the motors, we decided to declare our own PwmOut and DigitalOut signals.

Note: In the demonstration below, the code does not distinguish between a button pressed and a button released. If you would like to have an action occur upon a press only, simply uncomment the lines regarding the "state" of the button. For reference, state = 1 means pressed, state = 0 means released.

Note: The servos take in a value from 0 to 1 and translate that to a position. For this reason, our chosen values are specific to our servos; you may have to tweak the bounds depending on the servos used.


You may import the program (includes the Servo library created by Simon Ford) directly into the mbed compiler or view the code below

Import programMrBoombaBT

ECE 4180 Final Project - Bluetooth Controlled Robot that aims/fires a Digital Output Device, in this case, a laser or buzzer

main.cpp

#include "mbed.h"
#include "Servo.h"

Serial bt(p28,p27); //tx,rx

Servo pan(p24);
Servo tilt(p23);

PwmOut left(p21);
PwmOut right(p22);

DigitalOut fwdl(p5);
DigitalOut revl(p6);

DigitalOut laser(p7);

DigitalOut fwdr(p11);
DigitalOut revr(p12);

union packet {
    
    float f;
    char c[4];
    
};

int main() {
    
    char button, temp = 0;
    union packet x, y; // range is -10 to 10

    // initialize servo to middle, motors off, and laser off
    fwdl = revl = fwdr = revr = 0;
    left = right = 0.0;
    pan = 0.5;
    tilt = 0.225;
    laser = 0;
    
    while (1) {
        
        if (bt.getc() == '!') {
            
            button = bt.getc();
            switch (button) {

                case 'B':  // if button
                
                    button = bt.getc();
                    //state = bt.getc();
                    
                    switch (button) {
                        
                        case '1':
                        
                            //if (state == '1') { // toggle the laser
                                
                            laser = !laser;
                            break;    
                            
                            //}      
                                          
                        case '2':  // recenter the laser
                        
                            //if (state == '1') {
                                
                            tilt = 0.225;
                            pan = 0.5;
                            wait(0.2);
                            break;
                            
                            //}
                        
                        case '5': // forward
                        
                            //if (state == '1') {
                                
                            if (tilt <= 0.05) {tilt = 0.0;}
                            else {tilt = tilt - 0.05;}
                            wait(0.1);
                            break;
                            
                            //}
                            
                        case '6': // backward
                            
                            //if (state == '1') {
                                
                            if (tilt >= 0.40) {tilt = 0.45;}
                            else {tilt = tilt + 0.05;}
                            wait(0.1);
                            break;
                            
                            //}
                            
                        case '7': // right
                        
                            //if (state == '1') {
                                
                            if (pan <= 0.05) {pan = 0.0;}
                            else {pan = pan - 0.05;}
                            wait(0.1);
                            break;
                            
                            //}
                            
                            
                        case '8': // left
                            
                            //if (state == '1') {
                                
                            if (pan >= 0.95) {pan = 1.0;}
                            else {pan = pan + 0.05;}
                            wait(0.1);
                            break;
                            
                           // }
                        
                    }
                    break; 
                
                case 'A': // otherwise accelerometer 
                    
                    // fetch and store accelerometer data
                    
                    for (int i = 0; i < 4; i++) {
                        
                        temp = bt.getc();
                        x.c[i] = temp;
                        
                    }
                    
                    for (int i = 0; i < 4; i++) {
                        
                        temp = bt.getc();
                        y.c[i] = temp;

                    }
                    
                    // final loop to capture Z accelerometer data (NOT USED)
                    for (int i = 0; i < 4; i++) {

                        temp = bt.getc();

                    }

                    temp = bt.getc();
                    
                    // read accelerometer data and control motors
                    
                    if (x.f <= -2.0) {   // left
                    
                        fwdl = fwdr = 1;
                        revl = revr = 0;
                        left = 0.1;
                        right = 1.0;
                        
                    }
                    
                    else if (x.f >= 2.0) {  // right
                        
                        fwdl = fwdr = 1;
                        revl = revr = 0;
                        left = 1.0;
                        right = 0.1;
                            
                    }
                    
                    else { // if no tilt, make sure that motors are disengaged
                        
                        fwdl = fwdr = revl = revr = 0;
                        left = right = 0.0;    
                    }
                    
                    if (y.f <= -2.0) {   // reverse
                    
                        fwdl = fwdr = 0;
                        revl = revr = 1;
                        right = left = 1.0;
                            
                    }
                    
                    else if (y.f >= 2.0) {  // forward
                        
                        fwdl = fwdr = 1;
                        revl = revr = 0;
                        right = left = 1.0;
                            
                    }
        
                    break;

            }
        }
    }
}

In order to control the pan and tilt servos, we utilized the Servo class created by Simon Ford.

Import libraryServo

A class to control a model R/C servo, using a PwmOut


Demonstration


Please log in to post comments.