Presentation is loading. Please wait.

Presentation is loading. Please wait.

WEP 1035 Programming WEP 1035. AGENDA Introduction to Mbed Registration on Mbed Developer Website Hello World/Blinky Program Electrical Schematic Overview.

Similar presentations


Presentation on theme: "WEP 1035 Programming WEP 1035. AGENDA Introduction to Mbed Registration on Mbed Developer Website Hello World/Blinky Program Electrical Schematic Overview."— Presentation transcript:

1 WEP 1035 Programming WEP 1035

2 AGENDA Introduction to Mbed Registration on Mbed Developer Website Hello World/Blinky Program Electrical Schematic Overview of the PCB Importing Skeleton Code Libraries Overview Begin Programming (Declarations and Initializations)

3 INTRODUCTION TO MBED NXP LPC1768 MCU ARM® Cortex™-M3 Core 96MHz, 32KB RAM, 512KB FLASH Ethernet, USB Host/Device, 2xSPI, 2xI2C, 3xUART, CAN, 6xPWM, 6xADC, GPIO Prototyping form-factor 40-pin 0.1" pitch DIP package 5V USB or 4.5-9V supply Based on 3.3V Logic Built-in USB drag 'n' drop FLASH programmer

4 INTRODUCTION TO MBED High level C/C++ SDK USB Drag ‘n’ Drop Programming Interface

5 INTRODUCTION TO MBED mbed.org Developer Website Online Compiler Entry-level Online Compiler Nothing to Install: Browser-based IDE Immediately compiling examples or writing your own

6 REGISTRATION http://developer.mbed.org After Signup: Choose LPC1768 Platform

7 BLINKY PROGRAM

8 HELLO WORLD PROGRAM

9 ELECTRICAL PCB OVERVIEW IMU MBED Motor Driver Fuse Camera DC Conv 5V DC Conv LED

10 ELECTRICAL PCB OVERVIEW

11

12 IMU (Sparkfun - SEN 10121) ADXL345 accelerometer (3-axis accelerometer) Measures accelerations in x, y, z (m/s^2) ITG-3200 gyro (3 axis gyroscope) Measures angular velocity in x, y, z (rads/s) 3.3V input I2C interface (Refer to Altium Schematic) Used on the robot for measuring the tilt (pitch)

13 ELECTRICAL PCB OVERVIEW Motor Driver (Dual MC33926 Motor Driver) PWM Pins: Motor 1: M1D2 Motor 2: M2D2 Directions Pins Motor 1: M1IN1, M1IN2 Motor 2: M2IN1, M2IN2

14 ELECTRICAL PCB OVERVIEW DC Motors 70:1 metal gearbox Quadrature Encoder 16 pulses per rev 64 counts per rev (16x4) Channel A & B on interrupt pins Refer to Altium Schematic

15 NEOPIXEL LEDS Tiny, bright RGB pixels Daisy Chain Design Only 8mm x 10mm Need 1 pin/wire to control all the LEDs in the chain

16 IMPORTING SKELETON CODE https://developer.mbed.org/users/weprobotics/code/WEP_Basic/

17 ETHERNET/UDP DECLARATIONS // Ethernet Declarations here static const char* robotIP = "192.168.10.177"; //Robot IP static const char* mask = "255.255.255.0"; // Mask static const char* gateway = "192.168.10.253"; //Gateway const char* broadcastIP = "192.168.10.255"; //broadcast it const int port = 8888; char packetBuffer[10]; //Buffer for receiving the UDP Packets (in our case from the Android Tablet) UDPSocket sendSocket; //Socket for sending UDPSocket receiveSocket; //One for receiving Endpoint broadcastServer; //Where you send the debug messages Endpoint client; //where you receive your messages from

18 ETHERNET/UDP SETUP AND INITIALIZATION EthernetInterface eth; // eth.init(); //If you want to use DHCP enable this eth.init(robotIP, mask, gateway); //For Static IP while (eth.connect()<0); //Get stuck here if ethernet is not setup successfully #ifdef SERIAL_DEBUG pc.printf("IP Address is %s\n", eth.getIPAddress()); pc.printf("Network Mask is %s\n", eth.getNetworkMask()); pc.printf("Gateway is %s\n", eth.getGateway()); #endif sendSocket.init(); sendSocket.set_broadcasting(); //Needed for broadcasting... receiveSocket.bind(port); receiveSocket.set_broadcasting(); receiveSocket.set_blocking(false,50); broadcastServer.set_address(broadcastIP, port); wait_ms(500); #ifdef SERIAL_DEBUG pc.printf(" UDP setup complete!\n" ); #endif

19 UDP RECEIVE PACKETS int receivedBytes = receiveSocket.receiveFrom(client, packetBuffer, sizeof(packetBuffer)); if(receivedBytes) //UDP bytes received { switch(packetBuffer[0]) { case 0x00: // Open Loop joystickAlive = true; status = 1; //In Open Loop openLoop(); break; case 0xF0: mbed_reset(); break; case 0xF1: //To do break; case 0xF2: //To do break; case 0xF3: //To do break; case 0xF4: //To do break; }

20 ETHERNET WIRING TO MBED Rx-Green Rx+White/Green Tx-Orange Tx+White/Orange

21 MOTOR DRIVER DECLARATIONS //MC33926 - Motor Controller Pinout Declaration #define M1D2 p26 //PWM Pins #define M2D2 p25 //PWM Pins #define M2IN2 p24 #define M2IN1 p23 #define M1IN2 p22 #define M1IN1 p21 //Declaration of the Motor Driver Objects Motor leftMotor(M1D2,M1IN1,M1IN2); Motor rightMotor(M2D2,M2IN1,M2IN2);

22 ANDROID JOYSTICK APP

23 255 127 000

24 MOTOR DEADBAND Joystick Command Motor Command 255 (Max Forward Speed) 1.0 128 (Min Forward Speed) ~ 0.4 127 (Stop) 0.0 126 (Min Reverse Speed) ~ -0.4 0 (Max Reverse Speed)

25 MOTOR CONTROL FUNCTION void openLoop() { //Equations to map the android joystick from 0-255 leftMotorSpeed = ((float)packetBuffer[1]-127 + 0.5f * ((float)packetBuffer[4]-127))/-128.0f*0.6; rightMotorSpeed = ((float)packetBuffer[1]-127 - 0.5f * ((float)packetBuffer[4]-127))/128.0f*0.6; //Dead Zone Corrections if (leftMotorSpeed>0) leftMotorSpeed+=0.4; if (leftMotorSpeed<0) leftMotorSpeed-=0.4; if (rightMotorSpeed>0) rightMotorSpeed+=0.4; if (rightMotorSpeed<0) rightMotorSpeed-=0.4; //Setting the Motor Speed leftMotor.speed(leftMotorSpeed); rightMotor.speed(rightMotorSpeed); //Setting colors for the neopixel (Will be done later) #ifdef SERIAL_DEBUG pc.printf("leftMotorSpeed: %f\n",leftMotorSpeed); pc.printf("rightMotorSpeed: %f\n",rightMotorSpeed); #endif }

26 IMU DECLARATIONS //IMU Declaration #define IMU_INT1 p8 #define IMU_SDA p9 #define IMU_SCL p10 #define IMU_INT0 p11 SEN10121 imu(IMU_SDA, IMU_SCL); Ticker imuFilterTicker; //A recurring interrupt for filtering IMU data

27 IMU SETUP AND INITIALIZATIONS #ifdef SERIAL_DEBUG pc.printf(" Initializing & Calibrating IMU.\n" ); #endif //IMU Initialization and Calibration imu.initialize(); imu.calibrate(); imuFilterTicker.attach(&imu, &SEN10121::filter, imu.dt); //Filter to be called every 50ms to remove accelerometer noise

28 BATTERY VOLTAGE DECLARATION //Battery Voltage Pinout Declaration #define BATTERY_ANALOG p18 //for monitoring battery voltage //Battery Voltage Declaration AnalogIn batteryVoltage(BATTERY_ANALOG);

29 BATTERY VOLTAGE FUNCTION float getBatteryVoltage() { return batteryVoltage.read()*3.3*12.6/2.244; //In Volts }

30 TIMER AND SAFETY DECLARATIONS // Timer & Safety Declarations volatile bool joystickAlive = false; //flag for knowing that the joystick commands are being sent volatile bool safetyBrake = false; //flag for knowing when to engage the safety (disable power to the motors) Ticker safetyBrakeTicker; //Continuous timer interrupt called for safety Ticker robotStatusTicker; //Continuous timer interrupt for sending status messages to the android tablet over UDP volatile bool robotStatusRequested = false; //flag used by robotStatusTicker volatile char status = 0; //status byte for sending robot status to the android app

31 TIMER (ISR) INITIALIZATIONS safetyBrakeTicker.attach(&safetyBrakeCheck, 0.5); robotStatusTicker.attach(&robotStatusISR, 0.3);

32 SAFETY BRAKE AND ROBOT STATUS STATEMENTS //SafetyBrake Statements if(safetyBrake) { safetyBrake = false; leftMotor.speed(0.0); rightMotor.speed(0.0); LEDs.setColor(pixel, stopColors, numPixels); } //Robot Status Statements if(robotStatusRequested) { robotStatusRequested = false; sendRobotStatus(); }

33 SAFETY BRAKE AND ROBOT STATUS FUNCTIONS void safetyBrakeCheck(void) { if(!joystickAlive) safetyBrake = true; else joystickAlive = false; } void sendRobotStatus() { char frame[12]; frame[0] = 0x46; frame[1] = 0x21; *((float*) (frame+2)) = getBatteryVoltage(); *((float*) (frame+6)) = imu.getPitch(); *(frame+10) = status; frame[11] = 0x0A; sendSocket.sendTo(broadcastServer, frame, sizeof(frame)); }

34 NEOPIXEL LED DECLARATIONS //NeoPixel LED Declarations #define LED_PIN p5 // The pixel array control class. using namespace neopixel; //For neopixel LED Library PixelArray LEDs(LED_PIN); #define numPixels 3 Pixel pixel[numPixels]; //Array of pixel structures holding the colors of each pixel uint8_t stopColors[numPixels*3] = {50,0,0, 50,0,0, 50,0,0}; //RGB colors of the three pixels uint8_t driveColors[numPixels*3] = {0,150,0, 0,150,0, 0,150,0}; uint8_t steerColors[numPixels*3] = {0,0,150, 0,0,150, 0,0,150};

35 NEOPIXEL LED //Add to openLoop() function if (packetBuffer[1]==127) { if (packetBuffer[4]==127) LEDs.setColor(pixel, stopColors, numPixels); else LEDs.setColor(pixel, steerColors, numPixels); } else LEDs.setColor(pixel, driveColors, numPixels);

36 ENCODER DECLARATIONS //Motor Encoder Pinout Declarations #define LEFT_CH_A p30 #define LEFT_CH_B p29 #define RIGHT_CH_A p28 #define RIGHT_CH_B p27 //Declaration of the Quadrature Encoders on the two Motors QEI leftEncoder(LEFT_CH_A, LEFT_CH_B, NC, 16, QEI::Encoding); QEI rightEncoder(RIGHT_CH_A, RIGHT_CH_B, NC, 16, QEI::Encoding);

37 TEAMS MechanicalElectronicsEmbedded Programming Team 1 Bingjie ChenYANG LIUUsman Amin Fiaz Muhammad Akram Karimi Muxingzi Li Team 2 Aaron Sanchez YanezRen LiMartin Velazquez-RizoYazeed AlHarbiJorge Rosas Team 3 Ditho PulunganAyman KaramHassan AlmutawaYomna Al IbrahimHind Alamro Team 4 Mayadah AlhashemAbdullah Alshehri Carmen Leticia Castrejon Barron Sarah AlghamdiNoureddine Toumi Team 5 Mireille HantoucheKhalil MoussiPo-Chun ChenJean LahoudNura Aljaafari Team 6 Zhen JianAbdullah AlmansouriShuai YANGFurrukh SanaRana Al-Rabeh


Download ppt "WEP 1035 Programming WEP 1035. AGENDA Introduction to Mbed Registration on Mbed Developer Website Hello World/Blinky Program Electrical Schematic Overview."

Similar presentations


Ads by Google