-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
130 lines (115 loc) · 4.42 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* lab6-interrupt_template.c
*
* Template file for CprE 288 Lab 6
*
* @author Diane Rover, 2/15/2020
*
*/
#include "uart-interrupt.h"
#include "driverlib/interrupt.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include "Scanner.h"
#include "Timer.h"
#include <inc/tm4c123gh6pm.h>
#include "lcd.h"
#include "open_interface.h"
#include "movement.h"
#include "objects.h"
#include "adc.h"
#include "servo.h"
#include "ping.h"
int main(void)
{
// Initialize various components and sensors
timer_init(); // Initialize timer
oi_t *sensor_data = oi_alloc(); // Allocate memory for sensor data
oi_init(sensor_data); // Initialize the sensor data
lcd_init(); // Initialize LCD display
adc_init(); // Initialize analog-to-digital converter
uart_interrupt_init(); // Initialize UART interrupt
servo_init(); // Initialize servo motor
ping_init(); // Initialize ultrasonic sensor
// Variables for tracking distance moved and angle turned
float distanceMoved;
float angleTurned;
while (1)
{
distanceMoved = 0; // Reset distanceMoved to 0
angleTurned = 0; // Reset angleTurned to 0
// Check if a flag has been set to move forward
if (flag_m)
{
distanceMoved = move_forward(sensor_data, 100); // Move forward 100 units
char returnString[20];
sprintf(returnString, "D0!%f", distanceMoved); // Format a string with the distance moved
uart_sendStr(returnString); // Send the string over UART
flag_m = false; // Reset the flag
}
// Check if a flag has been set to turn left at 90 degrees
if (flag_1)
{
angleTurned = turn_left(sensor_data, 90); // Turn left 90 degrees
char returnString[20];
sprintf(returnString, "D%f!0", angleTurned); // Format a string with the angle turned
uart_sendStr(returnString); // Send the string over UART
flag_1 = false; // Reset the flag
}
// Check if a flag has been set to turn left at 45 degrees
if (flag_2)
{
angleTurned = turn_left(sensor_data, 45); // Turn left 45 degrees
char returnString[20];
sprintf(returnString, "D%f!0", angleTurned); // Format a string with the angle turned
uart_sendStr(returnString); // Send the string over UART
flag_2 = false; // Reset the flag
}
// Check if a flag has been set to turn left at 15 degrees
if (flag_3)
{
angleTurned = turn_left(sensor_data, 15); // Turn left 15 degrees
char returnString[20];
sprintf(returnString, "D%f!0", angleTurned); // Format a string with the angle turned
uart_sendStr(returnString); // Send the string over UART
flag_3 = false; // Reset the flag
}
// Check if a flag has been set to perform an IR scan
if (flag_s)
{
scannerIR(); // Perform an IR scan
identifyObjects(rawVal); // Identify objects in the scan
}
// Check if a flag has been set to turn right 15 degrees
if (flag_4)
{
angleTurned = turn_right(sensor_data, 15); // Turn right 15 degrees
char returnString[20];
sprintf(returnString, "D%f!0", angleTurned); // Format a string with the angle returned
uart_sendStr(returnString); //Send the string over UART
flag_4 = false; // Reset the flag
}
// Check if a flag has been set to turn right 45 degrees
if (flag_5)
{
angleTurned = turn_right(sensor_data, 45); // Turn right 45 degrees
char returnString[20];
sprintf(returnString, "D%f!0", angleTurned); // Format a string with the angle returned
uart_sendStr(returnString); // Send the string over UART
flag_5 = false; // Reset the string
}
//Check if a flag has been set to turn right 90 degrees
if (flag_6)
{
angleTurned = turn_right(sensor_data, 90); // Turn right 90 degrees
char returnString[20];
sprintf(returnString, "D%f!0", angleTurned); // Format a string with the angle returned
uart_sendStr(returnString); // Send the string over UART
flag_6 = false; // Reset the flag
}
}
}