zhaw_st16b_pes2_10 / Mbed 2 deprecated PES_Official

Dependencies:   mbed Servo ServoArm

Fork of PES_Yanick by zhaw_st16b_pes2_10

Files at this revision

API Documentation at this revision

Comitter:
beacon
Date:
Wed Apr 26 14:09:08 2017 +0000
Parent:
5:1aaf5de776ff
Child:
7:6fed0dcae9c1
Child:
8:593f82e66bdf
Commit message:
YESSS! On time!!

Changed in this revision

Headers/Declarations.h Show annotated file Show diff for this revision Revisions of this file
Headers/Robot.h Show annotated file Show diff for this revision Revisions of this file
Sources/Arm.cpp Show annotated file Show diff for this revision Revisions of this file
Sources/Robot.cpp Show annotated file Show diff for this revision Revisions of this file
Sources/main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Headers/Declarations.h	Wed Apr 26 08:05:25 2017 +0000
+++ b/Headers/Declarations.h	Wed Apr 26 14:09:08 2017 +0000
@@ -28,8 +28,10 @@
 //Greifer:
 #define PC_7 SERVO0
 
-//Arm:
-#define BACK 80             //Angle to set the arm up and back
+//Arm
+#define COLLECT_POS 65.0f
+#define RELEASE_POS 80.0f
+#define TAKE_POS -70.0f
 
 //Misc:
 #define TIMEOUT 140         //if the timer reaches TIMEOUT ([TIMEOUT] = 0.1s), the robot will reset.
--- a/Headers/Robot.h	Wed Apr 26 08:05:25 2017 +0000
+++ b/Headers/Robot.h	Wed Apr 26 14:09:08 2017 +0000
@@ -53,24 +53,26 @@
     
         AnalogIn*   FarbVoltage;
 };
-/*
+
 class Arm{
     
     public:
-        Arm(Servo joint);
+        
         Arm();
-        void init(Servo joint);
+        Arm(Servo* servoArm);
         
-        void down();
-        void neutral();
-        void back();
-        void setAngle(float angle);
+        void init(Servo* servoArm);
+        
+        void collecttodown(int* done);
+        void downtocollect(int* done);
+        void collecttoback(int* done);
+        void backtocollect(int* done);
         
     private:
-        Servo joint;
+        Servo*  servoArm;
+        float   angle;
         
 };
-*/
 
 class Robot
 {
@@ -78,7 +80,7 @@
     public:
         
         //Robot related:
-        Robot(PwmOut* left, PwmOut* right, DigitalOut* enableSignal, DigitalOut* leds, AnalogIn* FarbVoltage,  AnalogIn* frontS, AnalogIn* leftS, AnalogIn* rightS );
+        Robot(PwmOut* left, PwmOut* right, DigitalOut* enableSignal, DigitalOut* leds, AnalogIn* FarbVoltage,  AnalogIn* frontS, AnalogIn* leftS, AnalogIn* rightS, Servo* Arm );
         
         //Drive Functions
         void drive();
@@ -117,10 +119,13 @@
         //void init();
         
         //LEDS related:
-        DigitalOut*      leds;
+        DigitalOut*     leds;
         
         //Farbsensors related:
-        Farbsensor FarbVoltage;
+        Farbsensor      FarbVoltage;
+        
+        //Arm related:
+        Arm             Arm;
         
     private:
     
--- a/Sources/Arm.cpp	Wed Apr 26 08:05:25 2017 +0000
+++ b/Sources/Arm.cpp	Wed Apr 26 14:09:08 2017 +0000
@@ -1,30 +1,61 @@
-/*#include "Robot.h"
+#include "Robot.h"
+#include "Declarations.h"
+
 
-Arm::Arm(Servo joint){
-    init(joint);
+Arm::Arm(){
+}
+
+Arm::Arm(Servo* servoArm){
+    init(servoArm);
 }
 
-Arm::Arm(){
+void Arm::init(Servo* servoArm){
+    this->servoArm = servoArm;
     
+    this->servoArm->calibrate(0.0015f, 180.0f);
+    this->servoArm->position(COLLECT_POS);
 }
 
-void Arm::init(Servo joint){
-    this.joint = joint;
+void Arm::collecttodown(int* done){
+    static float pos=COLLECT_POS;
+    if(pos>TAKE_POS) {
+        pos-=0.5f;
+        this->servoArm->position(pos);
+    }
+    else{
+        *done = 1;
+    }
 }
 
-void Arm::down(){
-    //do stuff
-}
-
-void Arm::neutral(){
-    //do stuff
+void Arm::downtocollect(int* done){
+    static float pos=TAKE_POS;
+    if(pos<COLLECT_POS) {
+        pos+=0.5f;
+        this->servoArm->position(pos);
+        }
+    else{
+        *done = 1;
+    }
 }
 
-void Arm::back(){
-    //do stuff
+void Arm::collecttoback(int* done){
+    static float pos=COLLECT_POS;
+    if(pos<RELEASE_POS) {
+        pos+=0.5f;
+        this->servoArm->position(pos);
+        }
+    else{
+        *done = 1;
+    }
 }
 
-void Arm::setAngle(float angle){
-    //do stuff
-}
-*/
\ No newline at end of file
+void Arm::backtocollect(int* done){
+    static float pos=RELEASE_POS;
+    if(pos>COLLECT_POS) {
+        pos-=0.5f;
+        this->servoArm->position(pos);
+        }
+    else{
+        *done = 1;
+    }
+}
\ No newline at end of file
--- a/Sources/Robot.cpp	Wed Apr 26 08:05:25 2017 +0000
+++ b/Sources/Robot.cpp	Wed Apr 26 14:09:08 2017 +0000
@@ -3,7 +3,7 @@
 
 /* Work in progress -------------------------------------------- */
 
-Robot::Robot(PwmOut* left, PwmOut* right, DigitalOut* enableSignal, DigitalOut* leds, AnalogIn* FarbVoltage, AnalogIn* frontS, AnalogIn* leftS, AnalogIn* rightS )
+Robot::Robot(PwmOut* left, PwmOut* right, DigitalOut* enableSignal, DigitalOut* leds, AnalogIn* FarbVoltage, AnalogIn* frontS, AnalogIn* leftS, AnalogIn* rightS, Servo* Arm )
 {
     this->powerSignal = enableSignal;
     this->left =        left;
@@ -19,7 +19,7 @@
     this->leftS =       leftS;
     this->rightS =      rightS;
     
-    this->arm =         arm;
+    this->Arm =         Arm;
 
 }
 
--- a/Sources/main.cpp	Wed Apr 26 08:05:25 2017 +0000
+++ b/Sources/main.cpp	Wed Apr 26 14:09:08 2017 +0000
@@ -30,12 +30,12 @@
 DigitalIn       overtemperatur(PB_15);
 
 //Arm:
-//Servo arm(PC_7);
+Servo servoArm(PA_6);
 
 //Farbsensor:
 AnalogIn FarbVoltage(A0);
 
-Robot sam( &left, &right, &powerSignal, leds, &FarbVoltage, &frontS, &leftS, &rightS ); //Implement the Farbsensor into the Robot init function!!
+Robot sam( &left, &right, &powerSignal, leds, &FarbVoltage, &frontS, &leftS, &rightS, &servoArm); //Implement the Farbsensor into the Robot init function!!
 
 void initializeDistanceSensors(){
     for( int ii = 0; ii<9; ++ii) {
@@ -45,7 +45,7 @@
     }
 }
 
-/* */
+/* * /
 int main(){
     initializeDistanceSensors();        //Initialises IR-Sensors.
     int counter = 0;                    //Counts how many times the robot has turned, before driving
@@ -101,4 +101,35 @@
         wait(0.2);
     }
 }
-/* */
\ No newline at end of file
+/* */
+
+/* */
+int main(){
+    sam.stop();
+    int done = 0;           //1:= finished process; 0:= not finished
+    int fun = 0;            //just to test.
+    
+    while(1){
+        if(fun == 0){
+            done = 0;
+            sam.Arm.collecttoback(&done);
+            done == 0 ? fun = 0 : fun = 1;
+        }
+        else if(fun == 1){
+            done = 0;
+            sam.Arm.backtocollect(&done);
+            done == 0 ? fun = 1 : fun = 2;
+        }
+        else if(fun == 2){
+            done = 0;
+            sam.Arm.collecttodown(&done);
+            done == 0 ? fun = 2 : fun = 3;
+        }
+        else if(fun == 3){
+            done = 0;
+            sam.Arm.downtocollect(&done);
+            done == 0 ? fun = 3 : fun = 0;
+        }
+        wait(0.1);
+    }
+}    
\ No newline at end of file