Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include "sra_board.h"
- void left_shift(){
- //implement a logic to blink LEDs in a pattern from right to left.
- }
- void blink_task(void *pvParameters) {
- switch(node_type) {
- case 1: // ONLY LEFT || LEFT+STRAIGHT
- left_shift();
- break;
- case 2: // ONLY RIGHT
- right_sift();
- break;
- case 3: // RIGHT+STRAIGHT
- towards_center();
- break;
- case 4: // DEAD END
- stationary();
- break;
- case 5: // PLUS
- blink();
- break;
- }
- }
- void motor_task(void *pvParameters) {
- uint8_t turn_type = *(uint8_t *)pvParameters;
- switch(turn_type) {
- case 1: // Left turn
- set_motor_speed(motor_a_0, MOTOR_BACKWARD, motor_pwm);
- set_motor_speed(motor_a_1, MOTOR_FORWARD, motor_pwm);
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- break;
- case 2: // Right turn
- set_motor_speed(motor_a_0, MOTOR_FORWARD, motor_pwm);
- set_motor_speed(motor_a_1, MOTOR_BACKWARD, motor_pwm);
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- break;
- case 3: // Straight
- //set_motor_speed------
- break;
- case 4: // U-turn
- //set_motor_speed------
- break;
- }
- vTaskDelete(NULL);
- }
- void process_node_turn(uint8_t node_type, uint8_t turn_type) {
- // Create tasks for LED blinking and motor control movement
- xTaskCreate(blink_task, "blink_task", 4096, &node_type, 1, NULL);
- xTaskCreate(motor_task, "motor_task", 4096, &turn_type, 1, NULL);
- }
- void read_and_process_txt_file(const char *filename) {
- FILE *file = fopen(filename, "r");
- if (file == NULL) {
- printf("Error opening file.\n");
- return;
- }
- char line[100];
- while (fgets(line, sizeof(line), file)) {
- char node[20], turn[20], direction[20];
- sscanf(line, "%s %s %s", node, turn, direction);
- uint8_t node_type, turn_type;
- // Assign node type based on the node description
- if (strcmp(node, "ONLY LEFT") == 0 || strcmp(node, "LEFT+STRAIGHT") == 0)
- node_type = 1; // Node type: ONLY LEFT or LEFT+STRAIGHT
- else if (strcmp(node, "ONLY RIGHT") == 0)
- node_type = 2; // Node type: ONLY RIGHT
- else if (strcmp(node, "RIGHT+STRAIGHT") == 0)
- node_type = 3; // Node type: RIGHT+STRAIGHT
- else if (strcmp(node, "PLUS") == 0)
- node_type = 4; // Node type: PLUS
- else if (strcmp(node, "DEAD END") == 0)
- node_type = 5; // Node type: DEAD END
- else
- node_type = 0; // Invalid node
- // Assign turn type based on the turn description
- if (strcmp(turn, "LEFT") == 0)
- turn_type = 1; // Turn type: LEFT
- else if (strcmp(turn, "RIGHT") == 0)
- turn_type = 2; // Turn type: RIGHT
- else if (strcmp(turn, "STRAIGHT") == 0)
- turn_type = 3; // Turn type: STRAIGHT
- else if (strcmp(turn, "UTURN") == 0)
- turn_type = 4; // Turn type: UTURN
- else
- turn_type = 0; // Invalid turn
- process_node_turn(node_type, turn_type);
- }
- fclose(file);
- }
- void app_main() {
- char filename[100];
- printf("Enter the path to the .txt file: ");
- scanf("%s", filename);
- // Read and process the .txt file
- read_and_process_txt_file(filename);
- }
Advertisement
Add Comment
Please, Sign In to add comment