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.
Fork of PES by
Revision 6:4af735d26b7a, committed 2017-04-11
- Comitter:
- itslinear
- Date:
- Tue Apr 11 14:53:18 2017 +0000
- Parent:
- 5:f48b2609c328
- Child:
- 7:edb4e0cfc0d1
- Commit message:
- new
Changed in this revision
--- a/Roboter.cpp Tue Apr 11 14:43:29 2017 +0000
+++ b/Roboter.cpp Tue Apr 11 14:53:18 2017 +0000
@@ -20,9 +20,6 @@
this->switch2 = switch2;
- pwmL->period(0.00005f); // Setzt die Periode auf 50 μs
- pwmR->period(0.00005f);
-
}
float Roboter::readSensor1()
@@ -39,19 +36,23 @@
float x=0.13f; // Distanz ab welcher sensoren reagieren sollen
+ offsetDir = 0;
+ offsetLin = 0;
- offsetDir = 0;
- offsetLin = 0.1;
-
+ if(sensors[0] < x && sensors[1] < x && sensors[5] < x) { // alle sensoren aktiv, roboter fährt nach hinten
+ offsetLin = -0.1f;
+ }
if(sensors[0].read() < x && sensors[5] > x) { // sensor vorne, roboter dreht nach links
offsetDir = -0.05;
offsetLin = 0;
}
+
if(sensors[1] < x) { // sensor rechts, roboter dreht nach links
offsetDir = -0.05;
offsetLin = 0;
}
+
if(sensors[5] < x && sensors[1]>(x+0.02f)) { // sensor links, roboter dreht nach rechts
offsetDir = 0.05;
offsetLin = 0;
@@ -71,23 +72,3 @@
}
-
-void Roboter::findBlock() //im Kreis drehen
-{
- static int count =0;
- count++;
-
- if(count <= 10); //1s lang (10*0.1s) im Kreis drehen
- *pwmL = 0.55f;
- *pwmR = 0.55f;
-
- if(count > 10 && count <= 20); //zwischen Sekunde 1 und 2 geradeaus fahren
- *pwmL = 0.6f;
- *pwmR = 0.4f;
-
- if(count > 20 && count <=30); //zwischen Sekunde 2 und 3 im Kreis drehen
- *pwmL = 0.55f;
- *pwmR = 0.55f;
-
-}
-
--- a/Roboter.h Tue Apr 11 14:43:29 2017 +0000
+++ b/Roboter.h Tue Apr 11 14:53:18 2017 +0000
@@ -15,7 +15,7 @@
void bandeAusweichen();
float readSensor1();
void pickup();
- void findBlock();
+
private:
--- a/main.cpp Tue Apr 11 14:43:29 2017 +0000
+++ b/main.cpp Tue Apr 11 14:53:18 2017 +0000
@@ -15,13 +15,13 @@
Servo servos1(PB_7);
Servo servos2(PA_6);
-//Periphery for limit switch
+//Periphery for limit switch
DigitalIn limitSwitch1(PA_10);
-DigitalIn limitSwitch2(PB_13);
+DigitalIn limitSwitch2(PB_13);
-//Periphery for Swich ON/OFF
+//Periphery for Switch ON/OFF
-DigitalIn swichOnOFF (USER_BUTTON);
+DigitalIn swichtOnOFF (USER_BUTTON);
//motor stuff
DigitalOut enableMotorDriver(PB_2);
@@ -35,56 +35,82 @@
int main()
{
- enable = 1; // Sensoren einschalten
- enableMotorDriver = 1; // Schaltet die Motoren ein
+ enable = 1; // Sensoren einschalten
+ enableMotorDriver = 1; // Schaltet die Motoren ein
pwmL->period(0.00005f); // Setzt die Periode auf 50 μs
pwmR->period(0.00005f);
-
+
int state = 0; // Diese Variable gibt an in welchem State man sich befindet
-if ( kamera() == 1){ state = 4;) // Die Kamera erkennt ein grünen Klotz
- while(1) {
+ if ( kamera() == 1) {
+ state = 4;
+ ) // Die Kamera erkennt ein grünen Klotz
+ while(1) {
+
+ switch(state) {
+
+ case 1: // Roboter Anschalten mit Knopf
+
+ if (switchOnOff == 1) {
+ state = 2;
+ }
+ if (swichtOnOff ==0) {
+ state =1;
+ }
+ break;
+
+ case 2:
+ roboter1.bandeAusweichen();
+ static int time1 = 0;
+ if(time1 < 10) { // Im Kreis drehen für 1s
+ pwmL = 0.4f;
+ pwmR = 0.4f;
+ time1 ++;
+ } else {
+ time1 = 0;
+ pwmL = 0.5f;
+ pwmR = 0.5f;
+ state = 3;
+ }
+ break;
+
- swich(state){
-
- case 1: // Roboter Anschalten mit Knopf
-
- if (swichOnOff == 1){
- state = 2;}
- if (swichOnOff ==0){
- state =1;)
-
- break;
-
- case 2: // Im Kreis drehen
-
- ....
- break;
-
- case 3: // gerade aus fahren
-
- ....
- break;
-
- case 4: // Roboter erkennt gründer Klotz, Klotz wird angefahren
-
- ...
- break;
-
- case 5: // Aufnehmen des Klotzes
-
-
- .....
- break;
-
-
- default
-
- ... break ; }
+ case 3:
+ roboter1.bandeAusweichen();
+ static int time2 = 0;
+ if(time2 < 10) { // gerade aus fahren
+ pwmL = 0.6f;
+ pwmR = 0.4f;
+ time2 ++;
+ } else {
+ time2 = 0;
+ pwmL = 0.5f;
+ pwmR = 0.5f;
+ state = 2;
+ }
+ break;
+
+
+ case 4: // Roboter erkennt gründer Klotz, Klotz wird angefahren
- wait(0.1f);
+ ...
+ break;
+
+ case 5: // Aufnehmen des Klotzes
+
+
+ .....
+ break;
+
+
+ default
+
+ ... break ;
+ }
+
+ wait(0.1f);
+
+ }
}
-}
-
