Welcome to K210 Module repository
3.Recognize left and right sign
Recognize left and right sign
Recognize left and right sign1.Experimental goal2.Experimental principle3.Main source code analysis4.Experimental results
1.Experimental goal
In the first two lessons, we conducted model training on road signs, assembled and wired the car, and completed tracking on the black line. The purpose of this experiment is to recognize the left turn and right turn of road signs with the stm32 car combined with the k210 viewing angle module, and complete the map part of the roundabout
2.Experimental principle
k210 transmits the recognized road sign information to STM32 through the serial port. The position of the stop line at the stm32 car will process the information of the k210 viewing angle module, so as to drive the motor to do the corresponding action.
3.Main source code analysis
x//Right turn priority line patrolvoid Road_sign_right(void){ if((IN_S1 == 0 || IN_S3 == 0) && IN_S2 == 1 && IN_S4 == 1) //go straight { Motion_Set_Pwm(100,0,100,0); if(right_left_flag == 1) { right_left_num++; right_left_flag = 0; } } if(IN_S2 == 0 && IN_S3 == 1 )//Turn left { Motion_Set_Pwm(500,500,-350,-350); if(right_left_flag == 1) { right_left_num++; right_left_flag = 0; } } if(IN_S4 == 0 && IN_S1 == 1 )//Turn right { if(right_left_flag == 1) { right_left_num++; right_left_flag = 0; } } if(IN_S1 == 0 && IN_S3 == 0 && IN_S4 == 0)//1 3 4 is black line turn right ,2 can be ignored { right_left_flag = 1; Motion_Set_Pwm(-550,-550,550,550); delay_ms(200); } if(right_left_num == 2) { //back to normal patrol set_dataid(MAX_id); right_left_flag = 0 ; right_left_num = 0; }
}
//Left turn priority line patrolvoid Road_sign_left(void){ if((IN_S1 == 0 || IN_S3 == 0) && IN_S2 == 1 && IN_S4 == 1) //go straight { Motion_Set_Pwm(100,0,100,0); if(right_left_flag == 1) { right_left_num++; right_left_flag = 0; } } if(IN_S2 == 0 && IN_S3 == 1 )//Turn left { Motion_Set_Pwm(500,500,-350,-350); if(right_left_flag == 1) { right_left_num++; right_left_flag = 0; } } if(IN_S4 == 0 && IN_S1 == 1 )//Turn right { Motion_Set_Pwm(-550,-550,550,550); if(right_left_flag == 1) { right_left_num++; right_left_flag = 0; } } if(IN_S1 == 0 && IN_S2 == 0 && IN_S3 == 0 )//1 2 3 is black line turn left, 4 can be ignored. { right_left_flag = 1; Motion_Set_Pwm(500,500,-350,-350); delay_ms(200); } if(right_left_num == 2) { //back to normal patrol set_dataid(MAX_id); right_left_flag = 0 ; right_left_num = 0; }
}- right_left_flag:Sign to enter the roundabout.
- right_left_num:The number of times the sensors of the 4 line inspection modules in the roundabout recognize the black line at the same time. Generally, the maximum number is 2, entering/exiting the roundabout once. When this number is 2, the state of the roundabout line can be switched back to normal Patrol status. -set_dataid:This function is to switch the motion state of the car. -Road_sign_right:When the k210 viewing angle module recognizes the right turn sign, it will enter this function to inspect the line -Road_sign_left :When the k210 viewing angle module recognizes the turn left sign, it will enter this function to inspect the line
4.Experimental results
Use the serial port burning tool to download the STM32_K210_AI.hex file in the OBJ folder in the stm32 source code provided in this tutorial This series of tutorials only provides the source code of the stm32 car part. If you only need a small part of the functions in it, you can transplant it into the source code.
- When the car recognizes a right turn at the stop line of the roundabout, the car enters the right-turn priority patrol line, and automatically returns to the normal patrol line after exiting the roundabout.
- When the car recognizes a left turn at the stop line of the roundabout, the car enters the patrol line with left turn priority, and automatically returns to the normal patrol line after exiting the roundabout.
