Experience and partial implementation scheme of the Fifth College Student robot competition in Zhejiang Province

The game is finally over and you can finally have a good sleep. The competition was postponed from April to July, but it didn't affect me in any way to turn the competition into a video game. The total production time before and after may only be a whole week. I'm very satisfied to save three. Let's open a post to the students who will participate in the competition in the future, tell us about this experience and some important points I think.

teammate

Having good teammates is very important. Having two good teammates is half the success. What I do is the supermarket shopping group. Relatively speaking, the better matching is a mechanical one, a letter and electricity one, and a calculation one. It can be considered from the vehicle structure, bottom drive and image recognition. Since there are no students in our group who study mechanics, although we can think of the structure of some cars, if it is very difficult to do it, AutoCAD drawing and modeling software will not be used, and some competitiveness will be lost. The structure of some cars seen at the scene is really shocking.

The relationship between teammates is also good. It's better to be familiar with yourself and communicate more conveniently. The mentality of this game has collapsed for two days. My teammates just corrected my mentality. Thank my teammates very much for this. In short, teammates had better not be those who bring rowing and have no sense of time, otherwise they will be really tired, unless they are big guys and relax.

training field

It can be said that this time it was a big loss for the venue. The starting area of the venue in the school was not painted red, but the actual competition venue became red. When debugging on the field, the line patrol sensor was directly stunned and couldn't even go out of the departure area. The mentality exploded a little. When grabbing the goods, I found that there was still a difference of 2~3cm between the test site in the school and the actual competition site, which directly led to the fact that the manipulator couldn't catch anything at all, and the mentality exploded again. The venue still has to be built in strict accordance with the rules, otherwise it will collapse when it comes to the field. Or the fault tolerance rate of the manipulator program should be high enough to avoid the error caused by site production.

Pre competition preparation

To tell you the truth, there is still plenty of preparation time for the production of this competition. Don't make this competition into a video game like me. You can only sleep for two or three hours a day for several days and nights. Don't put it off until the last few days. Early commissioning, early detection and early resolution of problems. You must prepare more modules to be used, at least completely prepare an additional set. Take as much as you can!!!! Otherwise, you can't change it if you want to. Our broken robot can be said to have changed from the beginning to the end. The next day, the steering gear broke down, borrowed one from the next group, changed and debugged it overnight, burned a piece of steering gear drive board, half an hour before the start of the game, the step-down module was inexplicably burned, the voltmeter could not be found, borrowed one, and quickly replaced a module. It is very necessary to bring one more set.

Hardware

Seriously, hardware is really a penny for a penny. You still have to buy good performance and spend the money, otherwise there will be various module explosions on the field. At the beginning, we used the cheapest L298N for motor drive. At first, it was normal that the weight didn't go up, but after taking the bus, the current of the motor began to increase, and the car was hot after rotating for 30s. Later, I replaced a 70 + drive, which carried a lot of current, and it was not very hot. For transportation confrontation next door, they use two hundred and one piece of drive, and the peak current can reach 200A, which is difficult to burn.

Let's talk about the mechanical arm. Since we have no foundation for mechanical production, we can only think of using the mechanical arm. When you buy it, you must buy one with relatively stable structure!!!!! We removed a mechanical arm from the last car. It can't shake when moving. We sweat every time we catch it. The steering gear had to be brand-new. I wanted to use waste, but later it was all replaced with a new one. The torque must be big enough!!!! https://item.taobao.com/item.htm?spm=a1z09.2.0.0.299e2e8dl9HVl5&id=578661255198&_u=d2jd14b827f9 This store should be relatively cheap on Taobao, and the quality is OK, but I may have blocked the rotation for too long, but I still burned one.

The debugging of the manipulator has always been a very troublesome thing. Originally, I wanted to write the program directly with arduino, but later I felt it was too troublesome. I made a steering gear debugging board and a host computer, which can be adjusted by dragging. It is still more convenient. Nevertheless, the debugging of the manipulator is still very time-consuming. If there is anything that can record the state of the manipulator adjusted by hand, it would be great! (I was thinking about peach)

I saw the 16 way sensor used by many people. I searched the price on the Internet to persuade them to retreat, but it felt too easy to loosen the front with a single piece, and the spacing was not easy to control. During the preliminary preparation, I simply made a six-way and one-way sensor. There are lights in front. I'm no longer afraid of the influence of light. I can drive at night. But this potentiometer seems useless. It can't adjust the sensitivity. It's still considered white in red. Maybe we need to improve this place ourselves. I also open source these two sensors. The website is attached:

https://lceda.cn/wywy/tcrt5000

https://lceda.cn/wywy/tcrt5000-6-lu

The step-down module should also be prepared more. It mainly depends on the size of the current. The current for the steering gear and motor must be large. If it is too small, it will be burned out at once. Be sure to see the positive and negative when wiring!!!! Last time I was dizzy in the laboratory, I was connected reversely. When I was powered on, there were sparks and lightning all the way. 30 yuan was gone. All my partners in the laboratory were stupid. This is also the first capacitor I blew up in so long. My life is complete.... A photo of the buck module is attached.

Finally, I have to say that the Bluetooth module is really easy to use for shunting. All kinds of data can be called back to the mobile phone. There is no need to connect the computer serial port to see the data. It is very convenient. It is connected with the board's TX and RX, and the mobile phone app has data as soon as it is opened. It's very cool. Hc-04 and hc-08 are OK. Push the Bluetooth module for shunting.

Software implementation

Because I only do the underlying control, I can only talk about how the underlying software is implemented. The relatively simple arduino mega2560 is used, with sufficient IO ports and many serial ports, which is completely enough to connect various modules. I will also briefly talk about my realization ideas. The following figure shows that the red color of the departure area was not considered at the beginning, and the scene was changed immediately.

After modification

I only walked a big circle outside, but it's enough to win the prize. If I want to save a lot, I still have to take it in the middle.

Attach all chassis codes of my car:

#define jidianqi 13
#define wheel_left_en 44  
#define wheel_right_en 45 
#define left_wheel_in1 46 
#define left_wheel_in2 47 
#define right_wheel_in3 48 
#define right_wheel_in4 49 
#define qti_left 53 / / Black returns 1
#define qti_right 52
#define f_qti1 38
#define f_qti2 39
#define f_qti3 40
#define f_qti4 41
#define f_qti5 42
#define f_qti6 43
#define b_qti1 32
#define b_qti2 33
#define b_qti3 34
#define b_qti4 35
#define b_qti5 36
#define b_qti6 37

unsigned char action0[5] = {0xFF, 0x09, 0x00, 0x00, 0x00};
unsigned char action1[5] = {0xFF, 0x09, 0x00, 0x01, 0x00};
unsigned char action2[5] = {0xFF, 0x09, 0x00, 0x02, 0x00};
unsigned char action3[5] = {0xFF, 0x09, 0x00, 0x03, 0x00};
unsigned char action4[5] = {0xFF, 0x09, 0x00, 0x04, 0x00};
unsigned char action5[5] = {0xFF, 0x09, 0x00, 0x05, 0x00};
unsigned char action6[5] = {0xFF, 0x09, 0x00, 0x06, 0x00};

unsigned char f_QTIS = 0xff;
unsigned char b_QTIS = 0xff;
unsigned char s_QTIS = 0xff;

int crossing_counts = 0;
byte stop_flag = 0;     //At the intersection stop position, stop = 1 means the vehicle stops, and stop = 0 means the vehicle does not stop

int incomingByte = 0; // for incoming serial data
int result[7] = {};
int count = 0;

void setup() {
  delay(13000);
  car_init();
  motor_motion(80,80);
  delay(2000);
  stop_car();
  start_car();
}
void loop(){
  while(!stop_flag)
    Robot_hunting_judge_crossing();
  if((crossing_counts == 1)||(crossing_counts==2))
  {
    turn_left();
    start_car();
    motor_motion(255,255);
    delay(300);
  }
  else if(crossing_counts==3)
  {
    turn_right();
    start_car();
    motor_motion(255,255);
    delay(300);
  }
  else if((crossing_counts==12)||(crossing_counts==10)||(crossing_counts==11)||(crossing_counts==21)||(crossing_counts==19)||(crossing_counts==20)||(crossing_counts==30)||(crossing_counts==28)||(crossing_counts==29))
  {
    start_car();
    motor_motion(255,255);
    delay(300);
  }
  else if(((crossing_counts>=4)&&(crossing_counts<=8))||((crossing_counts>=13)&&(crossing_counts<=17))||((crossing_counts>=22)&&(crossing_counts<=26))||((crossing_counts>=31)&&(crossing_counts<=35)))
  {
    send_recieve_smd();
    how_carry_things();
    start_car();
    motor_motion(255,255);
    delay(300);
  }
  else if((crossing_counts==9)||(crossing_counts==18)||(crossing_counts==27)||(crossing_counts==36))
  {
    send_recieve_smd();
    how_carry_things();
    turn_right();
    start_car();
    motor_motion(255,255);
    delay(300);
  }
  else if(crossing_counts==37)
  {
    park_car();
  }
  stop_flag = 0;
}

void car_init()           //Initialization of each pin used by the trolley
{
  Serial.begin (115200);
  Serial1.begin (115200);
  Serial3.begin (9600);
  //Initialize each IO, and the mode is OUTPUT mode
  pinMode(jidianqi,OUTPUT);
  digitalWrite(jidianqi,LOW);
  pinMode(wheel_right_en,OUTPUT);
  pinMode(wheel_left_en,OUTPUT);
  pinMode(left_wheel_in1,OUTPUT);
  pinMode(left_wheel_in2,OUTPUT);
  pinMode(right_wheel_in3,OUTPUT);
  pinMode(right_wheel_in4,OUTPUT);
  digitalWrite(wheel_right_en,HIGH); //Feed high level
  digitalWrite(wheel_left_en,HIGH); //Feed high level
  pinMode(f_qti1,INPUT);
  pinMode(f_qti2,INPUT);
  pinMode(f_qti3,INPUT);
  pinMode(f_qti4,INPUT);
  pinMode(f_qti5,INPUT);
  pinMode(f_qti6,INPUT);
  pinMode(b_qti1,INPUT);
  pinMode(b_qti2,INPUT);
  pinMode(b_qti3,INPUT);
  pinMode(b_qti4,INPUT);
  pinMode(b_qti5,INPUT);
  pinMode(b_qti6,INPUT);
  pinMode(qti_left,INPUT);
  pinMode(qti_right,INPUT);
  digitalWrite(left_wheel_in1,HIGH); //Feed high level
  digitalWrite(left_wheel_in2,LOW);  //Feed low level
  digitalWrite(right_wheel_in3,HIGH); //Feed high level
  digitalWrite(right_wheel_in4,LOW);  //Feed low level
  send_arm_action(action0);
}

int f_readqti()       //Read the value of the front QTI
{
  int f_qti,f_q1,f_q2,f_q3,f_q4,f_q5,f_q6;
  f_q1=digitalRead(f_qti1);
  f_q2=digitalRead(f_qti2);
  f_q3=digitalRead(f_qti3);
  f_q4=digitalRead(f_qti4);
  f_q5=digitalRead(f_qti5);
  f_q6=digitalRead(f_qti6);
  f_qti=32*f_q1+16*f_q2+8*f_q3+4*f_q4+2*f_q5+f_q6;
  f_qti=f_qti & 0x3f;
  return f_qti;
}

int b_readqti()      //Read the value of the rear QTI
{
  int b_qti,b_q1,b_q2,b_q3,b_q4,b_q5,b_q6;
  b_q1=digitalRead(b_qti1);
  b_q2=digitalRead(b_qti2);
  b_q3=digitalRead(b_qti3);
  b_q4=digitalRead(b_qti4);
  b_q5=digitalRead(b_qti5);
  b_q6=digitalRead(b_qti6);
  b_qti=32*b_q1+16*b_q2+8*b_q3+4*b_q4+2*b_q5+b_q6;
  b_qti=b_qti & 0x3f;
  return b_qti;
}

int side_readqti()    //Read QTI values on both sides
{
  int s_qti,l_q,r_q;
  l_q=digitalRead(qti_left);
  r_q=digitalRead(qti_right);
  s_qti=2*l_q+r_q;
  s_qti=s_qti & 0x03;
  return s_qti;
}

void Robot_hunting()
{
  f_QTIS = f_readqti();
  switch (f_QTIS)
    {
      case 51:motor_motion(150, 150);break;     //1 110011 1, straight ahead
      case 31:motor_motion(0, 255);break;    //011111, turn left sharply
      case 15:motor_motion(0, 200);break;    //001111, turn left sharply
      case 7:motor_motion(0, 150);break;     //000111, turn left slightly
      case 39:motor_motion(0, 100);break;    //100111, turn left slightly
      case 35:motor_motion(0, 100);break;    //100011, turn left slightly
      case 55:motor_motion(0, 100);break;    //110111, turn left slightly
      case 57:motor_motion(100, 0);break;    //111001, turn right slightly
      case 49:motor_motion(100, 0);break;    //110001, turn right slightly
      case 59:motor_motion(100, 0);break;    //111011, turn slightly right
      case 56:motor_motion(150, 0);break;    //111000, turn right slightly
      case 60:motor_motion(200, 0);break;    //111100, turn right sharply
      case 62:motor_motion(255, 0);break;    //111110, turn right sharply
      default:motor_motion(150, 150);break;
    }
   delay(5);
}

void Robot_hunting_judge_crossing()     //Car patrol and intersection judgment
{
   f_QTIS = f_readqti();
   s_QTIS = side_readqti();
   //Serial.print("f_QTIS=");
   //Serial.println(s_QTIS);
   if(s_QTIS==0){
      stop_car();
      delay(20);
      stop_flag = 1;
      crossing_counts++;
   }
   switch (f_QTIS)
    {
      case 51:motor_motion(80, 80);break;     //1 110011 1, straight ahead
      case 31:motor_motion(0, 255);break;    //011111, turn left sharply
      case 15:motor_motion(0, 200);break;    //001111, turn left sharply
      case 7:motor_motion(0, 150);break;     //000111, turn left slightly
      case 39:motor_motion(0, 100);break;    //100111, turn left slightly
      case 35:motor_motion(0, 100);break;    //100011, turn left slightly
      case 55:motor_motion(0, 100);break;    //110111, turn left slightly
      case 57:motor_motion(100, 0);break;    //111001, turn right slightly
      case 49:motor_motion(100, 0);break;    //110001, turn right slightly
      case 59:motor_motion(100, 0);break;    //111011, turn slightly right
      case 56:motor_motion(150, 0);break;    //111000, turn right slightly
      case 60:motor_motion(200, 0);break;    //111100, turn right sharply
      case 62:motor_motion(255, 0);break;    //111110, turn right sharply
      default:motor_motion(80, 80);break;
    }
   delay(5);
}

void motor_motion(unsigned int left_val, unsigned int right_val)
{
  analogWrite(wheel_right_en,right_val);
  analogWrite(wheel_left_en,left_val);          
}

void turn_right()
{
  digitalWrite(left_wheel_in1,HIGH); //Feed high level
  digitalWrite(left_wheel_in2,LOW);  //Feed low level
  digitalWrite(right_wheel_in3,LOW);
  digitalWrite(right_wheel_in4,HIGH);
  motor_motion(255, 255);
  delay(600);
  while(1){
    f_QTIS = f_readqti();  
    if((f_QTIS == 51)||(f_QTIS == 49)||(f_QTIS == 35)||(f_QTIS == 57)||(f_QTIS == 39))
    {
      stop_car();
      break;
    }  
  }
}


/*
void turn_left()
{
  digitalWrite(left_wheel_in1,LOW); //Feed high level
  digitalWrite(left_wheel_in2,HIGH);  //Feed low level
  digitalWrite(right_wheel_in3,HIGH);
  digitalWrite(right_wheel_in4,LOW);
  motor_motion(255, 255);
  delay(1800);
  stop_car();
}

void turn_right()
{
  digitalWrite(left_wheel_in1,HIGH); //Feed high level
  digitalWrite(left_wheel_in2,LOW);  //Feed low level
  digitalWrite(right_wheel_in3,LOW);
  digitalWrite(right_wheel_in4,HIGH);
  motor_motion(255, 255);
  delay(1800);
  stop_car();
}

*/


void turn_left()
{
  digitalWrite(left_wheel_in1,LOW); //Feed high level
  digitalWrite(left_wheel_in2,HIGH);  //Feed low level
  digitalWrite(right_wheel_in3,HIGH);
  digitalWrite(right_wheel_in4,LOW);
  motor_motion(255, 255);
  delay(600);
  while(1){
    f_QTIS = f_readqti(); 
    //b_QTIS = b_readqti();
    if((f_QTIS == 51)||(f_QTIS == 49)||(f_QTIS == 35)||(f_QTIS == 57)||(f_QTIS == 39))
    {    
      stop_car();
      break;
    }  
  }
}


void stop_car(){
  digitalWrite(left_wheel_in1,LOW); 
  digitalWrite(left_wheel_in2,LOW); 
  digitalWrite(right_wheel_in3,LOW); 
  digitalWrite(right_wheel_in4,LOW);  
}

void start_car()       
{
  digitalWrite(left_wheel_in1,HIGH); //Feed high level
  digitalWrite(left_wheel_in2,LOW);  //Feed low level
  digitalWrite(right_wheel_in3,HIGH); //Feed high level
  digitalWrite(right_wheel_in4,LOW);  //Feed low level 
}

void send_arm_action(unsigned char action[])
{
  for(int i = 0; i < 5; i++)
  {
    Serial3.write(action[i]);
    delay(50);
  }

}

void send_recieve_smd()
{
  delay(1000);
  Serial1.write(49);
  delay(20);
  while(Serial1.read() >= 0){}//Clear the cache to avoid the impact of cached serial port data
  while(incomingByte != 55)
  {
    if (Serial1.available() > 0) {
      // read the incoming byte:
      incomingByte = Serial1.read();
      result[count] = incomingByte;
      count++;
      // say what you got:
      //Serial.print("I received: ");
      //Serial.println(incomingByte, DEC);
    }
  }
  incomingByte = 0;
}

void how_carry_things()
{
  if((count == 1)||(count>7))
    ;
  else
  {
    for(int i = 0; i < (count-1); i++)  
    {
      if(result[i] == 49)
      {
        send_arm_action(action1);
        delay(15000);
      }
      else if(result[i] == 50)
      {
        send_arm_action(action2);
        delay(15000);
      }
      else if(result[i] == 51)
      {
        send_arm_action(action3);
        delay(15000);
      }
      else if(result[i] == 52)
      {
        send_arm_action(action4);
        delay(20000);
      }
      else if(result[i] == 53)
      {
        send_arm_action(action5);
        delay(16000);
      }
      else if(result[i] == 54)
      {
        send_arm_action(action6);
        delay(20000);
      }
      else
        ;
    }
  } 
  count = 0;
}

void park_car()
{
    turn_right();
    digitalWrite(jidianqi,HIGH);
}

In fact, there are not many codes, just 300 lines. In the loop, I've been looking for the intersection, and then judge what to do according to the intersection count. It's very concise, and it's very clear together with the above figure. However, there is a big problem, that is, it's not good to turn according to what I wrote. However, due to the limited time, I don't have any good ideas. In one, because the center of gravity of the car is not completely at the center point, there are more or less problems. I can only rely on the front line patrol sensor to straighten the car body. Serial port 3 is connected to steering gear control board, and serial port 1 is connected to raspberry pie. The shopping cart is pulled by an electromagnet.

Let's write so much for the time being. I'll think of something to add in the future. You are also welcome to communicate in the comment area below, although this is my first robot competition and my last robot competition. I hope everyone can have good luck and good ranking in the competition.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Added by John_S on Fri, 21 Jan 2022 19:04:42 +0200