Add dynamic stepper position increasing
Fork of Stepper_Motor_X27168 by
Revision 1:a2c69c36861c, committed 2016-05-02
- Comitter:
- dylanslack
- Date:
- Mon May 02 14:28:23 2016 +0000
- Parent:
- 0:c346170974bc
- Commit message:
- Initial commit
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 |
--- a/StepperMotor_X27168.h Tue Oct 20 00:36:06 2015 +0000 +++ b/StepperMotor_X27168.h Mon May 02 14:28:23 2016 +0000 @@ -127,6 +127,9 @@ */ void angle_position(float angle); + int get_position(); + + void set_position_dynamic(float pos); private: BusOut motor_control; // 4-bit Bus Controlling the H-Brigde int max_position; // Software Limit to motor rotation
--- a/Stepper_Motor_X27168.cpp Tue Oct 20 00:36:06 2015 +0000 +++ b/Stepper_Motor_X27168.cpp Mon May 02 14:28:23 2016 +0000 @@ -95,4 +95,44 @@ void StepperMotor_X27168::angle_position(float angle) { step_position(int(angle*2)); +} + +int StepperMotor_X27168::get_position() { + return cur_position; +} + +void StepperMotor_X27168::set_position_dynamic(float pos){ + if(pos > max_position) + pos = max_position; + else if(pos < 0) + pos = 0; + + + int delta = abs(pos - cur_position); + speed = 100; + int max_speed = 1000; + //set_speed(speed); + + + while(cur_position < pos) { + if(abs(pos - cur_position) > delta/2 && speed < max_speed) + speed +=50; + if(abs(pos - cur_position) <= delta/2&& abs(pos - cur_position) <= 25 && speed >100) + speed -= 50; + + step(0); + } + while(cur_position > pos) { + if(abs(pos - cur_position) > delta/2 && speed < max_speed) + speed +=50; + if(abs(pos - cur_position) <= delta/2 && abs(pos - cur_position) <= 25 && speed >100) + speed -= 50; + + step(1); + } + + step(2); + + + } \ No newline at end of file