Keegan Hu
/
finalwarehouse
ddd
Fork of whouse by
Diff: Stepper_motor.cpp
- Revision:
- 2:ecf401a37aa3
- Parent:
- 1:6bf8f2422228
- Child:
- 3:09f6061e6e5d
diff -r 6bf8f2422228 -r ecf401a37aa3 Stepper_motor.cpp --- a/Stepper_motor.cpp Fri May 11 06:55:13 2018 +0000 +++ b/Stepper_motor.cpp Fri May 11 10:25:12 2018 +0000 @@ -1,4 +1,6 @@ #include "Stepper_motor.h" +#include "mbed.h" +extern Serial Info; /** * [Stepper_motor::Stepper_motor 构造函数 初始化一个步进电机对象] * @param _en [en引脚] @@ -8,15 +10,15 @@ * @param _ratio [减速比] * @param _micorstep [细分数] * @param _dir [初始方向] - * @param _rec [电机的转一圈所需脉冲数(未减速前)] + * @param _rec [步距角] */ Stepper_motor::Stepper_motor(PinName _en,PinName _stepPin,PinName _dirPin,PinName Inter,int _ratio,int _micorstep,int _dir,float _rec):Stepper(_en,_stepPin,_dirPin),InterruptIn(Inter) { ratio = _ratio; microstep = _micorstep; dir = _dir; - Ori_rec = 360.0 / _rec; - pos_dir = 1; + Ori_rec = _rec; + pos_dir = _dir; this->enable(); } /** @@ -50,6 +52,7 @@ dir = pos_dir; } long long int remain = rec * ratio * microstep / Ori_rec; + Info.printf("remain:%d frequency:%d\n",remain, frequency); this->enable(); this->step(dir,frequency,remain);