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 20:c961dc550882, committed 2017-05-01
- Comitter:
- schneju2
- Date:
- Mon May 01 09:42:51 2017 +0000
- Parent:
- 17:caf5ae550f2e
- Child:
- 21:d05dee0d1a7d
- Commit message:
- mit neues Main
Changed in this revision
| Roboter.cpp | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Roboter.cpp Tue Apr 25 12:26:04 2017 +0000
+++ b/Roboter.cpp Mon May 01 09:42:51 2017 +0000
@@ -1,5 +1,5 @@
#include "Roboter.h"
-
+#include "Servo.h"
Roboter::Roboter(AnalogIn* distance, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, PwmOut* pwmL, PwmOut* pwmR, Servo* s1, Servo* s2)
@@ -70,9 +70,14 @@
-void Roboter::pickup ()
-{
+void Roboter::pickup (){
+
+ }
+
+
+
-}
+
+
--- a/main.cpp Tue Apr 25 12:26:04 2017 +0000
+++ b/main.cpp Mon May 01 09:42:51 2017 +0000
@@ -1,6 +1,7 @@
#include <mbed.h>
#include "Roboter.h"
+
DigitalOut led(LED1);
//Periphery for distance sensors
@@ -34,19 +35,25 @@
enable = 1; // Sensoren einschalten
enableMotorDriver = 1; // Schaltet die Motoren ein
pwmL.period(0.00005f); // Setzt die Periode auf 50 μs
- pwmR.period(0.00005f);
- pwmL = 0.5f;
- pwmR = 0.5f;
+ pwmR.period(0.00005f); // Setzt die Periode auf 50 μs
+ pwmL = 0.5f; // Geschwindikeit auf 0
+ pwmR = 0.5f; // Geschwindikeit auf 0
int state = 0; // Diese Variable gibt an in welchem State man sich befindet
- int tempState = 2;
- int time1 = 0;
- int time2 = 0;
+ int tempState = 2; //
+ int time1 = 0; // Die Zeit wird auf 0 gesetzt
+ int time2 = 0; // Die Zeit wird auf 0 gesetzt
+
+
+
+
+
- while(1) {
+ while(1) {
- int camValue = readCamera();
+ double camValue = readCamera();
+
switch(state) {
@@ -61,10 +68,10 @@
case 1:
printf("1");
- if(camValue == 1 || camValue == 2 || camValue == 3) { // Die Kamera erkennt ein grünen Klotz
+ if(camValue >= 100 && camValue < 400 ) { // Die Kamera erkennt ein grünen Klotz , Werte von 100 und 399
state = 4;
}
- if(camValue == 4) { // Roboter in Position
+ if(camValue == 400) { // Roboter in Position
state = 5;
}
if(camValue == 0){
@@ -109,18 +116,25 @@
case 4: // Roboter erkennt gründer Klotz, Klotz wird angefahren
printf("4");
+ double maxWert = 0.3; // Maximale Werte für die pmL und pmR
roboter1.bandeAusweichen();
- if(camValue == 1) { // links fahren
+ if(camValue >= 100 && camValue <200 ) { // links fahren, wenn wir Werte von 100 bis 199 haben
+ camValue = camValue -99;
+ double speedValue = camValue * (maxWert /100.0);
pwmL = 0.45f;
- pwmR = 0.45f;
+ pwmR = 0.45f;
}
- if(camValue == 2) { // rechts fahren
- pwmL = 0.55f;
- pwmR = 0.55f;
+ if(camValue >=200 && camValue < 300) { // rechts fahren, wenn wir Werte von 200 bis 299 haben
+ camValue = camValue -199;
+ double speedValue = camValue * (maxWert /100.0);
+ pwmL = 0.5f + speedValue;
+ pwmR = 0.5f + speedValue;
}
- if(camValue == 3) { // gerade fahren
- pwmL = 0.55f;
- pwmR = 0.45f;
+ if(camValue >= 300 && camValue <400) { // gerade fahren, wenn wir Werte von 300 bis 399 haben
+ camValue = camValue-299; // CamValue nimmt die Werte von 1 bis 100 an
+ double speedValue = camValue * (maxWert /100.0); // Berechnung des speedValue's
+ pwmL = 0.5f + speedValue;
+ pwmR = 0.5f - speedValue;
}
state = 1;
@@ -146,5 +160,5 @@
//wait(0.1f);
}
-}
+}
