DESIGN A LINE MAZE ROBOT WITH LEFT-FORWARDING-RIGHT PRIORITY Student: TRAN, KHUONG DUY TRAN, HOANG TUAN Advisor:Dr.. Abstract In the project, we suggested the LFR algorithm, which fi
Introduction
B RIEF DESCRIPTION
Chapter 1: The concept of the line maze robot with Left-Forwarding-Right priority
Chapter 2: We discuss Hardware design, such as: PIC 18F4550, Voltage multiplier circuit, LED Circuit, Button Circuit, Buzzer Circuit
Chapter 3: We discuss Determine sub-routine for the crossroad, storing node information, direction, path-visit, mode, motion control, and the right-forwarding-left algorithm
Chapter 4: We discuss Experimental Results
Chapter 5: We make some conclusions
1.2 The concept of the line maze robot with left-Forwarding-Right priority:
A line maze typically features a black line on a white background, although it can also be a white line on black; this article focuses on black lines on white Each maze has a designated start point and a finish point, with the goal being for the robot to follow the line and reach the finish as quickly as possible Line mazes often contain many dead-end paths, requiring the robot to navigate through incorrect turns before finding the correct route In the example mazes provided, it is evident that the robot must make multiple wrong turns to successfully reach the finish point.
1 The left hand maze has no loops Using the left hand (or right hand) rule will always get you to the end of the maze
Figure 1 A tree-based routing map
2 The right hand maze has several loops
Figure 2 A cyclic-based routing map
At the present time, this paper does not address how to solve the maze below This algorithm may be added at a future date
The robot's core components include comprehensive hardware and firmware with algorithms to ensure optimal performance Its hardware setup features the PIC 18F4550 microcontroller, alongside essential circuits such as the power supply, voltage multiplier, LED display, LCD interface, button controls, buzzer alert system, burning circuit, H-Bridge motor driver, and the CNB1001 light sensor This integrated configuration allows the robot to function effectively across various applications.
This robot is built around the PIC 18F4550 microcontroller, which serves as the core control unit It features an LCD display that shows real-time robot parameters, enhancing user interface and monitoring Equipped with five light sensors, the robot can effectively detect and follow maze lines for accurate navigation The H-Bridge circuit controls two motors, enabling various motion modes essential for maze solving and autonomous movement.
The line maze robot is designed to follow the line based on direction priority, enabling it to determine the shortest path through the maze It performs three runs: first, it navigates from the start to the end point to explore the route; second, it returns from the end point to the start point along the shortest path; and finally, it traverses the shortest path directly from the start to the end point, ensuring efficient navigation through the maze.
In the searching path passage, the robot will follow the line according the direction priority
What is the direction priority? There are two types of direction priorities: Left –Forward-Right (LFR) and Right-Forward-Left (LFR)
LFR: In this paper, we use LFR priority
1.Always prefer a left turn over going straight ahead or taking a right turn
2.Always prefer going straight over going right
If the maze has no loops, this will always get you to the end of the maze
1.Always prefer a right turn over going straight ahead or taking a left turn
2.Always prefer going straight over going left
If the maze has no loops, this will always get you to the end of the maze
There are 8 situations the robot can encounter:
Figure 3 Eight types of robot motion over the crossroad
The robot, most of the time, will be involved in one of the following behaviors:
1.Following the line, looking for the next intersection
2.At an intersection, deciding what type of intersection it is
3.At an intersection, making a turn
These steps continue looping over and over until the robot senses the end of the maze
Robots need to be programmed to recognize and respond appropriately to different types of turns and intersections An intersection is a point where the robot faces multiple directional options, requiring accurate decision-making to navigate effectively Proper training ensures the robot understands the correct behavior to follow at each intersection, enhancing its autonomous navigation capabilities Incorporating these behaviors into the robot’s system is essential for safe and efficient movement in complex environments.
Figure 4 Motions of turn-left and turn-right
In both scenarios, the robot is forced to make a 90-degree turn, which it consistently executes without variation Since the robot's turn is always the same and there are no alternative options, this maneuver does not need to be recorded when solving the maze.
In this scenario, the robot must perform a 180-degree turn (U-turn) to exit a dead-end Recognizing that reaching a dead-end indicates a recent incorrect turn, the robot needs to log this information to prevent revisiting the same dead-end in future runs Proper navigation involves the robot avoiding this dead-end in subsequent attempts and executing a U-turn as the correct response when encountering a dead-end.
Figure 5 Motion of Dead end
In the first run, it goes down some number of dead-ends, and records these as “bad” paths so that they can be avoided on the second run
Next, we will learn how the LFR algorithm works through the following example:
Figure 6 Robot at the starting point
Figure 7 Robot visits the node 1
The robot takes off! At the first intersection, the robot meets a “Straight and Left” intersection The LFR priority requires the robot to turn left and store
Figure 8 Robot visits the node 2
Next, the robot encounters the “Right and Straight” intersection
According the LFR priority, the robot will go straight and store “S” in the memory
Figure 9 Robot visits dead-end
The robot finds that this path is a dead-end, then, makes a U-Turn And
“B” (Back) turn is recorded in the memory
Figure 10 Robot comes back node 2 when meeting dead-end
Then, the robot meets the “Left and Straight” crossroad According the LFR priority, the robot will turn left and store “L” turn in the memory
We recorded “SBL”, but we know (because of the “B”) that we should have not gone down that path
So, our first general rule is: Anywhere the stored path ends with
“Straight-Back-Left” (SBL), we replace it with “Right” (R)
After that, the robot meets the “Right and Straight” crossroad And because of LFR rule, the robot goes straight
Figure 13 Robot visits the node 4
Then, the robot meets the last intersection, a “Straight and Left” In consequence, the robot makes a left turn and record “L” in the memory
Figure 14 Robot found the target
Now, the robot has already defined a shortest path for two next run
Automatic searching robots are versatile tools used across various industries, including factory automation for supplying products efficiently They play a crucial role in monitoring and maintaining city water pump systems via Wi-Fi communication with main factories, ensuring seamless operations Additionally, these robots are essential in hazardous environments such as nuclear facilities and mining sites, where safety and precision are paramount for operations.
A PPLICATION
Automatic searching robots are versatile tools applicable across various industries, including factory automation for seamless product supply They are also essential for monitoring and maintaining water pump systems in urban environments via WiFi communication, ensuring efficient operations Additionally, these robots play a critical role in hazardous construction sites, such as nuclear facilities and mines, where safety and precise navigation are paramount.
Hardware Design
B LOCK DIAGRAM
Note: PIC18F4550 Microchip The introduction of MCU 8 bit
Note: The external frequency is about 24MHz, and the speed of
NOTE: The voltage for the PIC 18F4550 is 2.0V~5.5V。
Figure 17 The voltage multiplier circuit
NOTE: The input voltage is 4.8V amplified to 8.3V to supply for the PWM circuit
NOTE: Initially, the voltage of LED is low voltage Finally, the voltage is changed to high voltage
NOTE: Initially, the voltage of LED is low voltage Finally, the voltage is changed to high voltage
NOTE:The voltage is at high when the button is not yet pushed When the button is pushed, the voltages of RB4,RB5,RB6 are changed to low voltage
NOTE: The proper voltage is generated by the above resistance architecture By doing so, the voltage of the battery can be read.
NOTE:We use the buzzer, which is design inside the chip, to sound the event The operating voltage is form 3V~7V
NOTE:We take J2 component to download the firmware into the robot NOTE: Programming module developed by the Microchip PICkit 2 programmer
NOTE: 1 Using MPLAB IDE v8.53 version of the software features supported by the online programming (PICkit 2)
2.We take PICkit 2 as the interfere to download the firmware
3 We take Mini-USB as the interference to down load the firmware co
NOTE: When the PWM signal including PWMx =0, and DIRx=0; the motor moves forward
NOTE: When the PWM signal including PWMx=0, DIRx=1; the motor moves reverse
Figure 25 CNB1001 light sensor circuit
The ULN2003 IC is designed to reduce power consumption during line maze robot navigation When sensors are inactive, the LED remains off, conserving energy Conversely, the LED turns on to indicate active sensor detection of the line position, ensuring efficient power management and accurate line tracking.
Table 1: List of materials used in the project
Part Type Designator Footprint Description
680uF C2 0603 Capacitor 10uF C3 CASE-B Capacitor 100pF C4 0603 Capacitor
Part Type Designator Footprint Description
BUTTON SW1 SW-PB-SS 6.1*3.6mm
RESET SW2 SW-PB-SS 6.1*3.6mm
BUTTON SW3 SW-PB-SS 6.1*3.6mm
BUTTON SW4 SW-PB-SS 6.1*3.6mm
Mini-USB J1 USB-MINI B Mini-USB
Part Type Designator Footprint Description
BUZZER LS1 BUZZER Buzzer 9*4mm
POWER SW JP1 SWITCH Push button
Left-Forwarding-Right Algorithm
D ESCRIBE THE N OTE SUB - ROUTINE
3.3 Describe Motion Control sub-routine
3.4 The Left-Forwarding-Right algorithm
3.5 An example of the algorithm
3.1 Describe the Determine sub-routine
In the section, we list the illustration in Table 2 and the detailed sub-routine will be shown in appendix 1
Table 2: Illustration of the variable used in the Determine sub-routine
3.2 Describe the Note sub-routine:
The Note sub-routine enables the robot to memorize critical information at each node along its routing path, including line details, motion modes, and car directions This function utilizes arrays such as line_information[], mode_information[], and car_direction to store the respective data, ensuring accurate navigation Comprehensive source code for the Note sub-routine is provided in Appendix 2, with the motion source code detailed in Appendix 3, supporting precise implementation and understanding of the routing process.
3.2.1 Description of the line_formation:
The line_information data structure consists of 8 bits, with the upper 4 bits representing the directions passed by the robot and the lower 4 bits indicating the status of the routing paths By analyzing the lower four bits, the robot can determine the current state of each intersection When the robot visits a routing path, the corresponding lower four bits update from 0 to 1, allowing it to track which paths have been explored Initially, the line_information is set to 0000 0000, indicating no directions have been traveled and no paths visited.
A: shows the direction passed by the robot:
B: helps the robot to define the shape of the routing path:
3.2.2 Description of the mode_formation:
The mode_information data structure consists of 8 bits, where the upper 4 bits indicate the robot's direction, and the lower 4 bits represent its 8 different motion modes This design allows the robot to determine its current movement status by analyzing the lower four bits When the robot switches between motion modes, the lower four bits are updated accordingly, enabling it to accurately monitor its motion state The mode_information can be initialized as mode_information[line_node] = 0000 0000.
B: shows the motion mode of robot:
5: Turn right at the SR intersection
6: Turn left at the LS crossroad
3.2.3 Description of the car_direction:
The variable "car_direction" indicates the direction in which the robot is moving, with specific numerical values representing different directions A value of "1" signifies that the robot is traveling from the East to the West Conversely, "2" indicates movement from the North to the South, "3" from the West to the East, and "4" from the South to the North This coding system helps in accurately determining and controlling the robot's movement direction.
2: From the North to the South
3: From the West to the East
4: From the South to the North
The relative variable declarations are in shown in Table 3 To more detailed information, you may refer the detailed source code of motion sub-routine is shown in Appendix 3
3.4 The Left-Forwarding-Right algorithm:
In our analysis, we utilize the node degree to depict the searching path, considering nodes with a maximum degree of three, excluding the parent connection We model the initial tree T, which includes the root node and its sub-trees T1, T2, and T3 The priority algorithm Left-Forward-Right (LFR) directs the robot to prioritize moving right, then forward, and finally left, as illustrated in Figure 33 Different search algorithms with varying priorities result in diverse search outcomes, highlighting the importance of algorithm selection in navigation efficiency.
Algorithm: Left-Forward- Right Algorithm Input: A robot and the tree-based routing map
Output: A shortest path from source to target
Begin Start from the source;
Let current node is source; while (current node != target) {
Determine the node type at a crossroad;
Update the information of routing paths;
Determine the direction by the priority;
Figure 26 Algorithm for line following maze robot
3.5 An example of the algorithm:
This article illustrates the procedure of the line-following maze robot algorithm using an example in Figure 27 The initial tree starts with only a root node, representing the robot at its starting position When the robot encounters a crossroad, a new node is added to the tree, capturing the available routing options The algorithm then explores the left sub-tree based on its priority—left, forward, then right—visiting nodes accordingly The process involves the robot making forward moves, marking nodes as visited, and backtracking when reaching dead ends This systematic exploration continues through successive sub-trees until the robot reaches the target, with the complete routing tree recorded for optimal path determination.
Figure 27.1 Illustration of the LFR algorithm
Figure 27.2 Illustration of the LFR algorithm
Figure 27.3 Illustration of the LFR algorithm
This section presents fundamental routing map examples used to evaluate hardware circuits, automatic control systems, and the proposed algorithm The primary goal of this study is to develop a robot capable of minimizing search time when identifying the shortest path from a starting point to a designated target Additionally, the routing results vary depending on the robot's initial location within the map, highlighting the importance of efficient path planning.
In order to prevent interference with the placement of optical sensors, the number of tests conducted at each node is based on its degree For example, as shown in Figure 35(c), the robot's location offers three possible routing paths These routing outcomes vary because the robot initially proceeds straight and then determines the next direction at the crossroad based on a predefined priority system.
Figure 28 Illustration of four kinds of node-degree for routing map
To evaluate the effectiveness of the LFR algorithm, various test cases involving different sources and targets were conducted Due to space limitations, the analysis focuses on results where the start point varies while the target remains the same, as shown in Figure 28 In each test case, the robot's routing path from source to target is represented by the red line, demonstrating the paths generated by the robot Although all possible source-target combinations were tested, only in Figure 28(a) did the robot successfully identify the shortest path. -**Sponsor**Looking to optimize your article with SEO-friendly, coherent paragraphs? [Soku AI](https://pollinations.ai/redirect-nexad/Ae4bhgeh?user_id=983577) can help you rewrite and refine your content Trained by Facebook advertising and AI experts, Soku AI understands how to create compelling content based on your article's key points For example, from your text about the LFR algorithm, we can extract that tests with different start points were conducted (Figure 28), the robot successfully found its target and returned to the source in each test-case, but only achieved the shortest path in Figure 28(a) Let Soku AI transform your article into expertly crafted content that drives engagement.
Figure 29 illustrates various car directions, demonstrating how the robot identifies the target and memorizes the shortest path from source to target The search results vary, with the robot successfully locating only the target in different scenarios The robot can find the target and memorize the shortest path when placed at leaf nodes, which have only one routing path Therefore, to effectively define the shortest path, the robot must be positioned at a leaf point in the network.
Figure 29 Illustration of four kinds of node-degree for routing map
The robust design of the robot combined with the powerful LFR algorithm enhances the effectiveness of course materials for student training This integration enables learners to develop practical skills in hardware circuit implementation, control theory, and algorithm concepts As a result, students gain comprehensive hands-on experience that bridges theoretical knowledge and real-world applications, fostering a deeper understanding of robotics and automation technologies.
A N EXAMPLE OF THE ALGORITHM
3.1 Describe the Determine sub-routine
In the section, we list the illustration in Table 2 and the detailed sub-routine will be shown in appendix 1
Table 2: Illustration of the variable used in the Determine sub-routine
3.2 Describe the Note sub-routine:
The Note sub-routine enables the robot to memorize critical routing information at each node along its path, including line details, motion modes, and car directions This functionality is achieved by recording data within the line_information[], mode_information[], and car_direction variables For implementation details, refer to the source code of the Note sub-routine provided in Appendix 2, with the motion source code available in Appendix 3 This structured approach ensures precise navigation and efficient route management for the autonomous robot.
3.2.1 Description of the line_formation:
The line_information data structure utilizes 8 bits, with the upper 4 bits representing the directions passed by the robot and the lower 4 bits indicating the status of the routing paths This design enables the robot to determine the crossroad status based on the lower four bits When the robot visits a routing path, the corresponding lower four bits change from 0 to 1, allowing the robot to track visited routes by checking the bit status For example, the initial state of line_information at a line_node is represented as 0000 0000.
A: shows the direction passed by the robot:
B: helps the robot to define the shape of the routing path:
3.2.2 Description of the mode_formation:
The mode_information data structure consists of 8 bits, with the upper 4 bits dedicated to recording the robot's directions and the lower 4 bits indicating its eight possible motion modes By analyzing the lower four bits, the robot can determine its current motion status When the robot changes its motion mode, the lower four bits are updated accordingly, allowing it to accurately monitor its movement An example of this data structure is mode_information[line_node] = 0000 0000, which reflects the robot's current directional and motion mode settings.
B: shows the motion mode of robot:
5: Turn right at the SR intersection
6: Turn left at the LS crossroad
3.2.3 Description of the car_direction:
The variable “car_direction” indicates the robot’s movement direction, with values ranging from “1” to “4” A value of “1” signifies that the robot moves from the East to the West, while “2” indicates a movement from North to South Similarly, “3” represents a direction from the West to the East, and “4” denotes a movement from South to North.
2: From the North to the South
3: From the West to the East
4: From the South to the North
The relative variable declarations are in shown in Table 3 To more detailed information, you may refer the detailed source code of motion sub-routine is shown in Appendix 3
3.4 The Left-Forwarding-Right algorithm:
We utilize node degree to characterize the search path, considering nodes with a maximum degree of 3, excluding the parent connection The initial tree T comprises a root node and its subtrees T1, T2, and T3 The priority-based search algorithm, Left-Forward-Right (LFR), directs the robot to prioritize right, then forward, and finally left movements, as illustrated in Figure 33 Different algorithms with varied priority orders will produce distinct search outcomes, influencing the efficiency and result of the traversal.
Algorithm: Left-Forward- Right Algorithm Input: A robot and the tree-based routing map
Output: A shortest path from source to target
Begin Start from the source;
Let current node is source; while (current node != target) {
Determine the node type at a crossroad;
Update the information of routing paths;
Determine the direction by the priority;
Figure 26 Algorithm for line following maze robot
3.5 An example of the algorithm:
The article illustrates the procedure of a line-following maze robot algorithm using an example in Figure 27 The robot's position is indicated by the square, while the circle marks the target location Initially, the search tree starts with a single root node, as shown in Figure 27.1 When the robot encounters a crossroad, the tree expands by adding node 1 to represent the branching paths, depicted in Figure 27.2 According to the LFR algorithm's priority—left, forward, then right—the robot explores the left pathway, leading to the creation of a left sub-tree and stopping at node 2, which connects two paths, as shown in Figure 27.3 The robot then proceeds forward, visiting node 3, labeled as visited Since node 3 is a leaf with no further routes, the algorithm backtracks, as illustrated in subsequent figures This process continues through sub-trees shown from Figures 27.5 to 27.7 until the goal is reached and the complete routing path is recorded, demonstrating the step-by-step operation of the maze-solving algorithm.
Figure 27.1 Illustration of the LFR algorithm
Figure 27.2 Illustration of the LFR algorithm
Figure 27.3 Illustration of the LFR algorithm
This article presents basic routing map examples designed to test hardware circuits, automatic control systems, and the effectiveness of the proposed algorithm The primary goal is to develop a robot capable of minimizing search time when identifying the shortest path from the source to a designated target Additionally, the study highlights that the robot's location on the routing map influences the routing results, emphasizing the importance of optimized navigation strategies.
To protect the placement of optical sensors, the number of tests for each node considers its degree For example, as shown in Figure 35(c), the robot has three possible routing paths from the current location These different routing outcomes occur because the robot initially proceeds straight and then selects its next direction at the crossroads based on a predefined priority.
Figure 28 Illustration of four kinds of node-degree for routing map
To evaluate the effectiveness of the LFR algorithm, experiments were conducted using various sources and targets to test the robot's navigation capabilities Due to space limitations, the analysis focuses on results where the target remains constant while the starting point varies, as illustrated in Figure 28 In each test case, the red line represents the robot's routing path from source to target While all possible start and target combinations were tested, only the results in Figure 28(a) show that the robot successfully finds the shortest path.
Figure 29 illustrates various car directions, demonstrating how the robot locates the target and memorizes the shortest path from source to destination The search results vary, but the robot can only successfully find the target when positioned at a leaf node with a single routing path Therefore, placing the robot at a leaf point is essential for accurately defining and memorizing the shortest path in pathfinding applications.
Figure 29 Illustration of four kinds of node-degree for routing map
Leveraging the robustness of the robot and the effectiveness of the LFR algorithm, the course materials are designed to enhance students' understanding of hardware circuit implementation, control theory, and algorithm concepts, ensuring comprehensive practical and theoretical learning.
Experimental results
This paper presents a line-following maze robot integrated with circuits, automatic control systems, and algorithms Implementing this robot enables students to develop skills in hardware design using Protel 99 SE software, understand motor control theory, and learn algorithmic search techniques from source to target.
In the future, line-following maze robots will be enhanced to navigate complex routing maps, including loop line mazes Incorporating graph-based algorithms like minimal spanning tree, Dijkstra's algorithm, and depth-first search into the tutorial will motivate undergraduates to study relevant courses and deepen their understanding of advanced maze-solving techniques.
1 Microchip Technology, Inc “dsPIC30F6010A/6015/4550 datasheet,”
2 J.H Chang, J.H Su, C.Sh Lee, K.E Lin, and G.H Lin, “A Do-It-Yourself Line following Robot for Introductory Automatic Control Courses,” in Proc of 2007 CACS International Automatic
3 Cormen, C E Leiserson, R L Rivest, Introduction to Algorithms, the MIT Press, McGraw-Hill, 1990
4 K H Rosen, Discrete Mathematics and Its Application, McGraw-Hill, Fifth edition, 2003
5 Romỏn Osorio C., Josộ A Romero, Mario Peủa C., and Ismael López-Juárez, “Inteligent Line Follower Mini-Robot System,” in
International Journal of Computers, Communications & Control, pp73-83, 2006
6 Jean-Francois Dupuis and Marc Parizeau, “Evolving a Vision-Based Line-Following Robot Controller” in Proc of the 3rd IEEE Canadian Conference on Computer and Robot Vision, pp.75-75, 2006
7 Skaff, S Kantor, G Maiwand, D Rizzi, A.A., “Inertial Navigation and Visual Line Following for a Dynamical Hexapod Robot,” in Proc of IEEE/RSJ Intelligent Robots and Systems, pp 27-31, 2003
8 N Mohan, T M Undeland, and W P Robbins, Power Electronics – converters, applications, and design, John Wiley & Sons, Inc., 1995
9 http://robot2009.lhu.edu.tw/index.php
APPENDIX 1: Describe the Determine function:
The function of determine sub-routine is to define the shape of the corner, the crossroad, in order to assign the suitable motion mode for each corner or crossroad
Source code: void Determine(void)
The system evaluates ADC values to determine routing paths, specifically checking if certain sensor readings exceed thresholds of 150 or 160 When the ADC values at indices 4, 3, 2, or 1 surpass these thresholds, and the condition for both right and left routing paths is met, or if the LSR_lock is activated, the system recognizes the presence of active routing channels This logic ensures accurate detection of routing paths for efficient system operation.
LSR_lock=1; if(nor_CNB1001_ADCValue[0]>160)
LSR_lock=0; //set the variable if(nor_CNB1001_ADCValue[3]>200||nor_CNB1001_ADCValue[2]>2 00||nor_CNB1001_ADCValue[1]>200)
LSR_lock=0; //set the variable if(nor_CNB1001_ADCValue[3]>200||nor_CNB1001_ADCValue[2]>2 00||nor_CNB1001_ADCValue[1]>200)
} } } if(nor_CNB1001_ADCValue[4]>170&&nor_CNB1001_ADCValue[3]>21 0&&nor_CNB1001_ADCValue[2]>210&&nor_CNB1001_ADCValue[1]>
{ goal_count++; if(goal_count == 18)
{ goal_count=0; //set the variable
LSR_lock=0; //set the variable goal=1; // set the variable when we find the goal
{ if(goal==1) { goal=0; mode=7; // we find the goal note_mode = 1; note_LSR = 7;
Determine_lock = 1; // Determine_lock=1 do not go the subroutine find_goal = 1;
{ mode=4; note_mode = 1; // note_mode=1 to run sub-routine, otherwise do not run sub-routine note_LSR=1;
{ mode=3; note_mode = 1; // note_mode=1, we run the sub-routine, otherwise we do no run the sub-routine note_LSR=2;
{ mode=6; note_mode = 1; // note_mode=1, we run the sub-routine, otherwise we do no run the sub-routine note_LSR=3;
{ mode=1; note_mode = 1; // note_mode=1, we run the sub-routine, otherwise we do no run the sub-routine note_LSR=4;
{ mode=4; note_mode = 1; // note_mode=1, we run the sub-routine, otherwise we do no run the sub-routine note_LSR=5;
{ mode=6; // note_mode = 1; // note_mode=1 we run the sub-routine, otherwise we do no run the sub-routine note_LSR=6;
} else if(nor_CNB1001_ADCValue[4]160||nor_CNB1001_ADCValue[2]>160||no r_CNB1001_ADCValue[1]>160)) || LSR_lock==1 )// no routing paths { noline=0; mode=0;
LSR_lock=1; if(nor_CNB1001_ADCValue[0]>160)
LSR_lock=0; //set variable if(nor_CNB1001_ADCValue[3]>200||nor_CNB1001_ADCValue[2]>2 00||nor_CNB1001_ADCValue[1]>200)
LSR_lock=0; // set variable if(nor_CNB1001_ADCValue[3]>200||nor_CNB1001_ADCValue[2]>2 00||nor_CNB1001_ADCValue[1]>200)
} } else if(nor_CNB1001_ADCValue[4]160||nor_CNB1001_ADCValue[2]>160||no r_CNB1001_ADCValue[1]>160)) || LSR_lock==1 )// there are two routing paths
LSR_lock=1; if(nor_CNB1001_ADCValue[0]>160)
LSR_lock=0; //set variable if(nor_CNB1001_ADCValue[3]>200||nor_CNB1001_ADCValue[2]>2 00||nor_CNB1001_ADCValue[1]>200)
LSR_lock=0; //set variable if(nor_CNB1001_ADCValue[3]>200||nor_CNB1001_ADCValue[2]>2 00||nor_CNB1001_ADCValue[1]>200)
{ noline=0; mode=1; //mode type is to follow the road note_mode = 0;
APPENDIX 2: describe the note function
The note function is designed to record node information and routing paths, serving as a crucial component for efficient motion control However, reading its sub-routine can be complex due to the need to insert and delete nodes within the data structure dynamically Additionally, this information is continuously updated in real-time as the robot searches for a target and calculates the shortest path from source to destination, ensuring optimal navigation performance.
Source code: void note(void)
{ if(note_IF == 0){ if(note_mode == 1){ line_node++; switch(car_direction){ case 1: // -From West to East - if(note_LSR == 1){ // -"┐
" - line_information[line_node] line_information[line_node]|0x4C;
} else if(note_LSR == 2){ // - "┌" - line_information[line_node] line_information[line_node]|0x46;
} else if(note_LSR == 3){ // - "┤" - line_information[line_node] line_information[line_node]|0x4D; else if(note_LSR == 4){ // - "├" - line_information[line_node] line_information[line_node]|0x47;
" - line_information[line_node] line_information[line_node]|0x4E;
} else if(note_LSR =6){// -"┼" - line_information[line_node] line_information[line_node]|0x4F;
} else if(note_LSR == 7) // stop
{ line_information[line_node] line_information[line_node]|0x44;
This article explains the implementation of a switch-case structure to control vehicle modes based on sensor inputs The system manages various driving modes, including forward movement, line following, U-turns, and turning left or right Specific mode codes (e.g., 0x00, 0x11, 0x12) are assigned to each mode, and corresponding vehicle directions are set accordingly, such as moving forward, turning left or right, or performing a U-turn Additionally, line information is modified with bitwise operations to indicate specific navigation signals, enhancing the vehicle's ability to interpret intersection symbols and complex route patterns This structured approach ensures precise control and navigation for autonomous vehicle systems.
} break; case 2: // - From North to
" - line_information[line_node] line_information[line_node]|0x89;
-"┌" - line_information[line_node] line_information[line_node]|0x8C;
" - line_information[line_node] line_information[line_node]|0x8B;
} else if(note_LSR == 4){ // - "├" - line_information[line_node] line_information[line_node]|0x8E;
} else if(note_LSR == 5){ // - "┬" - line_information[line_node] line_information[line_node]|0x8D;
" - line_information[line_node] line_information[line_node]|0x8F;
} else if(note_LSR == 7) // stopping
{ line_information[line_node] line_information[line_node]|0x44;
This code segment outlines various driving modes based on line detection When in forward mode, the system sets the mode information to 0x00 and the vehicle direction to 2, indicating straight movement To follow the line, it updates mode information to 0x21, maintains the direction at 2, and activates line following with specific flags For U-turn maneuvers, the mode is set to 0x22 with a direction of 4, preparing the vehicle to turn around Right turn commands update the mode to 0x23, set the direction to 3, and modify line information flags to execute a turn to the right safely.
// -Turn left - mode_information[line_node] = 0x24; car_direction = 1; line_information[line_node] line_information[line_node]|0x10; break; case 5:
// - "├ ┼" - mode_information[line_node] = 0x25; car_direction = 3; line_information[line_node] line_information[line_node]|0x40; break; case 6: //
-"┤ ┼" - mode_information[line_node] = 0x26; car_direction = 1; line_information[line_node] line_information[line_node]|0x10; break; case 7: //stopping mode_information[line_node] = 0x27; car_direction = 2; break;
} break; case 3: // - From East to
┐" - line_information[line_node] line_information[line_node]|0x13;
} else if(note_LSR == 2){ // -"┌" - line_information[line_node] line_information[line_node]|0x19;
} else if(note_LSR == 3){ // -"┤" - line_information[line_node] line_information[line_node]|0x17;
├" - line_information[line_node] line_information[line_node]|0x1D;
┬" - line_information[line_node] line_information[line_node]|0x1B; else if(note_LSR == 6){ // - "┼" - line_information[line_node] line_information[line_node]|0x1F;
} else if(note_LSR == 7) //stopping
{ line_information[line_node] line_information[line_node]|0x44;
} switch (mode) { case 0: // Forward mode_information[line_node] = 0x00; car_direction = 3; break; case 1: //
-Forward, follow the line - mode_information[line_node] = 0x31; car_direction = 3; line_information[line_node] line_information[line_node]|0x40; break; case 2: //
-U turn - mode_information[line_node] = 0x32; car_direction = 1; break; case 3:
// -Turn right - mode_information[line_node] = 0x33; car_direction = 4; line_information[line_node] line_information[line_node]|0x80; break; case 4: //
-Turn left - mode_information[line_node] = 0x34; car_direction = 2; line_information[line_node] line_information[line_node]|0x20; break; case 5: //
-"├ ┼" - mode_information[line_node] = 0x35; car_direction = 4; line_information[line_node] line_information[line_node]|0x80; break; case 6: //
-"┤ ┼" - mode_information[line_node] = 0x36; car_direction = 2; line_information[line_node] line_information[line_node]|0x20; break; case 7: // stopping mode_information[line_node] = 0x37; car_direction = 3;
} break; case 4: // - From South to North - if(note_LSR == 1){ // -"┐" - line_information[line_node] line_information[line_node]|0x26;
} else if(note_LSR == 2){ // - "┌" - line_information[line_node] line_information[line_node]|0x23;
┤" - line_information[line_node] line_information[line_node]|0x2E;
" - line_information[line_node] line_information[line_node]|0x2B;
} else if(note_LSR == 5){ // -"┬" - line_information[line_node] line_information[line_node]|0x27;
} else if(note_LSR == 6){ // -"┼" - line_information[line_node] line_information[line_node]|0x2F;
{ line_information[line_node] line_information[line_node]|0x44;
// -forward - mode_information[line_node] = 0x00; car_direction = 4; break; case 1:
// -forward, follow the line - mode_information[line_node] = 0x41; car_direction = 4; line_information[line_node] line_information[line_node]|0x80; break; case 2: //
-U-turn - mode_information[line_node] = 0x42; car_direction = 2; break; case 3:
// -Turn right - mode_information[line_node] = 0x43; car_direction = 1; line_information[line_node] line_information[line_node]|0x10; break; case 4: //
-Turn left - mode_information[line_node] = 0x44; car_direction = 3; line_information[line_node] line_information[line_node]|0x40; break; case 5: // -"
├ ┼" - mode_information[line_node] = 0x45; car_direction = 1; line_information[line_node] line_information[line_node]|0x10; break; case 6: //
-"┤ ┼" - mode_information[line_node] = 0x46; car_direction = 3; line_information[line_node] line_information[line_node]|0x40; break; case 7: //stopping mode_information[line_node] = 0x47; car_direction = 4;
} } else if(note_mode == 2){ //迴轉 開始回扣節點 switch(car_direction)
{ case 1: car_direction = 3; break; case 2: car_direction = 4; break; case 3: car_direction = 1; break; case 4: car_direction = 2; break;
A = (line_information[line_node] & 0xF0) >> 4 ;
B = (line_information[line_node] & 0x0F) ; if( A == B) //這路口全部路線都走過
{ mode_information[line_node] = 0x00; line_node = line_node - 1; switch(car_direction)//
The provided code snippet demonstrates how different cases assign specific directions to a car based on its current state Certain cases explicitly set the car's direction, such as cases 0 and 1 assigning direction 1, while others like case 2 assign direction 3, highlighting a directional control logic Additionally, some cases, such as case 5 and case 6, include comments indicating particular maneuvers or symbols, which help clarify the intended movement patterns The code also features a nested switch statement within case 2, suggesting a more complex mode-dependent behavior, essential for adaptive vehicle control Implementing clear case handling and descriptive comments enhances the readability and functionality of the navigation logic in programming autonomous or guided vehicles.
The provided code defines various car maneuvers based on different cases When the case is 1, the car moves forward and follows the line, setting the direction to 2 For a U-turn (case 2), the car changes direction to 4 Turning right (case 3) adjusts the car's direction to 3, while turning left (case 4) sets the direction to 1 These instructions facilitate precise vehicle control for different driving scenarios, enhancing autonomous navigation.
- car_direction = 1; break; case 7: //stopping break;
This article outlines various vehicle maneuvers, including moving forward while following a line, performing a U-turn, turning right, and turning left It also describes specific directional commands such as turning right ("┤ ┼") and turning left ("├ ┼"), as well as stopping the vehicle altogether These instructions are essential for programming vehicle navigation and autonomous driving systems, ensuring precise control of car directions for safe and efficient operation.
This code snippet defines vehicle behavior based on different scenarios, with specific directions assigned for each case For instance, when the car is moving forward or following a line, the direction is set to 4 An U-turn is executed by setting the direction to 2, while turning right and left are represented by directions 1 and 3, respectively Additional cases handle specific path symbols, such as "├ ┼" and "┤ ┼," which also correspond to right and left turns When the vehicle stops, the direction is maintained at 4 These directional commands are crucial for controlling vehicle navigation in various driving or autonomous systems.
} } else{ note_IF = 0; switch(car_direction)
This code snippet manages vehicle navigation directions based on different case scenarios For example, it directs the car to move forward when the case is 0 or 1, with additional line information updates for following a line A U-turn is executed when the case is 2 by setting the car direction to 3 Turning right or left is handled in cases 3 and 4, respectively, with corresponding updates to line information through bitwise operations Cases 5 and 6 manage specific directional symbols, setting the car direction and updating line details accordingly Lastly, the stopping scenario in case 7 resets the vehicle to move forward, ensuring smooth and organized vehicle control in various navigation situations.
The code defines various driving instructions based on different cases, such as moving forward, following a line, making a U-turn, turning right or left, and stopping When the car moves forward or follows the line, the car_direction is set to 2, with additional line information updated accordingly For a U-turn, the direction is set to 4; for a right turn, the car_direction is set to 3 with specific line information adjustments Left turns are handled similarly, with car_direction set to 1 and corresponding line data modified Special cases like "├ ┼" and "┤ ┼" involve turning directions with specific bitwise updates to line information Lastly, stopping the vehicle resets the direction to moving forward This structured control logic ensures accurate vehicular responses based on different scenarios.
This code segment defines various driving commands based on different case scenarios, such as moving forward, following a line, executing a U-turn, turning right or left, and stopping For example, when the car moves forward or follows the line, the direction is set to 3, and specific line information bits are updated to reflect the current maneuver Turning right or left involves changing the direction to 4 or 2 respectively, with corresponding line information modifications Additionally, the code handles complex intersection movements represented by symbols like "├ ┼" and "┤ ┼," adjusting the car's direction and line data accordingly The stopping case sets the vehicle's direction back to forward, ensuring safe halting when necessary This logic facilitates precise control and navigation for autonomous vehicles in an obstacle-rich environment.
This code segment defines various car navigation cases, including forward movement, line following, U-turns, and turns to the right or left When the car moves forward or follows a line, the direction is set to 4, with line information updated accordingly For U-turns, the direction switches to 2, while right and left turns update the direction to 1 and 3, respectively, with line information flags set to indicate the turn type The cases also cover specific line patterns like "├ ┼" and "┤ ┼," adjusting direction and line information to navigate complex intersections Finally, the stopping case resets the car's direction to 4 These logic controls facilitate precise vehicle maneuvering and navigation based on different drive scenarios.
//更改 mode_information if(((mode_information[line_node] & 0xF0) >> 4) == 1)
{ if((line_information[line_node] & 0x01) == 0)//沒線
{ case 1: mode_information[line_node] = 0x11; break; case 2: mode_information[line_node] = 0x13; break; case 3: mode_information[line_node] = 0x12; break; case 4: mode_information[line_node] = 0x14; break;
{ case 1: mode_information[line_node] = 0x11; break; case 2: mode_information[line_node] = 0x15; break; case 3: mode_information[line_node] = 0x12; break; case 4: mode_information[line_node] = 0x16; break;
} } } else if(((mode_information[line_node] & 0xF0) >> 4) == 2)
{ if((line_information[line_node] & 0x02) == 0)//沒線
{ case 1: mode_information[line_node] = 0x24; break; case 2: mode_information[line_node] = 0x21; break; case 3: mode_information[line_node] = 0x23; break; case 4: mode_information[line_node] = 0x22; break;
{ case 1: mode_information[line_node] = 0x26; break; case 2: mode_information[line_node] = 0x21; break; case 3: mode_information[line_node] = 0x25; break; case 4: mode_information[line_node] = 0x22; break;
} } } else if(((mode_information[line_node] & 0xF0) >> 4) == 3)
{ if((line_information[line_node] & 0x04) == 0)//沒線
{ case 1: mode_information[line_node] = 0x32; case 2: mode_information[line_node] = 0x34; break; case 3: mode_information[line_node] = 0x31; break; case 4: mode_information[line_node] = 0x33; break;
{ case 1: mode_information[line_node] = 0x32; break; case 2: mode_information[line_node] = 0x36; break; case 3: mode_information[line_node] = 0x31; break; case 4: mode_information[line_node] = 0x35; break;
} } } else if(((mode_information[line_node] & 0xF0) >> 4) == 4)
{ if((line_information[line_node] & 0x08) == 0)//沒線
{ case 1: mode_information[line_node] = 0x43; break; case 2: mode_information[line_node] = 0x42; break; case 3: mode_information[line_node] = 0x44; break; case 4: mode_information[line_node] = 0x41; break;
{ case 1: mode_information[line_node] = 0x45; break; case 2: mode_information[line_node] = 0x42; break; case 3: mode_information[line_node] = 0x46; break; case 4: mode_information[line_node] = 0x41; break;
APPENDIX 3: Describe the Motion Control:
The motion sub-routine is responsible for executing essential robot movements such as forwarding, turning left or right, navigating intersections, rotating, and stopping Once the determine sub-routine identifies the required action, it stores the corresponding motion commands in an array The robot then performs the programmed movement seamlessly, ensuring accurate navigation and control.
LATDbits.LATD0=0; // register with the relative bit
CCPR2L = 20; break; case 1: // follow the line position_calculate( ); // calculate the position
PD_control(); // PD_control sub-routine
{ position_calculate( ); // calculate the position
PD_control_decelerate(); // PD_control_decelerate } else
{ decelerate++; position_calculate( ); // calculate the position
PD_control(); // PD_control sub-routine } break; case 2: //turn-round
LATDbits.LATD3=1; decelerate=0; break; case 3: // turn right
R_turn( ); decelerate=0; break; case 4: // turn left
L_turn( ); decelerate=0; break; case 5: // "├ ┼" SR_turn( );
LATDbits.LATD3=1; decelerate=0; break; case 6: // "┤ ┼"
LATDbits.LATD2=1; decelerate=0; break; case 7: