Control a robot via a web browser, by routing the control signals via a web server.
Dependencies: HTTPClient Motordriver WiflyInterface mbed
main.cpp
- Committer:
- angalo3
- Date:
- 2012-10-12
- Revision:
- 0:d1a9db1a5652
File content as of revision 0:d1a9db1a5652:
#include "mbed.h" #include "WiflyInterface.h" #include "motordriver.h" #include "HTTPClient.h" Serial pc(USBTX, USBRX); WiflyInterface wifly(p9, p10, p25, p26, "mbed", "password", WPA); HTTPClient http; /* wifly object where: * - p9 and p10 are for the serial communication * - p25 is for the reset pin * - p26 is for the connection status * - "mbed" is the ssid of the network * - "password" is the password * - WPA is the security */ DigitalOut f(LED1); DigitalOut b(LED2); DigitalOut l(LED3); DigitalOut r(LED4); Motor A(p22, p6, p5, 1); // pwm, fwd, rev, can brake Motor B(p21, p7, p8, 1); // pwm, fwd, rev, can brake int main() { wifly.init(); // use DHCP while (!wifly.connect()); char buffer[2]; buffer[1]='\0'; char a; while(1) { http.get("http://develop.jissjohn.com/netbot/command.txt", buffer,2); printf("\n%s\n\r", buffer); a=buffer[0]; if(a=='1')// Forward direction {f=1; A.speed(0.4); B.speed(0.4); wait(0.02); } else if(a=='5')//Reverse Direction {b=1; f=0; l=0; r=0; A.speed(-0.4); B.speed(-0.4); wait(0.02); } else if(a=='7')//Turn Left Direction { l=1; f=0; r=0; b=0; A.speed(-0.5); B.speed(0.5); wait(0.02); } else if(a=='3')//Turn Right Direction {r=1; f=0; l=0; b=0; A.speed(0.5); B.speed(-0.5); wait(0.02); } else { A.stop(1); B.stop(1); wait(1); A.coast(); B.coast(); } } wifly.disconnect(); }