Mateusz Grzywacz / Yellow2WheeledRobot_motor_shield
Committer:
amateusz
Date:
Thu Feb 04 02:50:06 2016 +0000
Revision:
2:6f6e591f1838
Parent:
1:85961b2af06e
Child:
3:c656543830df
So moved it to a class, and sub-class for motors, but something doesn't work.. like it is calling constructor without given argument.. strange. Got to come up with a workaround

Who changed what in which revision?

UserRevisionLine numberNew contents of line
amateusz 2:6f6e591f1838 1 #ifndef YELLOWMOTORS_H
amateusz 2:6f6e591f1838 2 #define YELLOWMOTORS_H
amateusz 0:85e85976c650 3
amateusz 2:6f6e591f1838 4 #include "mbed.h"
amateusz 2:6f6e591f1838 5 extern Serial pc;
amateusz 2:6f6e591f1838 6 extern DigitalIn s1;
amateusz 1:85961b2af06e 7 // 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.
amateusz 2:6f6e591f1838 8
amateusz 2:6f6e591f1838 9 float motorLinearizationL(float); // left motor is worse. at max desired speed it'll run at full 100% speed. this is thus weaker compensation.
amateusz 2:6f6e591f1838 10 float motorLinearizationR(float); // this is stronger compensation for more powerful motor. it runs it at < 100% speed
amateusz 2:6f6e591f1838 11
amateusz 2:6f6e591f1838 12 class YellowMotors
amateusz 2:6f6e591f1838 13 {
amateusz 2:6f6e591f1838 14 private:
amateusz 2:6f6e591f1838 15 DigitalOut _clk;
amateusz 2:6f6e591f1838 16 DigitalOut _lat;
amateusz 2:6f6e591f1838 17 DigitalOut _dat;
amateusz 2:6f6e591f1838 18 DigitalOut _ena; // OE active LOW
amateusz 2:6f6e591f1838 19 char _directions;
amateusz 2:6f6e591f1838 20 PinName Lpwm;
amateusz 2:6f6e591f1838 21 PinName Rpwm;
amateusz 2:6f6e591f1838 22 public:
amateusz 2:6f6e591f1838 23 YellowMotors(PinName clk = D4, PinName lat = D12, PinName dat = D8, PinName ena = D7, PinName Lpwm = D11, PinName Rpwm = D3);
amateusz 2:6f6e591f1838 24 void setDirections(char); // shift directions to shift register on Adafruit motor shield v1
amateusz 2:6f6e591f1838 25 class motorItself // define a class for separate motors objects.
amateusz 2:6f6e591f1838 26 {
amateusz 2:6f6e591f1838 27 private:
amateusz 2:6f6e591f1838 28 PwmOut _pwmPin;
amateusz 2:6f6e591f1838 29 float _pwmSigned; // signed with direction
amateusz 2:6f6e591f1838 30 public:
amateusz 2:6f6e591f1838 31 int speed;
amateusz 2:6f6e591f1838 32 motorItself(PinName pwmPin): _pwmPin(pwmPin) {}; // fuck you, you default constructor.
amateusz 2:6f6e591f1838 33
amateusz 2:6f6e591f1838 34 explicit motorItself(float value): _pwmPin(D0) { // _pwmPin(FUCKYOU) , pwm has no default constructor.. JEEEZ
amateusz 2:6f6e591f1838 35 this->_pwmSigned = value; // store this value;
amateusz 2:6f6e591f1838 36 //_pwmPin = abs(value); // to be done: apply linearization
amateusz 2:6f6e591f1838 37 pc.printf("explicit glupi/n/r");
amateusz 2:6f6e591f1838 38 }
amateusz 2:6f6e591f1838 39
amateusz 2:6f6e591f1838 40
amateusz 2:6f6e591f1838 41 //operator float();
amateusz 2:6f6e591f1838 42 void operator= (const float value) {
amateusz 2:6f6e591f1838 43 this->_pwmSigned = value; // store this value;
amateusz 2:6f6e591f1838 44 this->_pwmPin.write(abs(value)); // to be done: apply linearization
amateusz 2:6f6e591f1838 45 pc.printf("jestem w operatorze =. przypisuje %.2f. odczyt: %f\n\r", abs(value), _pwmPin.read());
amateusz 2:6f6e591f1838 46 };
amateusz 2:6f6e591f1838 47 bool operator== ( float value) {
amateusz 2:6f6e591f1838 48 return abs(this->_pwmSigned) == value ;
amateusz 2:6f6e591f1838 49 }
amateusz 2:6f6e591f1838 50 //float operator= (const motorItself & toreturn) {
amateusz 2:6f6e591f1838 51 // return toreturn._pwmSigned; // return current desired speed with direction indication
amateusz 2:6f6e591f1838 52 //};
amateusz 2:6f6e591f1838 53 };
amateusz 2:6f6e591f1838 54 motorItself L(PinName pin = D8);
amateusz 2:6f6e591f1838 55 motorItself R(PinName pin = D11);
amateusz 2:6f6e591f1838 56
amateusz 2:6f6e591f1838 57 };
amateusz 2:6f6e591f1838 58
amateusz 2:6f6e591f1838 59 #endif