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.
Diff: lin_step_mtr.cpp
- Revision:
- 8:f1d869d9b8df
- Parent:
- 7:0d941d1140ad
- Child:
- 11:2507965c1bec
--- a/lin_step_mtr.cpp Mon Apr 27 17:26:51 2020 +0000
+++ b/lin_step_mtr.cpp Tue Apr 28 20:57:32 2020 +0000
@@ -1,9 +1,8 @@
// Code for the lin_step_mtr driver
#include "lin_step_mtr.h"
-#include "debug.h"
-//Construtor
+//Construtors
LinStepMtr::LinStepMtr(PinName A_f, PinName A_r, PinName B_f, PinName B_r, int m_rpm=MAX_RPM)
:mtr_ctrl(B_r, A_r, B_f,A_f), max_speed((m_rpm > MAX_RPM) ? floor((float)MAX_RPM * 10/3):floor((float)m_rpm * 10/3)),
max_rpm(m_rpm)
@@ -15,8 +14,6 @@
min_rev_cnt = MIN_DOUBLE_VAL;
max_rev_cnt = MAX_DOUBLE_VAL;
-
- pc.printf("Init:\nmin: %f\nmax: %f\n",min_rev_cnt,max_rev_cnt);
}
LinStepMtr::LinStepMtr(PinName A_f, PinName A_r, PinName B_f, PinName B_r)
@@ -28,11 +25,12 @@
cur_step = ONE;
}
+// Destructor
LinStepMtr::~LinStepMtr()
{
}
-
+// Member Functions
float LinStepMtr::get_speed()
{
return (float) speed * 3 / 10;
@@ -53,8 +51,6 @@
min_rev_cnt = MIN_DOUBLE_VAL;
else
min_rev_cnt = rc;
-
- pc.printf("min: %f\n", min_rev_cnt);
}
double LinStepMtr::get_min_rev_cnt()
@@ -68,8 +64,6 @@
max_rev_cnt = MAX_DOUBLE_VAL;
else
max_rev_cnt = rc;
-
- pc.printf("max: %f\n",max_rev_cnt);
}
double LinStepMtr::get_max_rev_cnt()
@@ -83,16 +77,22 @@
min_rev_cnt = MIN_DOUBLE_VAL;
}
-
-
-
-
LinStepMtr::Direction LinStepMtr::get_dir()
{
return dir;
}
-double LinStepMtr::rotate(Direction d, float rev)
+/* NOT SUPPORTED
+LinStepMtr::set_dir(Direction d)
+{
+ if(dir !=d)
+ dir = d;
+}
+*/
+
+// NOTE: uses wait() instead of Thread::wait() because depending on speed, can be
+// waiting for under a millisecond, and Thread::wait() only supports ms
+double LinStepMtr::rotate(Direction d, float rev=1)
{
int steps = floor(200 * rev);
float w = 1/(float)speed;
@@ -123,10 +123,10 @@
return rev_cnt;
}
+/*
#define SPIN_INCR 83 // steps
#define SPIN_WAIT 10 // ms
void LinStepMtr::spin_up(float rpm) {
-/*
int end_speed;
if(rpm == -1) {
@@ -139,11 +139,11 @@
Thread::wait(SPIN_WAIT);
}
speed = end_speed;
-*/
+
}
int LinStepMtr::spin_down(float rpm) {
-/*
+
int end_speed;
int s = speed;
@@ -159,20 +159,14 @@
}
speed = end_speed;
return s;
-*/
+
return -1;
}
+*/
-// Private Step Class functions
-/*
-LinStepMtr::Step::Step() : cur_step(ONE)
-{
- pc.printf("\n\nCalled Constructor\n cur_step: %x\n",cur_step);
-
- pc.printf("Step_Num val:\n ONE = %x\n TWO = %x\n THREE = %x\n FOUR = %x\n\n", ONE, TWO, THREE, FOUR);
-};
-*/
+// Private Class: Step Functions
+
LinStepMtr::Step_Num LinStepMtr::Step::get_cur_step()
{
return cur_step;
@@ -194,7 +188,6 @@
cur_step = ONE;
break;
}
- //pc.printf(" CUR_STEP = %x\n",cur_step);
return cur_step;
}