hej

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Risifutti
Date:
Sat Apr 05 09:30:52 2014 +0000
Commit message:
hej;

Changed in this revision

hack_motor.cpp Show annotated file Show diff for this revision Revisions of this file
hack_motor.h 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/hack_motor.cpp	Sat Apr 05 09:30:52 2014 +0000
@@ -0,0 +1,101 @@
+#include "mbed.h"
+#include "hack_motor.h"
+#include "PwmOut.h"
+
+Wheel::Wheel() : M1A(PTC8), M1B(PTC10), M2A(PTC9), M2B(PTC11), GrabA(PTA5), GrabB(PTC7), HejsA(PTA4), HejsB(PTC5)
+    {
+        init();    
+    }
+    
+    
+void Wheel::init() //Initialize the driver pwm to 150Hz
+    {
+        M1A.period(0.0066);
+        M2A.period(0.0066);
+        GrabA.period(0.0066);
+        HejsA.period(0.0066);
+        speed = 0.0;
+    }    
+    
+void Wheel::FW()
+    {
+        fw = 0.5+(0.5*speed); //forward lies in the upper 50% of the duty cycle
+        M1A.write(fw); //Set the duty cycle to the wanted percent, from speed variable
+        M2A.write(fw); // -//-
+        M1B = 0;
+        M2B = 0;
+        wait_ms(1);
+    }
+    
+void Wheel::BW()
+    {
+        bw = 0.5-(0.5*speed); //Backward lies within the lower 50% of the duty cycle
+        M1A.write(bw); //Set the duty cycle to the wanted percent, from speed variable
+        M2A.write(bw); // -//-
+        M1B = 1; 
+        M2B = 1;
+    }
+    
+void Wheel::right()
+    {
+        M1A.write(0.75); //Left side forward 50%
+        M2A.write(0.25); //Right side backwards 50%
+        M1B = 0;
+        M2B = 1;
+    }
+    
+void Wheel::left()
+    {
+        M1A.write(0.25); //Right side forward 50%
+        M2A.write(0.75); //Left side backwards 50%
+        M1B = 1;
+        M2B = 0;
+    }
+    
+void Wheel::stop()
+    {
+        M1A.write(0.0); //Pin A's set low
+        M2A.write(0.0);
+        M1B = 0;
+        M2B = 0;  //Pin B's set high
+        GrabA.write(0.0);
+        HejsA.write(0.0);
+        GrabB = 0;
+        HejsB = 0;
+    }
+    
+void Wheel::open()
+    {
+        GrabA.write(0.3);
+        GrabB = 1;
+        wait(0.9);
+        GrabA.write(0.0);
+        GrabB = 0;
+    }
+    
+void Wheel::close()
+    {
+        GrabA.write(0.8);
+        GrabB = 0;
+        wait(0.6);
+        GrabA.write(0.0);
+        GrabB = 0;
+    }
+    
+    void Wheel::hejs()
+    {
+        HejsA.write(0.75);
+        HejsB = 0;
+        wait(0.3);
+        HejsA.write(0.0);
+        HejsB = 0;
+    }
+    
+void Wheel::saenk()
+    {
+        HejsA.write(0.25);
+        HejsB = 1;
+        wait(0.3);
+        HejsA.write(0.0);
+        HejsA = 0;
+        }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hack_motor.h	Sat Apr 05 09:30:52 2014 +0000
@@ -0,0 +1,34 @@
+#ifndef HACK_MOTOR_H
+#define HACK_MOTOR_H
+#include "mbed.h"
+
+class Wheel {
+ 
+public:
+    PwmOut M1A, M2A;
+    PwmOut GrabA;
+    PwmOut HejsA;
+    
+    DigitalOut M1B, M2B, GrabB, HejsB;
+    
+    Wheel();
+    void FW();
+    void BW();
+    void right();
+    void left();
+    void stop();
+    void init();
+    void open();
+    void close();
+    void hejs();
+    void saenk();
+    float speed;
+    
+protected:
+    float fw, bw;
+    
+};
+
+    
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Apr 05 09:30:52 2014 +0000
@@ -0,0 +1,80 @@
+#include "mbed.h" 
+#include "hack_motor.h" 
+  
+Serial pc(USBTX, USBRX); 
+  
+Wheel robot; 
+  
+main() 
+    { 
+        robot.init(); 
+        char c; 
+        pc.printf(" speed 1, 2 & 3, frem w, bagud s, venstre a & hoejre d"); 
+          
+        while (1) 
+            { 
+            c = pc.getc(); 
+              
+            switch (c) 
+                {  
+                    case 0x31: 
+                        robot.speed = 1.0; 
+                        pc.printf("1"); 
+                        break; 
+                          
+                    case 0x32: 
+                        robot.speed = 0.5; 
+                        pc.printf("2"); 
+                        break; 
+                          
+                    case 0x33:  
+                        robot.speed = 0.25; 
+                        pc.printf("3"); 
+                        break; 
+                          
+                    case 0x77: 
+                        robot.FW(); 
+                        pc.printf("w"); 
+                        break; 
+                      
+                    case 0x73: 
+                        robot.BW(); 
+                        pc.printf("s"); 
+                        break; 
+                          
+                    case 0x61: 
+                        robot.left();  
+                        pc.printf("a"); 
+                        break; 
+                          
+                    case 0x64: 
+                        robot.right(); 
+                        pc.printf("d"); 
+                        break; 
+                        
+                    case 'n':
+                        robot.open();
+                        pc.printf("n");
+                        break;
+                        
+                        case 'm':
+                        robot.close();
+                        pc.printf("m");
+                        break;
+                        
+                        case 'h':
+                        robot.hejs();
+                        pc.printf("h");
+                        break;
+                        
+                        case 'b':
+                        robot.saenk();
+                        pc.printf("b");
+                        break;
+                      
+                    default : 
+                        robot.stop(); 
+                        break; 
+                    } 
+                } 
+    }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Apr 05 09:30:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7d30d6019079
\ No newline at end of file