Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. /*
  2. * Test.c
  3. *
  4. * Created on: Apr 18, 2018
  5. * Author: cabarnes
  6. */
  7.  
  8. /*
  9. * main.c
  10. */
  11.  
  12. #include "SERVO.h"
  13. #include "timer.h"
  14. #include "uart.h"
  15. #include "lcd.h"
  16. #include "ir.h"
  17. #include "math.h"
  18. #include "Sonar.h"
  19. #include "button.h"
  20. #include <stdbool.h>
  21. #include "driverlib/interrupt.h"
  22. #include <inc/tm4c123gh6pm.h>
  23. #include "advancedmovement.h"
  24. #include "scan.h"
  25.  
  26.  
  27. /*#define TIMER4B_PRESCALER 50
  28.  
  29. volatile unsigned rising_time; // start time of the return pulse
  30. volatile unsigned falling_time; // end time of the return pulse
  31. volatile int flag = 0;
  32. //interrupt for the sonar to capture the rising and falling edge, moved here for compatability issues
  33. void TIMER3B_Handler(void) {
  34. if(TIMER3_RIS_R &= 0x400){
  35. int event_time = TIMER3_TBR_R;
  36. if(flag == 0) {
  37. //rising
  38. rising_time = event_time;
  39. flag = 1;
  40. }
  41. else if(flag == 1) {
  42. //falling
  43. falling_time = event_time;
  44. flag = 2;
  45. }
  46. }
  47. TIMER3_ICR_R |=0x400;
  48. }*/
  49. //Rotates the servo by 2 degrees from 0 to 180 and takes a measurment with the ir and sonar sensors at each increment,
  50. //while doing this it keeps track of the number of objects it detects and their widths,
  51. //when 180 is reached it points to the smallest object
  52. void main(void) {
  53. //initilize the IR sensor, Sonar sensor, Servo, LCD and clock
  54. lcd_init();
  55. servo_timer_init();
  56. uart_init();
  57. adc_init();
  58. timer_init();
  59. sonar_init();
  60. //putty variables
  61. char data1 = 0;
  62. char uartStr[80];
  63. //servo variables
  64. int counter = 7500;
  65. //set the servo to 0 degrees by changing the matcher value
  66. TIMER1_TBMATCHR_R = 0x04E200 - counter;
  67.  
  68. oi_t *sensor_data = oi_alloc();
  69. oi_init(sensor_data);
  70.  
  71. //char password[] = "password";
  72. //WiFi_start(password);
  73.  
  74. int raw = 0;
  75. int deg = 0;
  76. int move_dist = 0;
  77.  
  78. int command = 0;
  79.  
  80. char message[5] = {0,0,0,0,0};
  81. int i = 0;
  82. while(1){
  83. data1 = uart_receive();
  84. //check if enter was pressed, if it was print out the whole string of characters and start a new line in putty
  85.  
  86.  
  87.  
  88. if(data1 == 'S' || data1 == 's'){
  89. lcd_printf("test2");
  90. timer_waitMillis(250);
  91. data1 = 0;
  92. data1 = uart_receive();
  93. lcd_printf("%c fuck", data1);
  94. timer_waitMillis(250);
  95. deg = data1;
  96. scan(raw, deg);
  97. }
  98. }
  99. }
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. // data = uart_receive();
  108. // //check if enter was pressed, if it was print out the whole string of characters and start a new line in putty
  109. // lcd_printf("%c",data);
  110. // timer_waitMillis(250);
  111. // if(data == '\r'){
  112. // uart_sendChar('\r');
  113. // uart_sendChar('\n');
  114. //
  115. // //lcd_printf("%.*s", i, message);
  116. //
  117. // lcd_printf("%c %c %c %c %c",message[0],message[1],message[2],message[3],message[4]);
  118. // timer_waitMillis(250);
  119. // command = 1;
  120. // i = 0;
  121. // data = 0;
  122. // }
  123. // else if(data != 0){ //so it doesn't always set message[i] = 0
  124. // message[i] = data;
  125. // lcd_printf("%c", message[i]);
  126. // timer_waitMillis(250);
  127. // i++;
  128. // data = 0;
  129. // }
  130. //
  131. //
  132. //if(command == 1){
  133. // if(message[0] == 'F' || message[0] == 'f'){
  134. // lcd_printf("test2");
  135. // if(message[2] != 0){
  136. // move_dist = (message[1] * 10) + message[2];
  137. // }
  138. // else{
  139. // move_dist = message[1];
  140. // }
  141. // move_forward(sensor_data, move_dist * 10);
  142. // }
  143. // if(message[0] == 'B' || message[0] == 'b'){
  144. // if(message[2] != 0){
  145. // move_dist = ((message[1] * 10) + message[2]);
  146. // }
  147. // else{
  148. // move_dist = message[1];
  149. // }
  150. // move_backward(sensor_data, move_dist * 10);
  151. // }
  152. // if(message[0] == 'R' || message[0] == 'r'){
  153. // if(message[3] != 0){
  154. // deg = (message[1] * 100) + (message[2] * 10) + message[3];
  155. // }
  156. // else if(message[2] != 0){
  157. // deg = (message[1] * 10) + message[2];
  158. // }
  159. // else{
  160. // deg = message[1];
  161. // }
  162. // turn_clockwise(sensor_data, deg);
  163. // sprintf(uartStr, "%d turn to the right complete", deg);
  164. // uart_sendStr(uartStr);
  165. // }
  166. // if(message[0] == 'L' || message[0] == 'l'){
  167. // if(message[3] != 0){
  168. // deg = (message[1] * 100) + (message[2] * 10) + message[3];
  169. // }
  170. // else if(message[2] != 0){
  171. // deg = (message[1] * 10) + message[2];
  172. // }
  173. // else{
  174. // deg = message[1];
  175. // }
  176. // turn_counterClockwise(sensor_data, deg);
  177. // sprintf(uartStr, "%d turn to the left complete", deg);
  178. // uart_sendStr(uartStr);
  179. // }
  180. // if(message[0] == 'S' || message[0] == 's'){
  181. // if(message[1] == 'R' || message[1] == 'r'){
  182. // raw = 1;
  183. // if(message[4] != 0){
  184. // deg = (message[2] * 100) + (message[3] * 10) + message[4];
  185. // }
  186. // else{
  187. // deg = (message[2] * 10) + message[3];
  188. // }
  189. // scan(raw, deg); // return raw data
  190. // }
  191. // else{
  192. // if(message[3] != 0){
  193. // deg = (message[1] * 100) + (message[2] * 10) + message[3];
  194. // }
  195. // else{
  196. // deg = (message[1] * 10) + message[2];
  197. // }
  198. // scan(raw, deg);//return info about objects
  199. // raw = 0;
  200. // }
  201. // }
  202. // for(i = 0; i < 5; i++){
  203. // message[i] = 0;
  204. // }
  205. // command = 0;
  206. // }
  207. // }
  208. //}
  209. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement