Commit a39a302 1 parent ea12fd6 commit a39a302 Copy full SHA for a39a302
File tree 6 files changed +71
-6
lines changed
Steering/Firmware/Steering_Controller/Steering_Controller/Steering_Controller
6 files changed +71
-6
lines changed Original file line number Diff line number Diff line change 12
12
#include <avr/io.h>
13
13
#include <stdint.h>
14
14
#include <avr/interrupt.h>
15
+ #include <stdbool.h>
15
16
16
17
// Global Variables
17
18
#define F_CPU 8000000UL
Original file line number Diff line number Diff line change @@ -35,13 +35,18 @@ int main(void)
35
35
timer2_init ();
36
36
adc_init ();
37
37
38
+ // Sets up PI Controller K values
38
39
pi_setup ();
39
40
40
- calibrate_steering ();
41
+ // Reads and sets up voltage reference values used for steering (Disabled for Proteus)
42
+ //calibrate_steering();
41
43
42
- sei ();
44
+ //****(Enabled for Proteus)
45
+ min_val = MAX_LIMIT ;
46
+ max_val = MIN_LIMIT ;
43
47
while (1 ) {
44
-
48
+ //****(Enabled for Proteus)
49
+ calibrate_steering ();
45
50
}
46
51
}
47
52
Original file line number Diff line number Diff line change @@ -37,13 +37,13 @@ void pi_controller(){
37
37
// Sets the duty cycle on IN_1 or IN_2
38
38
if (set_output > 0 ){ // Turning Right (positive error)
39
39
IN_1_OFF ;
40
- set_duty_cycle (set_output );
41
40
IN_2_ON ;
41
+ set_duty_cycle (set_output );
42
42
}
43
43
else { // Turning Left (negative error)
44
44
IN_2_OFF ;
45
- set_duty_cycle (set_output * (-1 ));
46
45
IN_1_ON ;
46
+ set_duty_cycle (set_output * (-1 ));
47
47
}
48
48
}
49
49
Original file line number Diff line number Diff line change @@ -39,7 +39,9 @@ void set_duty_cycle(int16_t value){
39
39
// Checks which PWM output is ON
40
40
if (CHECK_IN_1 ){
41
41
OCR0A = t_on ;// Sets Duty Cycle
42
+ OCR1A = 0 ;
42
43
} else if (CHECK_IN_2 ){
44
+ OCR0A = 0 ;
43
45
OCR1A = t_on ;
44
46
}
45
47
}
Original file line number Diff line number Diff line change 8
8
#include "steering.h"
9
9
10
10
// Finds reference voltage values for each angle
11
+ // Works on two assumptions:
12
+ // - Low voltage = Left, High voltage = Right
13
+ // - Input pins to motor are correctly connected
11
14
void calibrate_steering (){
12
- //insert calibration code
15
+ // Sets maximum and minimum voltage ranges (Disabled for Proteus)
16
+ // min_val = MAX_LIMIT;
17
+ // max_val = MIN_LIMIT;
18
+
19
+ IN_1_ON ;
20
+ find_ref ();
21
+ IN_1_OFF ;
22
+
23
+ IN_2_ON ;
24
+ find_ref ();
25
+ IN_2_OFF ;
26
+
27
+ set_reference_values ();
28
+
29
+ //Add straighten wheels function
13
30
}
31
+
32
+ // Reads and sets maximum and minimum values
33
+ void find_ref (){
34
+ set_duty_cycle (MAX_LIMIT );
35
+
36
+ while (calibration_flag == 0 ){
37
+ adc_val = adc_read ();
38
+ if (adc_val < min_val ){
39
+ min_val = adc_val ;
40
+ }
41
+ else if (adc_val > max_val ){
42
+ max_val = adc_val ;
43
+ }
44
+ else {
45
+ calibration_flag = 1 ; // If steering motor has turned its maximum angle
46
+ }
47
+ }
48
+ calibration_flag = 0 ; // Clears flag
49
+ }
50
+
51
+ void set_reference_values (){
52
+ full_l_turn = min_val ;
53
+ full_r_turn = max_val ;
54
+
55
+ // Reference voltage for moving straight
56
+ straight_turn = (max_val - min_val )/2 + min_val ;
57
+
58
+ // Reference voltage for half left turn
59
+ half_l_turn = (straight_turn - full_l_turn )/2 + full_l_turn ;
60
+
61
+ // Reference voltage for half right turn
62
+ half_r_turn = (full_r_turn - straight_turn )/2 + straight_turn ;
63
+ }
Original file line number Diff line number Diff line change 11
11
12
12
#include "global.h"
13
13
#include "adc.h"
14
+ #include "pwm.h"
14
15
#include "led.h"
15
16
16
17
void calibrate_steering ();
18
+ void find_ref ();
19
+ void set_reference_values ();
20
+
21
+ volatile uint16_t min_val ;
22
+ volatile uint16_t max_val ;
23
+ volatile uint8_t calibration_flag ;
17
24
18
25
#endif /* STEERING_H_ */
You can’t perform that action at this time.
0 commit comments