Skip to content

Commit b4d5f4f

Browse files
committed
keep track of step & ref point in float
1 parent 2c30337 commit b4d5f4f

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

manual_tests/motors_calibration_test/motors_calibration_test.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
void calibration();
1313
void sensor_reading();
1414
void simultaneous();
15+
//slower stronger torque
1516
uint8_t period = 100;
1617
uint8_t times = 12; //shaft rotates exactly one circle with this period and times
17-
uint8_t sum = 0;
18+
double sum = 0.0;
1819
// TO-DO: keeping track of how many "steps" down
1920
uint8_t step = 0;
2021

@@ -31,21 +32,24 @@ uint8_t key_pressed(const uint8_t* buf, uint8_t len) {
3132
switch (buf[0]) {
3233
case 'w':
3334
while (count < 5){
34-
print("cycle %d\n",count+1);
35+
print("cycle %d, step %d\n",count+1, step+1);
3536
calibration();
3637
count += 1;
3738
}
3839
break;
3940
case 's':
4041
while (count < 5){
4142
actuate_motors(period, times, true);
43+
print("Moving up");
4244
count += 1;
45+
step -= 1; //step now underflow here
4346
}
4447
break;
4548
case 'r':
46-
//reset set point
47-
sum = 0;
48-
sensor_reading();
49+
//reset set point and step count
50+
sum = 0.0;
51+
step = 0;
52+
print("System reset\n");
4953
break;
5054
case 't':
5155
for (uint8_t i = 0; i < calibration_channel_num; i++){
@@ -59,7 +63,7 @@ uint8_t key_pressed(const uint8_t* buf, uint8_t len) {
5963
break;
6064
case 'e':
6165
//reset set point
62-
sum = 0;
66+
sensor_reading();
6367
disable_motors();
6468
print("motors disabled\n");
6569
break;
@@ -77,21 +81,27 @@ uint8_t key_pressed(const uint8_t* buf, uint8_t len) {
7781
void calibration(){
7882
print("Actuating: %dms, %d times, going down\n", period, times);
7983
actuate_motors(period, times, false);
84+
step += 1;
8085
sensor_reading();
8186
}
8287

8388
void simultaneous(){
89+
sum = 0.0;
8490
// sum is the set-point
85-
while (sum < 5){
91+
while (sum < 4.3){
92+
//reset after each step
93+
sum = 0.0;
8694
for (uint8_t i = 0; i < calibration_channel_num; i++){
8795
fetch_all_adc_channels(&adc);
8896
uint8_t channel = adc_channels[i];
8997
uint16_t raw_data = read_adc_channel(&adc, channel);
9098
print("Channel %d Raw Data: %d\n", channel, raw_data);
9199
sum += raw_data;
92100
}
93-
sum = sum/2; //implicit typecast here, will look into float more
101+
print("sum: %f\n", sum);
102+
sum = sum/2;
94103
actuate_motors(period,times,false);
104+
step += 1;
95105
}
96106
disable_motors();
97107
print("motors disabled\n");
@@ -105,7 +115,6 @@ void sensor_reading(){
105115
uint16_t raw_data = read_adc_channel(&adc, channel);
106116
double voltage = adc_raw_data_to_raw_vol(raw_data);
107117
print("Raw Data: %d, Voltage: %f V\n", raw_data, voltage);
108-
_delay_ms(1000); // might not be needed
109118
}
110119
}
111120

0 commit comments

Comments
 (0)