Wifi Controlled Robot is done as a mini project (Lab4) for ECE 4180 class (Georgia Tech). Robot is assembled in Sparkfun's Shadow chasis robot kit. This robot takes the command from the webpage to move forward, reverse without colliding. The distance sensor is used as a mechanism for collision detection and play a short beep sound. It turn 90 degree with magnetometer when the turn command is sent.

Dependencies:   Motordriver mbed

/media/uploads/pkoirala3/capture.jpg Showing the setup and calibration: Part1 In this part the Wifi setups and attains an IP address so we can control it through a webpage on our phone/PC. After it obtains an IP address it calibrates the IMU so we can have accurate compass headings for precise turns.

The parts that we use are as follows:

  • Mbed
  • 2 DC motors
  • H-Bridge (to drive the DC motors)
  • Speaker
  • Class D Amp (to drive the Speaker)
  • IMU (use the magnometer for compass headings)
  • Wifi card (ESP8266)

Showing webpage functionality and Robot Functionality: In this part we demonstrate the functionality of the robot and the webpage to control it.

Final Code

[Repository '/teams/Prana-Koirala/code/Wifi_controlled_Robot_ECE4180/docs/tip/main_8cpp_source.html' not found]

Committer:
pkoirala3
Date:
Mon Mar 13 21:54:22 2017 +0000
Revision:
5:e9f1030a5bbb
Parent:
4:166570fa7fda
ECE4180_ROBOT_CONTROLLEDBY_WiFI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pkoirala3 4:166570fa7fda 1 class Speaker
pkoirala3 4:166570fa7fda 2 {
pkoirala3 4:166570fa7fda 3 public:
pkoirala3 4:166570fa7fda 4 Speaker(PinName pin) : _pin(pin) {
pkoirala3 4:166570fa7fda 5 // _pin(pin) means pass pin to the Speaker Constructor
pkoirala3 5:e9f1030a5bbb 6 // precompute 32 sample points on one sine wave cycle
pkoirala3 5:e9f1030a5bbb 7 // used for continuous sine wave output later
pkoirala3 5:e9f1030a5bbb 8 for(int k=0; k<32; k++) {
pkoirala3 5:e9f1030a5bbb 9 Analog_out_data[k] = int (65536.0 * ((1.0 + sin((float(k)/32.0*6.28318530717959)))/2.0));
pkoirala3 5:e9f1030a5bbb 10 // scale the sine wave to 16-bits - as needed for AnalogOut write_u16 arg
pkoirala3 5:e9f1030a5bbb 11 }
pkoirala3 5:e9f1030a5bbb 12
pkoirala3 4:166570fa7fda 13 }
pkoirala3 5:e9f1030a5bbb 14 // class method to play a note based on AnalogOut class
pkoirala3 4:166570fa7fda 15 void PlayNote(float frequency, float duration, float volume) {
pkoirala3 5:e9f1030a5bbb 16 // scale samples using current volume level arg
pkoirala3 5:e9f1030a5bbb 17 for(int k=0; k<32; k++) {
pkoirala3 5:e9f1030a5bbb 18 Analog_scaled_data[k] = Analog_out_data[k] * volume;
pkoirala3 5:e9f1030a5bbb 19 }
pkoirala3 5:e9f1030a5bbb 20 // reset to start of sample array
pkoirala3 5:e9f1030a5bbb 21 i=0;
pkoirala3 5:e9f1030a5bbb 22 // turn on timer interrupts to start sine wave output
pkoirala3 5:e9f1030a5bbb 23 Sample_Period.attach(this, &Speaker::Sample_timer_interrupt, 1.0/(frequency*32.0));
pkoirala3 5:e9f1030a5bbb 24 // play note for specified time
pkoirala3 4:166570fa7fda 25 wait(duration);
pkoirala3 5:e9f1030a5bbb 26 // turns off timer interrupts
pkoirala3 5:e9f1030a5bbb 27 Sample_Period.detach();
pkoirala3 5:e9f1030a5bbb 28 // sets output to mid range - analog zero
pkoirala3 5:e9f1030a5bbb 29 this->_pin.write_u16(32768);
pkoirala3 5:e9f1030a5bbb 30
pkoirala3 4:166570fa7fda 31 }
pkoirala3 5:e9f1030a5bbb 32 private:
pkoirala3 5:e9f1030a5bbb 33 // sets up specified pin for analog using AnalogOut class
pkoirala3 5:e9f1030a5bbb 34 AnalogOut _pin;
pkoirala3 5:e9f1030a5bbb 35 // set up a timer to be used for sample rate interrupts
pkoirala3 5:e9f1030a5bbb 36 Ticker Sample_Period;
pkoirala3 4:166570fa7fda 37
pkoirala3 5:e9f1030a5bbb 38 //variables used by interrupt routine and PlayNote
pkoirala3 5:e9f1030a5bbb 39 volatile int i;
pkoirala3 5:e9f1030a5bbb 40 short unsigned Analog_out_data[32];
pkoirala3 5:e9f1030a5bbb 41 short unsigned Analog_scaled_data[32];
pkoirala3 5:e9f1030a5bbb 42
pkoirala3 5:e9f1030a5bbb 43 // Interrupt routine
pkoirala3 5:e9f1030a5bbb 44 // used to output next analog sample whenever a timer interrupt occurs
pkoirala3 5:e9f1030a5bbb 45 void Sample_timer_interrupt(void) {
pkoirala3 5:e9f1030a5bbb 46 // send next analog sample out to D to A
pkoirala3 5:e9f1030a5bbb 47 this->_pin.write_u16(Analog_scaled_data[i]);
pkoirala3 5:e9f1030a5bbb 48 // increment pointer and wrap around back to 0 at 32
pkoirala3 5:e9f1030a5bbb 49 i = (i+1) & 0x01F;
pkoirala3 5:e9f1030a5bbb 50 }
pkoirala3 5:e9f1030a5bbb 51 };
pkoirala3 5:e9f1030a5bbb 52