Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Autopilot dillerdasker Rfid mbed
Fork of RoboticHackathon2 by
Revision 2:b996c95912b5, committed 2014-04-07
- Comitter:
- iLyngklip
- Date:
- Mon Apr 07 06:24:19 2014 +0000
- Parent:
- 1:e854d5c12659
- Child:
- 3:9289c1e52ca5
- Commit message:
- Final version 2. drive
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Rfid.lib Mon Apr 07 06:24:19 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/iLyngklip/code/Rfid/#051708395e3c
--- a/hack_motor.cpp Sat Apr 05 11:26:42 2014 +0000
+++ b/hack_motor.cpp Mon Apr 07 06:24:19 2014 +0000
@@ -101,21 +101,45 @@
HejsA = 0;
}
-void Wheel::venSelv1()
+void Wheel::venSelv1() // Højre
{
- M1A.write(0.9); //Set the duty cycle to the wanted percent, from speed variable
+ M1A.write(0.7); //Set the duty cycle to the wanted percent, from speed variable
+ M2A.write(0.0); // -//-
+ M1B = 0;
+ M2B = 0;
+ wait_ms(100);
+ M2A.write(0.7);
+ }
+void Wheel::venSelv2() // Venstre
+ {
+ M1A.write(0.0); //Set the duty cycle to the wanted percent, from speed variable
M2A.write(0.7); // -//-
M1B = 0;
M2B = 0;
- wait_ms(10);
- M2A.write(0.9);
+ wait_ms(100);
+ M1A.write(0.7);
}
-void Wheel::venSelv2()
+void Wheel::venSelv3() // Skarp højre
{
+ M1A.write(0.8);
+ M2A.write(0.8);
+ wait_ms(25);
M1A.write(0.7); //Set the duty cycle to the wanted percent, from speed variable
- M2A.write(0.9); // -//-
+ M2A.write(0.95); // -//-
M1B = 0;
+ M2B = 1;
+ wait_ms(10);
+ M1A.write(0.0);
+ }
+void Wheel::venSelv4() // Venstre Skarpt
+ {
+ M1A.write(0.8);
+ M2A.write(0.8);
+ wait_ms(25);
+ M1A.write(0.95); //Set the duty cycle to the wanted percent, from speed variable
+ M2A.write(0.7); // -//-
+ M1B = 1;
M2B = 0;
wait_ms(10);
- M1A.write(0.9);
+ M1A.write(0.0);
}
\ No newline at end of file
--- a/hack_motor.h Sat Apr 05 11:26:42 2014 +0000
+++ b/hack_motor.h Mon Apr 07 06:24:19 2014 +0000
@@ -24,6 +24,8 @@
void saenk();
void venSelv1();
void venSelv2();
+ void venSelv3();
+ void venSelv4();
float speed;
protected:
--- a/main.cpp Sat Apr 05 11:26:42 2014 +0000
+++ b/main.cpp Mon Apr 07 06:24:19 2014 +0000
@@ -8,20 +8,21 @@
HCSR04 sensor(PTA13, PTD5, PTD0, PTD2);
Wheel robot;
-
+int control = 0;
+int L1 = 0;
+int L2 = 0;
int main(){
pc.baud(9600);
- while(1){
+ while(control == 0){
robot.init();
char c;
pc.printf(" speed 1, 2 & 3, frem w, bagud s, venstre a & hoejre d");
{
- c = pc.getc();
-
+ c = pc.getc();
switch (c)
{
case 0x31:
@@ -39,24 +40,29 @@
pc.printf("3");
break;
- case 0x77:
+ case 's':
robot.FW();
- pc.printf("w");
+ pc.printf("s");
break;
- case 0x73:
+ case 'w':
robot.BW();
- pc.printf("s");
+ pc.printf("w");
break;
case 0x61:
robot.left();
pc.printf("a");
+ wait(0.1);
+ robot.stop();
+
break;
case 0x64:
robot.right();
- pc.printf("d");
+ pc.printf("d");
+ wait(0.1);
+ robot.stop();
break;
case 'n':
@@ -78,13 +84,61 @@
robot.saenk();
pc.printf("b");
break;
+
+ case 'p':
+ control = 1;
+ break;
+
default :
robot.stop();
break;
}
}
+ }
+ {
+
+
+
+
+
} // while
+
+ while(control == 1){
+
+ L1 = sensor.Distance(CM); // Højre
+ L2 = sensor.distance(CM); // Venstre
+
+ pc.printf("L1: %ld L2: %ld \r\n", L1, L2);
+
+
+ if(L1 >= L2 && L1 > 50){
+ robot.venSelv3(); // Højre skarpt
+ }
+
+ if(L2 >= L1 && L2 > 50){
+ robot.venSelv4(); // Venstre skarpt
+ }
+
+ if(L1 >= L2){
+ robot.venSelv1(); // Højre
+ }
+
+
+
+ if(L2 > L1){
+ robot.venSelv2(); // Venstre
+ }
+
+ if(L1 > 65){
+ control = 0;
+ }
+ }
+
+
+
+
+
} // main
