ทางบริษัทขอเรียนแจ้งให้ทราบว่า จะมีการลดราคาบอร์ด Raspberry Pi ในวันที่ 24 กันยายนนี้ หลังจากที่ธนาคารกลางสหรัฐฯ มีมติลดอัตราดอกเบี้ย โปรดติดตามราคาใหม่เร็วๆนี้!
Sumo Robot Game Strategies

Sumo Robot Game Strategies

PART 3: Game Strategies

 

The program of a sumo robot basically can be divided into 4 parts:

 

  • Start
  • Search
  • Attack
  • Back Off

 

However, these programs cannot work independently and all parts must be combined together in the main program loop.

 

1. Start

 

Start routine is the first movement of the robot after the game start. The strategy for start routine is highly depending on the local rules of the sumo robot competition. Some rules require that the robot only can start moving after 5 seconds, some are 1 second. Some rules allow the robot to be placed anywhere on the ring in any direction. Some require the robot to facing sideway in a predefined "start zone".

 

So, please plan your strategy accordingly. You can even use different strategies from match to match so that your opponent could not pre-program a counter-attack.

In this example, we programmed the robot to go to one side and attack the opponent from side way once the game starts.

 

This is the sample code for Start:

 

void startRoutine() {
  // Start delay.
  delay(1000);
  
  // Turn right around 45 degrees.
  MakerSumo.setMotorSpeed(MOTOR_L, 50);
  MakerSumo.setMotorSpeed(MOTOR_R, 0);
  delay(500);
  
  // Go straight.
  MakerSumo.setMotorSpeed(MOTOR_L, 80);
  MakerSumo.setMotorSpeed(MOTOR_R, 80);
  delay(1500);
  
  // Turn left until opponent is detected.
  MakerSumo.setMotorSpeed(MOTOR_L, 0);
  MakerSumo.setMotorSpeed(MOTOR_R, 50);
  
  unsigned long startTimestamp = millis();
  while (digitalRead(OPP_FC)) {
    // Quit if opponent is not found after timeout.
    if (millis() - startTimestamp > 1000) {
      break;
    }
  }
  
}
 

2. Search

 

As its name suggests, searching is to look for the opponent. In case of the start routine failed to attack the opponent, the robot will go around the ring in circular motion to look for the opponent. Once the opponent robot is detected, this program will be terminated and the robot will get into attack mode.

 

Sample code for Search:

 

void search(int dir) {
  // Move in circular motion.
  if (dir == LEFT) {
    MakerSumo.setMotorSpeed(MOTOR_L, 60);
    MakerSumo.setMotorSpeed(MOTOR_R, 80);
  } else {
    MakerSumo.setMotorSpeed(MOTOR_L, 80);
    MakerSumo.setMotorSpeed(MOTOR_R, 60);
  }
}

 

3.Attack

 

The only way to win the game is to push the opponent robot out of the ring. Once the opponent robot is detected by any of the 3 opponent sensors, the robot will turn into that direction and launch an attack in full speed.

 

The accuracy of the attack depends on how good your robot can track the opponent robot while moving forward in full speed. If the opponent manages to escape, the program will resume in searching mode.

 

void attack() {
  // Opponent in front center.
  // Go straight in full speed.
  if (digitalRead(OPP_FC) == LOW) {
    MakerSumo.setMotorSpeed(MOTOR_L, 255);
    MakerSumo.setMotorSpeed(MOTOR_R, 255);
  }
  
  // Opponent in front left.
  // Turn left.
  else if (digitalRead(OPP_FL) == LOW) {
    MakerSumo.setMotorSpeed(MOTOR_L, 0);
    MakerSumo.setMotorSpeed(MOTOR_R, 255);
  }
  
  // Opponent in front right.
  // Turn right.
  else if (digitalRead(OPP_FR) == LOW) {
    MakerSumo.setMotorSpeed(MOTOR_L, 255);
    MakerSumo.setMotorSpeed(MOTOR_R, 0);
  }
}

 

4. Back Off

 

Whenever any of the edge sensors senses the white line, the robot needs to back off and make a U-Turn. While rotating, the robot will also try to search for the opponent. If the opponent is in its view, it will attack in that direction.

 

void backoff(int dir) {
  // Reverse
  MakerSumo.setMotorSpeed(MOTOR_L, -50);
  MakerSumo.setMotorSpeed(MOTOR_R, -50);
  delay(300);
  
  // Rotate..
  if (dir == LEFT) {
    // Rotate left backward.
    MakerSumo.setMotorSpeed(MOTOR_L, -50);
    MakerSumo.setMotorSpeed(MOTOR_R, 50);
  } else {
    // Rotate right backward.
    MakerSumo.setMotorSpeed(MOTOR_L, 50);
    MakerSumo.setMotorSpeed(MOTOR_R, -50);
  }
  delay(600);
  
  // Stop the motors.
  MakerSumo.setMotorSpeed(MOTOR_L, 0);
  MakerSumo.setMotorSpeed(MOTOR_R, 0);
  delay(50);
}

อุปกรณ์ฮาร์ดแวร์

Ikedo Mini Sumo Robot Pro Kit

THB5,000.00 THB4,672.90

x 1 หน่วย