Callum and Adel's changes on 12/02/19
Dependencies: Crypto
Diff: main.cpp
- Revision:
- 31:b10ca6cf39bf
- Parent:
- 30:fbae0e5f200d
- Child:
- 32:fc5e00d9f74d
--- a/main.cpp Mon Mar 18 16:24:55 2019 +0000 +++ b/main.cpp Mon Mar 18 17:00:11 2019 +0000 @@ -341,12 +341,11 @@ }; - class Motor { protected: - const int8_t orState; //Rotor offset at motor state 0, motor specific + int8_t orState; //Rotor offset at motor state 0, motor specific volatile int8_t currentState; //Current Rotor State volatile int8_t stateList[6]; //All possible rotor states stored @@ -366,7 +365,7 @@ public: - Motor() : t_motor_ctrl(osPriorityAboveNormal, 1024) + Motor() : t_motor_ctrl(osPriorityAboveNormal, 1024) { // Set Power to maximum to drive motorHome() dutyC = 1; @@ -384,14 +383,15 @@ lead = 2; //2 for forwards, -2 for backwards - stateCount = 0; - - // p_comm = null; // null pointer for now + stateCount[0] = 0; stateCount[1] = 0; stateCount[2] = 0; + theStates[0] = 0; theStates[1] = 0; theStates[2] = 0; + + p_comm = NULL; // null pointer for now } - void motorStart(Comm &comm) { + void motorStart(Comm *comm) { // Establish Photointerrupter Service Routines (auto choose next state) I1.fall(callback(this, &Motor::stateUpdate)); @@ -410,7 +410,9 @@ pwmCtrl.pulsewidth(mtrPeriod*dutyC); // Start motor control thread - t_motor_ctrl.start(callback(this, &Comm::motorCtrlFn)); + t_motor_ctrl.start(callback(this, &Motor::motorCtrlFn)); + + p_comm = comm; } //Set a given drive state @@ -456,17 +458,14 @@ currentState = readRotorState(); // Store into state counter - switch (currentState) { - case 1: + if (currentState == theStates[0]) stateCount[0]++; - break; - case (1 + lead): + else if (currentState == theStates[1]) stateCount[1]++; - break; - case (1 + (lead*2)): + else if (currentState == theStates[2]) stateCount[2]++; - break; - } + + // (Current - Offset + lead + 6) %6 motorOut((currentState - orState + lead + 6) % 6); @@ -477,10 +476,10 @@ // attach_us -> runs funtion every 100ms void motorCtrlFn() { Ticker motorCtrlTicker; - motorCtrlTicker.attach_us(callback(this,&Comm::motorCtrlTick), 1e5); + motorCtrlTicker.attach_us(callback(this,&Motor::motorCtrlTick), 1e5); while (1) { t_motor_ctrl.signal_wait((int32_t)0x1); - pc.printf("B4115"); + p_comm->pc.printf("B4115"); } } @@ -492,6 +491,7 @@ + //Main int main() { @@ -518,6 +518,7 @@ uint32_t hashCounter = 0; Timer timer; + motor.motorStart(&comm_plz); comm_plz.start_comm(); // Motor States