![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Fx0 hackathon team4
Dependencies: NySNICInterface mbed-rtos mbed
Fork of RESTServerSample by
main.cpp@4:99a67256b765, 2015-02-15 (annotated)
- Committer:
- oks486
- Date:
- Sun Feb 15 02:55:36 2015 +0000
- Revision:
- 4:99a67256b765
- Parent:
- 1:e821c773d5f0
- Child:
- 5:70c9f6045f2d
add motor control with pwm
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
komoritan | 0:998e2e00df0c | 1 | #include "mbed.h" |
komoritan | 0:998e2e00df0c | 2 | #include "SNIC_WifiInterface.h" |
komoritan | 0:998e2e00df0c | 3 | #include "HTTPServer.h" |
komoritan | 0:998e2e00df0c | 4 | |
komoritan | 0:998e2e00df0c | 5 | /** |
komoritan | 0:998e2e00df0c | 6 | * Wifi AP parameter |
komoritan | 0:998e2e00df0c | 7 | */ |
komoritan | 0:998e2e00df0c | 8 | |
komoritan | 0:998e2e00df0c | 9 | /* Set this */ |
yi | 1:e821c773d5f0 | 10 | //#define WIFI_SSID "" |
yi | 1:e821c773d5f0 | 11 | //#define WIFI_SECUTIRY_KEY "" |
yi | 1:e821c773d5f0 | 12 | |
yi | 1:e821c773d5f0 | 13 | /* |
yi | 1:e821c773d5f0 | 14 | #define WIFI_SSID "2ndguests" |
yi | 1:e821c773d5f0 | 15 | #define WIFI_SECUTIRY_KEY "Sepkddi0077" |
yi | 1:e821c773d5f0 | 16 | #define WIFI_SECURITY_TYPE e_SEC_WPA2_AES |
yi | 1:e821c773d5f0 | 17 | */ |
yi | 1:e821c773d5f0 | 18 | |
yi | 1:e821c773d5f0 | 19 | //#define WIFI_SSID "Team3_4" |
yi | 1:e821c773d5f0 | 20 | #define WIFI_SSID "Team11_12" |
yi | 1:e821c773d5f0 | 21 | #define WIFI_SECUTIRY_KEY "123456789" |
yi | 1:e821c773d5f0 | 22 | #define WIFI_SECURITY_TYPE e_SEC_WPA2_AES |
yi | 1:e821c773d5f0 | 23 | |
yi | 1:e821c773d5f0 | 24 | |
yi | 1:e821c773d5f0 | 25 | |
komoritan | 0:998e2e00df0c | 26 | //#define WIFI_SECURITY_TYPE e_SEC_OPEN |
komoritan | 0:998e2e00df0c | 27 | //#define WIFI_SECURITY_TYPE e_SEC_WEP |
komoritan | 0:998e2e00df0c | 28 | //#define WIFI_SECURITY_TYPE e_SEC_WPA_TKIP |
yi | 1:e821c773d5f0 | 29 | //#define WIFI_SECURITY_TYPE e_SEC_WPA2_AES |
komoritan | 0:998e2e00df0c | 30 | //#define WIFI_SECURITY_TYPE e_SEC_WPA2_MIXED |
komoritan | 0:998e2e00df0c | 31 | |
komoritan | 0:998e2e00df0c | 32 | |
yi | 1:e821c773d5f0 | 33 | #define IP_ADDRESS "192.168.100.44" |
komoritan | 0:998e2e00df0c | 34 | #define NET_MASK "255.255.255.0" |
komoritan | 0:998e2e00df0c | 35 | #define DEFAULT_GATEWAY "192.168.0.1" |
komoritan | 0:998e2e00df0c | 36 | #define PORT_NUMBER 80 |
komoritan | 0:998e2e00df0c | 37 | |
yi | 1:e821c773d5f0 | 38 | #define _DEBUG |
komoritan | 0:998e2e00df0c | 39 | |
komoritan | 0:998e2e00df0c | 40 | Serial pc(USBTX, USBRX); // This is required when defined "_DEBUG" |
komoritan | 0:998e2e00df0c | 41 | /** Wi-Fi SNIC UART Interface*/ |
yi | 1:e821c773d5f0 | 42 | //C_SNIC_WifiInterface mSNICwifi( p13, p14, p12, p11, p20 ); |
yi | 1:e821c773d5f0 | 43 | C_SNIC_WifiInterface mSNICwifi( p9, p10, NC, NC, p30 ); |
komoritan | 0:998e2e00df0c | 44 | |
oks486 | 4:99a67256b765 | 45 | // Left motor |
oks486 | 4:99a67256b765 | 46 | PwmOut mPwmMotorL(p23); |
oks486 | 4:99a67256b765 | 47 | DigitalOut mDoutMotorL1(p15); |
oks486 | 4:99a67256b765 | 48 | DigitalOut mDoutMotorL2(p16); |
oks486 | 4:99a67256b765 | 49 | |
oks486 | 4:99a67256b765 | 50 | // Rigth motor |
oks486 | 4:99a67256b765 | 51 | PwmOut mPwmMotorR(p22); |
oks486 | 4:99a67256b765 | 52 | DigitalOut mDoutMotorR1(p18); |
oks486 | 4:99a67256b765 | 53 | DigitalOut mDoutMotorR2(p17); |
oks486 | 4:99a67256b765 | 54 | |
oks486 | 4:99a67256b765 | 55 | // Tail motor |
oks486 | 4:99a67256b765 | 56 | PwmOut mPwmMotorTail(p21); |
oks486 | 4:99a67256b765 | 57 | DigitalOut mDoutMotorTail1(p19); |
oks486 | 4:99a67256b765 | 58 | DigitalOut mDoutMotorTail2(p20); |
komoritan | 0:998e2e00df0c | 59 | |
komoritan | 0:998e2e00df0c | 60 | |
komoritan | 0:998e2e00df0c | 61 | void wifi_connect() |
komoritan | 0:998e2e00df0c | 62 | { |
komoritan | 0:998e2e00df0c | 63 | // Initialize Wi-Fi interface |
komoritan | 0:998e2e00df0c | 64 | if(mSNICwifi.init()!=0){ |
komoritan | 0:998e2e00df0c | 65 | printf("Wi-Fi initial failed\r\n"); |
komoritan | 0:998e2e00df0c | 66 | mbed_die(); |
komoritan | 0:998e2e00df0c | 67 | } |
komoritan | 0:998e2e00df0c | 68 | wait(0.5); |
komoritan | 0:998e2e00df0c | 69 | |
komoritan | 0:998e2e00df0c | 70 | if(mSNICwifi.disconnect()!= 0 ) |
komoritan | 0:998e2e00df0c | 71 | { |
komoritan | 0:998e2e00df0c | 72 | printf("on the disconnect state\r\n"); |
komoritan | 0:998e2e00df0c | 73 | mbed_die(); |
komoritan | 0:998e2e00df0c | 74 | } |
komoritan | 0:998e2e00df0c | 75 | wait(0.3); |
komoritan | 0:998e2e00df0c | 76 | |
komoritan | 0:998e2e00df0c | 77 | // Connect to AP |
komoritan | 0:998e2e00df0c | 78 | if(mSNICwifi.connect( WIFI_SSID,strlen(WIFI_SSID), |
komoritan | 0:998e2e00df0c | 79 | WIFI_SECURITY_TYPE, |
komoritan | 0:998e2e00df0c | 80 | WIFI_SECUTIRY_KEY, |
komoritan | 0:998e2e00df0c | 81 | strlen(WIFI_SECUTIRY_KEY))!=0) |
komoritan | 0:998e2e00df0c | 82 | { |
komoritan | 0:998e2e00df0c | 83 | printf("Connect AP is failed\r\n"); |
komoritan | 0:998e2e00df0c | 84 | mbed_die(); |
komoritan | 0:998e2e00df0c | 85 | } |
komoritan | 0:998e2e00df0c | 86 | wait(0.5); |
komoritan | 0:998e2e00df0c | 87 | |
komoritan | 0:998e2e00df0c | 88 | int retIp = mSNICwifi.setIPConfig(false, IP_ADDRESS, NET_MASK, DEFAULT_GATEWAY); |
yi | 1:e821c773d5f0 | 89 | |
komoritan | 0:998e2e00df0c | 90 | } |
komoritan | 0:998e2e00df0c | 91 | |
komoritan | 0:998e2e00df0c | 92 | |
komoritan | 0:998e2e00df0c | 93 | int main() |
komoritan | 0:998e2e00df0c | 94 | { |
komoritan | 0:998e2e00df0c | 95 | // for debug |
komoritan | 0:998e2e00df0c | 96 | pc.baud( 115200 ); |
oks486 | 4:99a67256b765 | 97 | |
oks486 | 4:99a67256b765 | 98 | mPwmMotorL.period_ms(20); |
oks486 | 4:99a67256b765 | 99 | mPwmMotorR.period_ms(20); |
oks486 | 4:99a67256b765 | 100 | mPwmMotorTail.period_ms(20); |
komoritan | 0:998e2e00df0c | 101 | |
komoritan | 0:998e2e00df0c | 102 | wifi_connect(); |
yi | 1:e821c773d5f0 | 103 | |
komoritan | 0:998e2e00df0c | 104 | HTTPServer srv; |
komoritan | 0:998e2e00df0c | 105 | |
komoritan | 0:998e2e00df0c | 106 | pc.printf("server init.\r\n"); |
komoritan | 0:998e2e00df0c | 107 | srv.init(PORT_NUMBER); |
komoritan | 0:998e2e00df0c | 108 | |
komoritan | 0:998e2e00df0c | 109 | srv.add_request_handler("GET", new GetRequestHandler()); |
komoritan | 0:998e2e00df0c | 110 | srv.add_request_handler("DELETE", new DeleteRequestHandler()); |
komoritan | 0:998e2e00df0c | 111 | srv.add_request_handler("POST", new PostRequestHandler()); |
komoritan | 0:998e2e00df0c | 112 | |
komoritan | 0:998e2e00df0c | 113 | wait(1); |
komoritan | 0:998e2e00df0c | 114 | pc.printf("server running.\r\n"); |
komoritan | 0:998e2e00df0c | 115 | srv.run(); |
komoritan | 0:998e2e00df0c | 116 | } |
yi | 1:e821c773d5f0 | 117 | |
yi | 1:e821c773d5f0 | 118 |