Lab 6 code.
Dependencies: mbed
Fork of WaG by
Diff: stepper.cpp
- Revision:
- 46:85c4b722baa7
- Parent:
- 45:54d18ab80fd1
- Child:
- 48:d612de6880b0
--- a/stepper.cpp Thu Mar 29 20:02:25 2018 +0000 +++ b/stepper.cpp Fri Mar 30 20:25:25 2018 +0000 @@ -53,7 +53,7 @@ jog_ccw.mode(PullUp); cal_button.mode(PullUp); home_sensor.mode(PullUp); - for (int i = 1; i <= NUM_SENSORS; i++) { + for (int i = 1; i <= TGT_SENSOR_QUAN; i++) { //stp_sensor_pos[i] = STP_POS_UNKN; } } @@ -107,7 +107,7 @@ void step_test() { stp_init(); while (uti_chk_ubutton() == 0); - pc.printf("test begin\n"); + pc.printf("step motor test begin\n"); while(1) { if (jog_ccw == 0) { if (stp_cur_pos != 0) { @@ -115,6 +115,10 @@ if (stp_cur_pos != STP_POS_UNKN) stp_cur_pos--; } + else { + pc.printf("Cannot turn past home position.\n"); + wait(0.02); + } } if (jog_cw == 0) { @@ -123,12 +127,16 @@ if (stp_cur_pos != STP_POS_UNKN) stp_cur_pos++; } - else + else { + pc.printf("Cannot turn past maximum position. Fatal error.\n"); while(1); + } } if (cal_button == 0) { stp_find_home(); } + if (uti_chk_ubutton() == 1) + break; } } @@ -152,7 +160,7 @@ for(int i = 0; i < 100; i++) stp_step(STP_CW); if (home_sensor == 0) { - pc.printf("Error, home sensor not functioning. Home sensor is currently %d\n", home_sensor.read()); + pc.printf("Error, home sensor not functioning. Fatal error.\n", home_sensor.read()); while(1); } }