C++ class for controlling DC motor with encoder feedback. Dependencies include LS7366LIB, MotCon, and PID.
Dependencies: LS7366LIB MotCon2 PID
Diff: Axis.cpp
- Revision:
- 3:71447d4fb4f0
- Parent:
- 2:653433f4ee72
- Child:
- 4:4079f92f9c26
diff -r 653433f4ee72 -r 71447d4fb4f0 Axis.cpp --- a/Axis.cpp Wed Sep 30 16:20:45 2015 +0000 +++ b/Axis.cpp Thu Oct 01 14:55:54 2015 +0000 @@ -3,6 +3,7 @@ #include "LS7366.h" #include "MotCon.h" #include "PID.h" +#define MIN_MOT_COL .06 Axis::Axis(SPI& spi, PinName cs, PinName pwm, PinName dir, PinName analog, int* limit, float totalCnts): _spi(spi), _cs(cs), _pwm(pwm), _dir(dir) , _analog(analog){ _cs = 1; // Initialize chip select as off (high) @@ -33,8 +34,8 @@ moveStatus = 0; //status flag to indicate state of profile movement moveState = 0; //used for state machine in movement profiles debug = 0; - update.attach(this, &Axis::paramUpdate, Tdelay); - axisState = 1; +// update.attach(this, &Axis::paramUpdate, Tdelay); + axisState = 0; pid = new PID(0.0,0.0,0.0,Tdelay); //Kc, Ti, Td, interval ls7366 = new LS7366(spi, cs); //LS7366 encoder interface IC @@ -275,9 +276,9 @@ this->moveProfile.attach(this, &Axis::moveUpdate, this->Tdelay); } -float Axis::readCurrent(void){ - motCurrent = _analog.read() * 3.3; - return motCurrent; +float Axis::readCurrent(void){ + this->motCurrent = this->_analog.read() * 3.3; + return this->motCurrent; } void Axis::axisOff(void){