Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MotorLib by
Diff: motor.cpp
- Revision:
- 15:88fecbdd191c
- Parent:
- 13:4563244c4071
- Child:
- 16:d818c1a4dafb
diff -r f0667bfc2e98 -r 88fecbdd191c motor.cpp
--- a/motor.cpp Wed Oct 31 14:38:14 2018 +0000
+++ b/motor.cpp Thu Nov 01 15:29:33 2018 +0000
@@ -1,10 +1,10 @@
#include "motor.h"
-void MotStatus::set(motorCommands Acmd, motorDir Adir, int32_t ANSteps) {
+void MotStatus::set(motorCommands aCmd, motorDir aDir, int32_t aNSteps) {
cmd = Acmd;
dir = Adir;
NSteps = NSteps;
-} MotStatus;
+};
Motor::Motor(PinName _MPh[4]) {
initialization( _MPh , MOTOR_STEP_TIME_DEFAULT_US);
@@ -34,7 +34,7 @@
Status.set(MOTOR_nop, CLOCKWISE, 0);// Default command is NOP, clockwise direction, 0 steps
- TickIsAttached = false;
+ Status.TickIsAttached = false;
StepTime_us = aStepTime_us;// duration in micro second for one step
Steps_FullTurn = MOTOR_STEPS_FOR_A_TURN; // Default Calibration value
@@ -110,15 +110,15 @@
StepTime_us = MOTOR_STEP_TIME_MIN_US;
else StepTime_us = aStepTime_us; // or if OK then assign value
// if ticker already running recreate a new ticker;
- if(TickIsAttached) { StopTick(); StartTick(); }
+ if(Status.TickIsAttached) { StopTick(); StartTick(); }
}
void Motor::StartTick() {
- if(!TickIsAttached) {
+ if(!Status.TickIsAttached) {
// Connect Interrupt routine in which the motor and all the state machine is performed
MotorSysTick.attach_us(callback(this, &Motor::ProcessMotorStateMachine), StepTime_us);
// last=tuneTimings.read_us();
- TickIsAttached=true;
+ Status.TickIsAttached=true;
}
}
@@ -126,14 +126,14 @@
{
switch(Status.cmd) {
case MOTOR_run: {
- switch(state) {
+ switch(Status.state) {
case Motor_OFF:
MotorON(); // First only turn on the motor ..
break;
case Motor_ZERO:
case Motor_ON:
- state = MOTOR_RUN;
- case MOTOR_RUN:
+ Status.state = Motor_RUN;
+ case Motor_RUN:
if (Status.NSteps==0) // No more steps to go
{ Status.cmd = MOTOR_stop;
if (_callback) _callback.call(); }
@@ -141,7 +141,7 @@
{ StepOnce();
Status.NSteps--;}
break;
- } // switch(state)
+ } // switch(Status.state)
} // case MOTOR_run
case MOTOR_stop:
StopTick();
@@ -155,8 +155,8 @@
}
void Motor::StopTick() {
- if(TickIsAttached)
- { MotorSysTick.detach(); TickIsAttached=false; }
+ if(Status.TickIsAttached)
+ { MotorSysTick.detach(); Status.TickIsAttached=false; }
}
/*******************************************************
@@ -166,22 +166,22 @@
/** Turn off all motor Phases, no more current flowing */
void Motor::MotorOFF()
{ for (int ph=0; ph<4; ph++) *MPh[ph] = 0;
- state=Motor_OFF;
+ Status.state=Motor_OFF;
}
/** Turn on the motor Phase, In the last used phase, memorized in StepPhases
* Equivalent to what previously the function "void Start();" did */
void Motor::MotorON()
{ SetPhases(); // attention, does not change StepPhase!
- if (StepPhase==0) state=Motor_ZERO;
- else state=Motor_ON;
+ if (StepPhase==0) Status.state=Motor_ZERO;
+ else Status.state=Motor_ON;
}
/** Motor phases turned on and put to Zero Position*/
void Motor::MotorZero() {
StepPhase = 0; // sets the phases to 0
SetPhases();
- state=Motor_ZERO;
+ Status.state=Motor_ZERO;
}
void Motor::StepOnce() // Move the Motor in the used 'direction'
