unsigned char s1[9]="AT\r\n"; //send "AT" command modem will response
unsigned char s2[18]="AT+CIPMODE=0\r\n";//Select TCPIP Application mode unsigned char s3[30]="AT+CLPORT=\"TCP\",\"5000\"\r\n"; //set Local Port unsigned char s4[45]="AT+CIPCSGP=1,\"airtelgprs.com\"\r\n";//set csd or GPRS for Connection mode "ur GPRS provide address" unsigned char s5[15]="AT+CSTT\r";//Start Task and set apn unsigned char s6[15]="AT+CIICR\r";//Bring up wireless connection with GPRS or CS D unsigned char s7[15]="AT+CIFSR\r"; // Get Local Ip Address "is assign for GPRS M odem" code unsigned char s8[50]="AT+CIPSTART=\"TCP\",\"10.3.0.100\",\"5000\"\r\n"; // Start Up TCP or Udp Connection you need to specify your IP of server unsigned char s9[15]="AT+CIPSEND\r\n"; //Send Datat Through TCP or UDP Connectio n unsigned char sd[46]="193308950\r\n"; / obstacle avoidance #include "mbed.h" #include "motordriver.h" Serial pc(USBTX, USBRX); Motor A(p23, p5, p6, 1); // pwm, fwd, rev, can brake Motor B(p22, p30, p29, 1); // pwm, fwd, rev, can brake AnalogIn p(p18); int main() {
project #include "mbed.h" //header file #include "Servo.h" // for servo motor #include "motordriver.h" // for mtotr driver void KNM(void); void RESTROOM(void); void STAIRS(void); void MEDICAL_ELECTRONICS(void); void START(int); Serial pc(USBTX, USBRX); Motor A(p21 ,p5, p6 ,1); // pwm, motor input A, motor input B, can brake Motor B(p22 ,p7, p8 ,1); Motor C(p23 ,p9, p10 ,1); Motor D(p24 ,p11, p12 ,1); Servo myservo(p25); // servo i/o pin AnalogIn u(p15); // ultrasonic sensor pin LocalFileSystem local("local"); int n[10]; char m[10]; int i=0; int c ; int main() { myservo.calibrate(0.004,45) ; pc.printf("\rPress\n\r\t1 for KNM room \n\r\t2 for STAIRS\n\r\t3 for RESTROO M\n\r\t4 for MEDICAL ELECTRONICS ROOM\n\r");
pc.scanf("%d",&c); START(c); } void START(int c) { switch(c) { case (1): KNM(); break; case (2): STAIRS(); break; case (3): RESTROOM(); break; case (4): MEDICAL_ELECTRONICS(); break; } } void KNM() //KNM file read and direct { FILE *fp = fopen("/local/KNM_DIRECTION.csv", "r"); // open the file in 'read' m ode
// while not end of file c=fgetc(fp); // get a character/byte from the file printf("Read from file %02x\n\r",c); // and show it in hex format fclose(fp); } void STAIRS() //STAIRS file read a nd direct { FILE *fp = fopen("/local/STAIRS_DIRECTION.csv", "r"); i=0; while (!feof(fp)) { m[i]=fgetc(fp); i++; } fclose(fp); fp = fopen("/local/STAIRS_VALUE.csv", "r"); i=0; while (!feof(fp)) { n[i]=fgetc(fp); i++ ; } fclose(fp); for(i=0;i<3;i++) { pc.printf("\t\r\n%c\t%d",m[i],n[i]); } } void RESTROOM() //RESTROOM file read and direct { FILE *fp = fopen("/local/RESTROOM_DIRECTION.csv", "r"); i=0; while (!feof(fp)) { m[i]=fgetc(fp); i++; } fclose(fp); fp = fopen("/local/RESTROOM_VALUE.csv", "r"); i=0; while (!feof(fp)) { n[i]=fgetc(fp); i++ ; } fclose(fp); for(i=0;i<3;i++) { pc.printf("\t\r\n%c\t%d",m[i],n[i]); } } void MEDICAL_ELECTRONICS() //MED_ELEC file read and direct { FILE *fp = fopen("/local/MED_ELEC_DIRECTION.csv", "r"); i=0; while (!feof(fp)) { m[i]=fgetc(fp); i++; } fclose(fp); fp = fopen("/local/MED_ELEC_VALUE.csv", "r"); i=0; while (!feof(fp)) { n[i]=fgetc(fp); i++ ; } fclose(fp); for(i=0;i<3;i++) { pc.printf("\t\r\n%c\t%d",m[i],n[i]); } } serial communication #include "mbed.h"
Serial pc(USBTX, USBRX); // tx, rx AnalogIn s1(p18); int main() { float x,y; while(1) { x=s1.read(); y=x*330;
for(float p=0.9; p>0.0; p -= 0.1) { myservo = p; wait(0.099); }} } servo 123 #include "mbed.h" #include "Servo.h" Servo myservo(p21); Serial pc(USBTX, USBRX); int main() { printf("Servo Calibration Controls:\n"); printf("1,2,3 - Position Servo (full left, middle, full right)\n"); printf("4,5 - Decrease or Increase range\n"); float range = 0.0005; float position = 0.5;
while(1) { switch(pc.getc()) { case '1': position = 0.0; break; case '2': position = 0.5; break; case '3': position = 1.0; break; case '4': range += 0.0001; break; case '5': range -= 0.0001; break; } printf("position = %.1f, range = +/-%0.4f\n", position, range); myservo.calibrate(range,60); myservo = position; } } static map #include "mbed.h" Serial pc(USBTX, USBRX); // USING HOST COMP AS IPUT AND SIMULATION char k[4]={'F','5','L','3'}; char r[4]={'F','8','L','4'}; char s[4]={'R','8','L','6'}; char me[4]={'L','9','F','9'}; int main() { pc.printf("\rPress '1' for KNM room , '2' for restroom, '3' for stairs, '4' for med electronics room\n\r"); int c ; pc.scanf("%d",&c);
switch(c) { case 1:
pc.printf("MOVING TOWARDS KNM ROOM\n\r");// output on host pc using hyper terminal wait(1); pc.printf("MOVING %c%c\n\r",k[0],k[1]); wait(1); pc.printf("MOVING %c%c\n\r",k[2],k[3]); wait(1); pc.printf("destination reached\n\r"); break;
case 2:
pc.printf("MOVING TOWARDS RESTROOM\n\r");// output on hos t pc using hyper terminal wait(1); pc.printf("MOVING %c%c\n\r",r[0],r[1]); wait(1); pc.printf("MOVING %c%c\n\r",r[2],r[3]); wait(1); pc.printf("destination reached\n\r"); break;
case 3:
pc.printf("MOVING TOWARDS STAIRS\n\r");// output on host pc using hyper terminal wait(1); pc.printf("MOVING %c%c\n\r",s[0],s[1]); wait(1); pc.printf("MOVING %c%c\n\r",s[2],s[3]); wait(1); pc.printf("destination reached\n\r"); break;
case 4:
pc.printf("MOVING TOWARDS MEDICAL ELECTRONICS ROOM\n\r"); // output on host pc using hyper terminal wait(1); pc.printf("MOVING %c%c\n\r",me[0],me[1]); wait(1); pc.printf("MOVING %c%c\n\r",me[2],me[3]); wait(1); pc.printf("destination reached\n\r"); break; default: pc.printf("ENTER A VALID INPUT\n\r");
} } static map excel #include "mbed.h" Serial pc(USBTX, USBRX); // FOR SERIAL COMMUNICATION VIA PC LocalFileSystem local("local"); // Create the local filesystem under the name "local" char e,f; //GLOBAL DECLARATION OF VARIABL ES int a,b; float m; FILE *fr1; int path; char c[5]; int main() {
fr1= fopen("/local/E.csv", "w"); //for scanning direction if(fr1==NULL)
pc.printf("error");
fprintf(fr1,"2\n"); fprintf(fr1,"F146\n"); fprintf(fr1,"L73\n"); fclose(fr1); } motor driver /*motor driver libary modified from the following libary, * * mbed simple H-bridge motor controller * Copyright (c) 2007-2010, sford * * by Christopher Hasler. * * from sford's libary, * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include "motordriver.h" #include "mbed.h" Motor::Motor(PinName pwm, PinName fwd, PinName rev, int brakeable): _pwm(pwm), _fwd(fwd), _rev(rev) { // Set initial condition of PWM _pwm.period(0.001); _pwm = 0; // Initial condition of output enables _fwd = 0; _rev = 0; //set if the motor dirver is capable of braking. (addition) Brakeable= brakeable; sign = 0;//i.e nothing. } float Motor::speed(float speed) { float temp = 0; if (sign == 0) { _fwd = (speed > 0.0); _rev = (speed < 0.0); temp = abs(speed); _pwm = temp; } else if (sign == 1) { if (speed < 0) { _fwd = (speed > 0.0); _rev = (speed < 0.0); _pwm = 0; temp = 0; } else { _fwd = (speed > 0.0); _rev = (speed < 0.0); temp = abs(speed); _pwm = temp; } } else if (sign == -1) { if (speed > 0) { _fwd = (speed > 0.0); _rev = (speed < 0.0); _pwm = 0; temp = 0; } else { _fwd = (speed > 0.0); _rev = (speed < 0.0); temp = abs(speed); _pwm = temp; } } if (speed > 0) sign = 1; else if (speed < 0) { sign = -1; } else if (speed == 0) { sign = 0; } return temp; } // (additions) void Motor::coast(void) { _fwd = 0; _rev = 0; _pwm = 0; sign = 0; } float Motor::stop(float duty) { if (Brakeable == 1) { _fwd = 1; _rev = 1; _pwm = duty; sign = 0; return duty; } else Motor::coast(); return -1; } float Motor::state(void) { if ((_fwd == _rev) && (_pwm > 0)) { return -2;//braking } else if (_pwm == 0) { return 2;//coasting } else if ((_fwd == 0) && (_rev == 1)) { return -(_pwm);//reversing } else if ((_fwd == 1) && (_rev == 0)) { return _pwm;//fowards } else return -3;//error } /* test code, this demonstrates working motor drivers. Motor A(p22, p6, p5, 1); // pwm, fwd, rev, can break Motor B(p21, p7, p8, 1); // pwm, fwd, rev, can break int main() { for (float s=-1.0; s < 1.0 ; s += 0.01) { A.speed(s); B.speed(s); wait(0.02); } A.stop(); B.stop(); wait(1); A.coast(); B.coast(); } */ #include "motordriver.h" #include "mbed.h" #include "obstacle_scan.h" DigitalIn ol(p19); void obstacle_scan_class::obstacle_scan_func() { Serial pc(USBTX, USBRX); Motor A(p23, p5, p6, 1); // pwm, fwd, rev, can brake Motor B(p22, p30, p29, 1); // pwm, fwd, rev, can brake pc.printf("\n\r\tobstacle detetcted A\n"); A.stop(1); B.stop(1); count=0; A.speed(1); // moving right B.speed(-1); x=35; y=20; o=50;
ultrasonic_sensor_detection_threshold=0.7; //for detection of a obstacle ultrasonic_sensor_error_threshold=0.7; //for waiting when obstacle d etected after avoidable distance obstacle_lenght_count=35; //no of counts on slot requir ed by vehicle to avoid the obsctacle count_90=20;
Serial pc(USBTX, USBRX); pc.printf("\n\r\tmoving straight");
Motor A(p24, p5, p6, 1); // pwm, fwd, rev, can brake Motor B(p22, p30, p29, 1); // pwm, fwd, rev, can brake
count_straight=n;
count=0;
A.speed(1); B.speed(1);
while(count<=count_straight) { while(slot.read()) { } count++; pc.printf("\n\r\t%d\t\t\t%f",count,ultrasonic_sensor.read()); if(ultrasonic_sensor.read()>=ultrasonic_sensor_detection_threshold) //obstacle detection { A.stop(1); B.stop(1); if(count>=(n-obstacle_lenght_count)) // if obstacle above avoidable position { pc.printf("obstacle detected beyond avoidable range..... please remove the obstacle to continue"); while(ultrasonic_sensor.read()>=ultrasonic_sensor_detection_thre shold) {} } else // if not then obstacle avoiding function is called { pc.printf("\n\r\tobstacle detected"); wait(0.5); obstacle_avoiding_class object; object.obstacle_avoiding_func(); count=count+65; } A.speed(1); B.speed(1); }
Serial pc(USBTX, USBRX); directions_class directions_object; directions_object.right(); //right directions_object.straight(obstacle_width_count); //right straight directions_object.left(); //left directions_object.straight(obstacle_lenght_count); //straight directions_object.left(); //left directions_object.straight(obstacle_width_count); //left straight directions_object.right(); //right and halt } excel writing #include "mbed.h" Serial pc(USBTX, USBRX); // FOR SERIAL COMMUNICATION VIA PC LocalFileSystem local("local"); // Create the local filesystem under the name "local" FILE *fr1,*fr2; int main() { fr2= fopen("/local/test_1.xls", "w"); //for scanning direction