sibren vuurberg / Mbed 2 deprecated speed_motors

Dependencies:   MODSERIAL QEI mbed

Files at this revision

API Documentation at this revision

Comitter:
sivuu
Date:
Mon Oct 17 08:23:28 2016 +0000
Commit message:
groep 12

Changed in this revision

MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
QEI.lib 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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Mon Oct 17 08:23:28 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/MODSERIAL/#4737f8a5b018
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI.lib	Mon Oct 17 08:23:28 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aberk/code/QEI/#5c2ad81551aa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Oct 17 08:23:28 2016 +0000
@@ -0,0 +1,77 @@
+#include "mbed.h" //standaard bieb mbed
+#include "QEI.h"  //bieb voor encoderfuncties in c++
+#include "MODSERIAL.h" //bieb voor modserial
+InterruptIn sw3(SW3);
+DigitalIn encoder1A(D13); 
+DigitalIn encoder1B(D12);
+DigitalIn button_cw(D11);
+DigitalIn encoder2A(D15);
+DigitalIn encoder2B(D14);
+DigitalIn button_ccw(D9);
+DigitalOut ledcw(D10);
+DigitalOut ledccw(D2);
+MODSERIAL pc(USBTX, USBRX);
+DigitalOut richting_motor1(D4);
+PwmOut pwm_motor1(D5);
+DigitalOut richting_motor2(D7);
+PwmOut pwm_motor2(D6);
+
+
+int n = 0; //start van de teller wordt op nul gesteld
+ 
+void SwitchN() {                        // maakt simpele functie die 1 bij n optelt
+    n++;
+    }
+    
+//constanten voor de encoder
+const int CW = 1; //definitie rechtsom 'lage waarde'
+const int CCW =0; //definitie linksom 'hoge waarde'
+const float gearboxratio=131; // gearboxratio van encoder naar motor
+const int rev_rond=32;        // aantal revoluties per omgang van de encoder
+    
+ 
+int main()
+{
+  pc.baud(115200);                      // zorgt voor de link voor putty, 115200 is snelheid
+  QEI Encoder1(D12,D13, NC, rev_rond);  // maakt een encoder aan! D12/D13 ingangen, rev_rond zijn aantal pulsen per revolutie! Bovenaan in te stellen. 
+  QEI Encoder2(D15,D14, NC, rev_rond);
+    float counts_encoder1;                  //variabele counts aanmaken
+    float rev_counts_motor1;                   //variabele motor rondjes aanmaken in radialen!!
+    float counts_encoder2;
+    float rev_counts_motor2;
+             
+ const float a=1.0; //voltingang motor 1
+ const float b=12;//voltingang motor 2
+ 
+  while (true) {                        // zorgt er voor dat de code oneindig doorgelopen wordt
+     
+   
+    if (button_cw==0)                        // als s ingedrukt wordt gebeurd het volgende
+    {
+                            
+           richting_motor1 = CW;
+           pwm_motor1 = a; 
+           counts_encoder1 = Encoder1.getPulses(); //tellen van de pulsen in  
+           rev_counts_motor1=counts_encoder1/(gearboxratio*rev_rond);              //berekenen van het aantal rondjes van motor. Gedeeld door gearboxratio en rev rond, om naar motorrondjes te gaan in plaats van pulsen van encoder!
+           pc.printf("motor rondjes motor1: %f \r\n", rev_counts_motor1);                  //weergeven
+          
+            
+                                  // als s is ingedrukt maar het getal is niet even (dus oneven) gebeurdt het onderstaande
+         
+           pc.printf("n is odd \n\r");  // print lijn "n is odd"
+           pc.printf("left \n\r");      // print lijn "left"
+           richting_motor2 = CCW;
+           pwm_motor2 = b;
+           counts_encoder2 = Encoder2.getPulses(); //tellen van de pulsen in  
+        rev_counts_motor2=counts_encoder2/(gearboxratio*rev_rond);            //weergeven van het aantal rondjes
+        pc.printf("motor rondjes motor2: %f \r\n", rev_counts_motor2);             
+    }   
+    
+    else{
+      // pc.printf("motor staat stil \n\r");
+    pwm_motor2=0;
+    pwm_motor1=0;
+        }              
+        }
+}      
+        
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Oct 17 08:23:28 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3
\ No newline at end of file