With calibration routine and driving method
Fork of Stepper_Motor_X27168 by
Revision 1:406a6e6c4bd7, committed 2016-03-16
- Comitter:
- yhbyhb4433
- Date:
- Wed Mar 16 18:03:32 2016 +0000
- Parent:
- 0:c346170974bc
- Commit message:
- Improve driving method and add calibration routine
Changed in this revision
StepperMotor_X27168.h | Show annotated file Show diff for this revision Revisions of this file |
Stepper_Motor_X27168.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c346170974bc -r 406a6e6c4bd7 StepperMotor_X27168.h --- a/StepperMotor_X27168.h Tue Oct 20 00:36:06 2015 +0000 +++ b/StepperMotor_X27168.h Wed Mar 16 18:03:32 2016 +0000 @@ -127,6 +127,10 @@ */ void angle_position(float angle); + /** Initialize the motor by rotating CW for full range and CCW for full range + */ + void init(); + private: BusOut motor_control; // 4-bit Bus Controlling the H-Brigde int max_position; // Software Limit to motor rotation
diff -r c346170974bc -r 406a6e6c4bd7 Stepper_Motor_X27168.cpp --- a/Stepper_Motor_X27168.cpp Tue Oct 20 00:36:06 2015 +0000 +++ b/Stepper_Motor_X27168.cpp Wed Mar 16 18:03:32 2016 +0000 @@ -56,18 +56,18 @@ else return -1; - switch (cur_state) { + switch (cur_state) { //improve 2 phase drive method. Original method commented out case 0: - motor_control = 0x1; + motor_control = 0x9;//0x1; break; case 1: - motor_control = 0x4; + motor_control = 0x5;//0x4; break; case 2: - motor_control = 0x2; + motor_control = 0x6;//0x2; break; case 3: - motor_control = 0x8; + motor_control = 0xA;//0x8; break; case 4: motor_control = 0x0; @@ -95,4 +95,15 @@ void StepperMotor_X27168::angle_position(float angle) { step_position(int(angle*2)); +} + +void StepperMotor_X27168::init() +{ + set_speed(400); //if too fast(>400) the motor will slip and go weird + + step_position(MAX_POS); //sweep to MAX position + wait(0.5); + + step_position(0); //sweep to zero position + wait(0.5); } \ No newline at end of file