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.
Dependencies: mbed
Fork of Lab_6_WaG by
Diff: stepper.cpp
- Revision:
- 53:389fe53b2642
- Parent:
- 52:8987e38851e5
- Child:
- 54:d5a95bc8ffb0
--- a/stepper.cpp Tue Apr 03 22:32:41 2018 +0000
+++ b/stepper.cpp Thu Apr 05 17:16:40 2018 +0000
@@ -78,9 +78,10 @@
//static int cur_pos = stp_cur_pos;
static int turn[4] = {0x03, 0x06, 0x0c, 0x09};
+ static int index = 0;
if (direction == STP_CW) {
- if (stp_cur_pos <= 200) {
+ if (stp_cur_pos <= 400) {
if (stp_cur_pos != STP_POS_UNKN){
//pc.printf("current position = %d\n", stp_cur_pos);
stp_cur_pos++;
@@ -91,12 +92,12 @@
while(1);
}
-
- for (int i = 0; i < 4; i++) {
- wait(MOTOR_DELAY);
- //pc.printf("i = %d\n", i);
- spi_send(drv8806, turn[i]);
- }
+ if (index == 3)
+ index = 0;
+ else
+ index++;
+ wait(MOTOR_DELAY);
+ spi_send(drv8806, turn[index]);
wait(TURN_DELAY);
}
else if (direction == STP_CCW) {
@@ -111,11 +112,12 @@
return;
}
- for (int i = 3; i >= 0; i--) {
- wait(MOTOR_DELAY);
- //pc.printf("i = %d\n", i);
- spi_send(drv8806, turn[i]);
- }
+ if (index == 0)
+ index = 3;
+ else
+ index--;
+ wait(MOTOR_DELAY);
+ spi_send(drv8806, turn[index]);
wait(TURN_DELAY);
}
wait(MOTOR_DELAY);
@@ -209,8 +211,13 @@
pc.printf("step 9 test begin\n");
int sensor_no = 0;
+ int scanned[8];
+ if (station == STATION_A) sensor_no = 8;
if (station == STATION_B) sensor_no = 8;
+
+ pc.printf("sensor_no: %d\n", sensor_no);
+
// find home position
stp_find_home();
@@ -224,7 +231,7 @@
ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2);
// keep turning stepper motor clock wise until it points to a PT sensor
- while (sensor_values[sensor_no + i] < PTTHRESH) {
+ while (sensor_values[sensor_no + i] * 3.3f < PTTHRESH) {
// turn CW one step
stp_step(STP_CW);
@@ -234,14 +241,15 @@
ana_scan_mux(sensor_values, TGT_SENSOR_QUAN * 2);
for (int j = 0; j < TGT_SENSOR_QUAN; j++) {
- if (sensor_values[sensor_no + j] > PTTHRESH)
- pc.printf("PT %d: %f ", sensor_no + j, sensor_values[sensor_no + j]);
+ if (sensor_values[sensor_no + j] * 3.3f > PTTHRESH) {
+ pc.printf("PT %d: %f\n", sensor_no + j, sensor_values[sensor_no + j] * 3.3f);
+ //scanned[i]++;
+ wait(0.02);
+ }
}
- pc.printf("\n");
}
// found the sensor, save it's position
stp_sensor_pos[i] = stp_cur_pos;
- //pc.printf("Sensor %d = %d\n", i, stp_sensor_pos[i]);
}
// found position of all 8 sensors
