Mateusz Grzywacz / Yellow2WheeledRobot_motor_shield
Revision:
2:6f6e591f1838
Parent:
1:85961b2af06e
Child:
3:c656543830df
--- a/YellowMotors.h	Wed Feb 03 16:16:33 2016 +0000
+++ b/YellowMotors.h	Thu Feb 04 02:50:06 2016 +0000
@@ -1,4 +1,59 @@
+#ifndef YELLOWMOTORS_H
+#define YELLOWMOTORS_H
 
+#include "mbed.h"
+extern Serial pc;
+extern DigitalIn s1;
 // this is rather strange case, because my motors aren't performing both well. Left one has far weaker, causing delayed start-up and lower RPM. Thus my functions differ. I have a whole bigass spreadsheet of graphs and calculations by the way.
-float motorLinearizationL(float desired);  // left motor is worse. at max desired speed it'll run at full 100% speed. this is thus weaker compensation.
-float motorLinearizationR(float desired);  //  this is stronger compensation for more powerful motor. it runs it at < 100% speed
+
+float motorLinearizationL(float);  // left motor is worse. at max desired speed it'll run at full 100% speed. this is thus weaker compensation.
+float motorLinearizationR(float);  //  this is stronger compensation for more powerful motor. it runs it at < 100% speed
+
+class YellowMotors
+{
+private:
+    DigitalOut _clk;
+    DigitalOut _lat;
+    DigitalOut _dat;
+    DigitalOut _ena; // OE active LOW
+    char _directions;
+    PinName Lpwm;
+    PinName Rpwm;
+public:
+    YellowMotors(PinName clk = D4, PinName  lat = D12, PinName  dat = D8, PinName ena = D7, PinName Lpwm = D11, PinName Rpwm = D3);
+    void setDirections(char); // shift directions to shift register on Adafruit motor shield v1
+    class motorItself  // define a class for separate motors objects.
+    {
+    private:
+        PwmOut _pwmPin;
+        float _pwmSigned; // signed with direction
+    public:
+        int speed;
+        motorItself(PinName pwmPin): _pwmPin(pwmPin) {};  // fuck you, you default constructor.
+        
+        explicit motorItself(float value): _pwmPin(D0) {  // _pwmPin(FUCKYOU) , pwm has no default constructor.. JEEEZ
+            this->_pwmSigned = value; // store this value;
+            //_pwmPin = abs(value); // to be done: apply linearization
+            pc.printf("explicit glupi/n/r");
+        }
+        
+
+        //operator float();
+        void operator= (const float value) {
+            this->_pwmSigned = value; // store this value;
+            this->_pwmPin.write(abs(value)); // to be done: apply linearization
+            pc.printf("jestem w operatorze =. przypisuje %.2f. odczyt: %f\n\r", abs(value), _pwmPin.read());
+        };
+        bool operator== ( float value) {
+            return abs(this->_pwmSigned) == value ;
+        }
+        //float operator= (const motorItself & toreturn) {
+        //    return toreturn._pwmSigned; // return current desired speed with direction indication
+        //};
+    };
+    motorItself L(PinName pin = D8);
+    motorItself R(PinName pin = D11);
+
+};
+
+#endif
\ No newline at end of file