a

Fork of ESE519_Lab6_part1_skeleton by Carter Sharer

Committer:
hydroguy45
Date:
Fri Nov 01 18:52:45 2019 +0000
Revision:
12:ea030e3181d3
Parent:
11:46c532b752d5
Cleaned up the header

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hydroguy45 12:ea030e3181d3 1 //ESE519/ESE350 Lab5 Controller Part 1 (INCOMPLETE IMPLIMENTATION)
hydroguy45 12:ea030e3181d3 2 //Author: Chris Foley (Building on Carter Sharer original implementation)
hydroguy45 12:ea030e3181d3 3 //Date: 11/1/2019
csharer 0:0ebe6f55caee 4
csharer 0:0ebe6f55caee 5 #include "mbed.h"
csharer 0:0ebe6f55caee 6 #include <string>
csharer 0:0ebe6f55caee 7 #include "Joystick.h"
hydroguy45 7:ca226305d28b 8 #include "wifiGETWrapper.h"
hydroguy45 9:b8801ba7d7c2 9 #define SEND //Uncomment if you want to transmit data
csharer 0:0ebe6f55caee 10 #define NONE 250
csharer 0:0ebe6f55caee 11
csharer 0:0ebe6f55caee 12 //============================
csharer 0:0ebe6f55caee 13 //== Pin Assignments ==
csharer 0:0ebe6f55caee 14 //============================
csharer 0:0ebe6f55caee 15 //Knobs
csharer 0:0ebe6f55caee 16 #define POT1 p17 //Knob1
csharer 0:0ebe6f55caee 17 #define POT2 p18 //Knob2
csharer 0:0ebe6f55caee 18 #define POT3 p16 //Knob3
csharer 0:0ebe6f55caee 19 #define POT4 p15 //Knob4
csharer 0:0ebe6f55caee 20 //JoyStick
csharer 0:0ebe6f55caee 21 #define POTV p19 //Vertial
csharer 0:0ebe6f55caee 22 #define POTH p20 //Horizontal
csharer 0:0ebe6f55caee 23 //Button
csharer 0:0ebe6f55caee 24 #define BUTTON1 p21
hydroguy45 10:dafae6093487 25 #define COMMUNICATION_FORMAT "Jstickh:|%0.0f|Jstickv:|%0.0f|Knob1|%0.2f|Knob2|%0.2f|Knob3|%0.2f|Knob4|%0.2f|Button:|%d"
csharer 0:0ebe6f55caee 26
csharer 0:0ebe6f55caee 27 //============================
csharer 0:0ebe6f55caee 28 //== Objects ==
csharer 0:0ebe6f55caee 29 //============================
csharer 0:0ebe6f55caee 30 //Knobs
csharer 0:0ebe6f55caee 31 AnalogIn pot1(POT1);
csharer 0:0ebe6f55caee 32 AnalogIn pot2(POT2);
csharer 0:0ebe6f55caee 33 AnalogIn pot3(POT3);
csharer 0:0ebe6f55caee 34 AnalogIn pot4(POT4);
csharer 0:0ebe6f55caee 35 float knob1, knob2, knob3, knob4;
csharer 0:0ebe6f55caee 36
csharer 0:0ebe6f55caee 37 //Joystick
csharer 0:0ebe6f55caee 38 Joystick jstick(POTV, POTH);
csharer 0:0ebe6f55caee 39 float jstick_h, jstick_v;
csharer 0:0ebe6f55caee 40
csharer 0:0ebe6f55caee 41 //Button
csharer 0:0ebe6f55caee 42 DigitalIn Button(BUTTON1);
csharer 0:0ebe6f55caee 43 bool button;
csharer 0:0ebe6f55caee 44
csharer 0:0ebe6f55caee 45 // LEDs
csharer 0:0ebe6f55caee 46 DigitalOut led1(LED1);
csharer 0:0ebe6f55caee 47 DigitalOut led2(LED2);
csharer 0:0ebe6f55caee 48 DigitalOut led3(LED3);
csharer 0:0ebe6f55caee 49 DigitalOut led4(LED4);
csharer 0:0ebe6f55caee 50
csharer 0:0ebe6f55caee 51 // Timer
csharer 0:0ebe6f55caee 52 Timer timer;
csharer 0:0ebe6f55caee 53
csharer 0:0ebe6f55caee 54 // Serial port for showing RX data.
csharer 0:0ebe6f55caee 55 Serial pc(USBTX, USBRX);
csharer 0:0ebe6f55caee 56
csharer 0:0ebe6f55caee 57 char txBuffer[128];
csharer 0:0ebe6f55caee 58 char rxBuffer[128];
csharer 0:0ebe6f55caee 59 int rxLen;
csharer 0:0ebe6f55caee 60
csharer 0:0ebe6f55caee 61 int main (void)
csharer 0:0ebe6f55caee 62 {
hydroguy45 7:ca226305d28b 63
csharer 0:0ebe6f55caee 64 //Set Baud rate (9600-115200 is ideal)
csharer 0:0ebe6f55caee 65 pc.baud(115200);
csharer 0:0ebe6f55caee 66 pc.printf("\r\n Start! \r\n");
hydroguy45 11:46c532b752d5 67
hydroguy45 9:b8801ba7d7c2 68 //This is an example wifi connection! Please fill this in with the SSID of your BBBL and the password too.
hydroguy45 11:46c532b752d5 69 const char * SSID = "BeagleBone-365E";//TODO: CHANGE THIS LINE
hydroguy45 11:46c532b752d5 70 const char * password = "BeagleBone";//TODO: CHANGE THIS LINE
hydroguy45 11:46c532b752d5 71
hydroguy45 9:b8801ba7d7c2 72 initConnection(SSID,password);
hydroguy45 11:46c532b752d5 73
csharer 0:0ebe6f55caee 74 //Start Timer
csharer 0:0ebe6f55caee 75 timer.start();
csharer 0:0ebe6f55caee 76
csharer 1:98c414bbfe8a 77 //Scale Joystick Values, range[-100, 100]
csharer 1:98c414bbfe8a 78 jstick.setScale(-100, 100);
hydroguy45 6:e0c358a351aa 79 int counter = 0;
csharer 0:0ebe6f55caee 80 while(1) {
csharer 0:0ebe6f55caee 81 //(1) Read Joystick Values, round to int8_t presision
csharer 0:0ebe6f55caee 82 jstick_h = (int8_t)jstick.horizontal();
csharer 0:0ebe6f55caee 83 jstick_v = (int8_t)jstick.vertical();
hydroguy45 9:b8801ba7d7c2 84 pc.printf("H: %0.2f V:%0.2f \r\n", jstick_h, jstick_v);
csharer 0:0ebe6f55caee 85
csharer 0:0ebe6f55caee 86 //(2) Read Pot Values, Scale, and round to precision
csharer 0:0ebe6f55caee 87 knob1 = (uint8_t)(pot1.read() * 100); //rounded to uint8_t
csharer 0:0ebe6f55caee 88 knob2 = (pot2.read() * 100);
csharer 0:0ebe6f55caee 89 knob3 = (pot3.read());
csharer 0:0ebe6f55caee 90 knob4 = (int)(pot4.read() * 100); //rounded to float
csharer 0:0ebe6f55caee 91
csharer 0:0ebe6f55caee 92 //(3)Read Button Val, Add to buffer
csharer 0:0ebe6f55caee 93 button = !Button.read(); //button is active low
csharer 0:0ebe6f55caee 94
csharer 0:0ebe6f55caee 95 #ifdef SEND
csharer 0:0ebe6f55caee 96 //SEND DATA: Send some data every 1/2 second
csharer 0:0ebe6f55caee 97 if(timer.read_ms() >= 500) {
csharer 0:0ebe6f55caee 98 //Reset the timer to 0
csharer 0:0ebe6f55caee 99 timer.reset();
csharer 0:0ebe6f55caee 100 // Toggle LED 2.
csharer 0:0ebe6f55caee 101 led2 = led2^1;
csharer 0:0ebe6f55caee 102
csharer 0:0ebe6f55caee 103 //(5) Add all values to buffer to be sent
csharer 0:0ebe6f55caee 104 sprintf(txBuffer, COMMUNICATION_FORMAT, jstick_h, jstick_v, knob1, knob2, knob3, knob4, button);
csharer 0:0ebe6f55caee 105
csharer 0:0ebe6f55caee 106 //(6) Send the buffer
hydroguy45 7:ca226305d28b 107 sendGET(txBuffer);
csharer 1:98c414bbfe8a 108 pc.printf("Sent| %s\r\n", txBuffer);
csharer 0:0ebe6f55caee 109 }
csharer 0:0ebe6f55caee 110 #endif
csharer 0:0ebe6f55caee 111
csharer 0:0ebe6f55caee 112 } //end loop
csharer 0:0ebe6f55caee 113 }//end main