Hướng dẫn làm robot sumo

Trụ sở chính Miền BắcTầng 5, Tòa nhà Mac Plaza Phường Mộ Lao, Quận Hà Đông, Hà Nội

Trụ sở chính Miền Nam152 Đ. Điện Biên Phủ, Phường 25, Bình Thạnh, Thành phố Hồ Chí Minh

Building a sumo robot and fighting with your friends or colleagues could be fun especially if you can use the company material and resources. I guess that is the fun part working in a robotics company.

There are several categories in Sumo Robot competition with different set of game rules and robot size. In this post, we will be sharing on building an autonomous sumo robot with 20cm x 20cm size. It is a casual project aims to give some tips for the beginners. Don't think we will send it to the real arena.

Components Selection

Since we are free to use the company resources, we will try to use what we have in our store hence some of the components may not be the best choice. You should explore more what is available in the market to give your robot the best performance if they are within your budget.

There are 5 major components in a Sumo Robot.

  1. Controller

Choose the controller that you are familiar with. If you do not have any preference, I would strongly suggest you to go for Arduino simply because we are using the Arduino board and you can use our sample code to start.

Whether you are using Arduino Uno, Mega or Nano, don't forget that you still need a 2-channel motor driver to drive your high power motors and an expansion board to connect all your sensors. You can build your own expansion board and connect all pins to your Arduino with jumpers or get an integrated board from our company where you can connect all electronic parts at one board to eliminate the hassle of wiring.

Main controller + Motor Drivers + Breadboard

  1. Motor

This is one of the most critical part in determining your robot performance. Ideally you want a high speed and high torque motor but the size will be big. You need to ensure your motors are able to fit within the size of 20cm x 20cm (including the wheels!)

There are 2 types of DC motors that you can consider.

Spur Gear & Planetary Gear

The output shaft is parallel to the motor. It is the most common type of geared motor however, the motor length may be limit by the 20cm size limit.

Worm Gear

The output shaft is perpendicular to the motor where you have more room for your robot but the selection is not many.

2-Wheels Drive VS 4-Wheel Drive

4-wheel drive is definitely more powerful in pushing the opponent robot and it has more traction because the wheel's surface touching with the ground is doubled compare to the 2-wheel drive. However, the 4-wheel robot's mobility is not as flexible as 2-wheel robot. Means it is more struggle to make a turn and reduce its agility. Not to forget the cost of the extra motors and wheels.

In this project we are building a 4-wheel drive mechanism that uses 4 x DC motor with 380RPM and 1.4kgfcm torque. To know how to select the right motor, you can read this tutorial we wrote a couple months ago.

3. Wheel

1 / 2 • JSumo Silicon Wheel is among the best choice for Sumo Robot

There are not many options we have in the market for a good wheel for Sumo Robot. The best wheel we can recommend is the silicon wheel manufactured by JSumo but it is a bit pricy. If it is above your budget, you can just go for the toy car's wheel and try to modify it to enhance its friction.

One thing to take note in selecting your wheel is the wheel mounting with DC motor. Make sure the wheel you selected has a hole size that can fit your motor's output shaft. In our case, the geared motor we are using has a 6mm shaft so we need to ensure our wheel comes with a 6mm hole.

4. Sensor

We need 2 type of sensors in the autonomous sumo robot.

Object Detection Sensor

We can either use infrared sensor or ultrasonic sensor for this task as long as it can sense your opponent robot. Although the sumo ring size is 150cm in diameter, we don't expect our robot to attack the opponent robot when it is standing at the far end of the ring. By the time your robot reach 150cm, the opponent robot may move to another corner.

Based on our observation, 60cm or lesser is the most suitable distance to launch an attack. So you need to ensure your sensor's sensing range is up to 60cm either it is a digital output or analog output.

For our robot, we are using the 3cm-80cm infrared sensor because it is cheap. We use 3 sensors to cover at least 60 degree in the 60cm range and another one sensor at each side.

Edge Detection Sensor

We need the infrared sensor to be mounted at the underneath of the robot to detect the white edge (line) of the sumo ring to avoid dropping off from the ring. You can mount multiple set of edge sensor at the front and at the back depends on your robot moving strategy.

5. Battery

image credit: https://oscarliang.com/lipo-battery-guide/

Usually we use the lithium polymer (Li-Po) battery simply because it can produce relatively more power compare to other battery types at the same size.

Since we are using the 12V DC motor, we will go for the 3 cells, 11.1V Li-Po battery. (1 cell is 3.7V) Don't worry that it doesn't give actual 12V to your motor, the motor still move anyway. One interesting fact about battery is that the voltage output is not constant while you are using. Its actual voltage is usually 10% higher than the voltage labelled i.e. 12.21V when it is fully charged. The actual output voltage will slowly drop to below the nominal voltage (11.1V) while you are using the battery. When the battery voltage drop below the nominal voltage, you need to recharge the battery immediately. Discharge your battery further will cause the battery dies.

image credit: https://oscarliang.com/lipo-battery-guide/

You can refer to this post if you would like to learn more about the Li-Po battery. https://oscarliang.com/lipo-battery-guide/

Design The Robot Chassis

You have 2 options here. Get the ready made robot base that can fit into the size of 20cm x 20cm or build from scratch using either CNC machining, metal bending and welding or 3D print. It depends on your skills and the tools available with you.

1 / 2 • CNC machined robot frame. Image credit: https://www.jsumo.com/

Since 3D printing is more economical and easy to duplicate, we will go for this method and share the 3D files to those who wish to build one at home.

It took us more than 36 hours to print the upper and lower casing

Assembly

Once the chassis is ready, we can assemble the robot before we can program it. The diagram & table below show the overview of the wiring connections for this sumo robot.

The first step I would recommend is to ensure all motors and sensors are soldered with wires or connect with jumper wires so that they can plug to the controller directly.

Most of the DC geared motors come without wire. We need to solder two wires (recommended wire size: 16-18AWG) to the motor's terminal so that we can connect it to the controller.

Note: No need to care about the '+' and '-' supply for a DC motor because it still runs with either polarity but direction of rotation will be reversed.

The sensors have polarity, usually Vcc (+V), Gnd (-V) and signal. Always check the sensor's datasheet before connect them to your controller.

Some of the sensors are labelled, please make sure you connect them correctly.

Once all motors and sensors are soldered with wires, we can start to assemble them to the robot chassis. First, mount the motors on the lower casing with the M3x10 bolts.

Then install the infrared sensors on the right side and left side of the lower casing.

Fasten the wheel's rim using the M4 set screw provided (come together when you purchase the wheel set) and then put on the silicon band.

The set screw need to be fastened at the flat part of the round shaft of the motor.

Next, install the edge sensor at the bottom of the scoop using the self-tapping screw.

You will find 2 holes at the front of the bottom casing. They are for the edge sensors wires to go through before we assemble the scoop.

Assemble the scoop with the lower casing using the M6x20 bolts and nuts.

Next, install the infrared sensors at the front sensor holder before we assemble it to the bottom casing.

Once all sensors and motors are mounted, it is a good practice to label each of the wires to help troubleshooting in the future.

Next, fasten the PCB spacer (25mm length) on the inner plate before we assemble the robot controller on it.

Please check the battery and sensors' polarity carefully before connect to the board. Remember to remove the battery after the correct polarity is verified before proceeding to connect other parts to URC10 board.

Since we are building a 4-wheel drive robot, 2 motors on the same side are to be connected together so that they can be controlled together. We need to squeeze in 2 wires at one port which is a bit difficult. You need to ensure no copper is exposed to avoid it shorts with the wires nearby.

If you want to use our sample code, it will be easier for you if all motors and sensors are connected to the same ports that we are using.

// Wiring Connections.

# define LED0          0   // Onboard LED 0

# define LED1          1   // Onboard LED 1

# define BUTTON        13  // Start button

# define EDGE_L        12  // Left edge sensor

# define EDGE_R        11  // Right edge sensor

# define OPPONENT_L    3   // Left opponent sensor

# define OPPONENT_R    10  // Right opponent sensor

# define OPPONENT_FR   A0  // Front right opponent sensor

# define OPPONENT_FC   A1  // Front center opponent sensor

# define OPPONENT_FL   A2  // Front left opponent sensor

Lastly, connect a 11.1V 1300mAh Li-Po battery before we enclose the upper casing with the self-tapping screw.

Finally, the sumo robot is ready!

Sensor Calibration

There is an important step most beginners may not be aware in setting up a robot - the sensor calibrating, before we can program our robot. Most of the sensors' sensing range is adjustable, we need to ensure the sensors are functioning within the sensing range we want.

Opponent Sensors

The sensor's maximum sensing range is 80cm. But we don't want it to sense anything at the range of 60-80cm, so we to calibrate the sensor so that its maximum sensing range reduced to 60cm.

To do that, we can put our robot facing a white flat surface at a distance of 60cm. Next, we adjust the variable resistor at the back of the sensor until the LED indicator is off, then tune the variable resistor slightly until it is on again. You can move the robot nearer and further to check the sensing range. Repeat the earlier steps until you get the desired result.

Edge Sensors

The edge sensors are mounted at a fixed distance and we want them to be able to differentiate the black and white surface.

The process is a little inconvenient compared to the sensors we did earlier, because they are mounted underneath and being blocked by the black scoop. Before we proceed, please load the sample code of this project. Once you loaded the code, before pressing anything, the program will reflect the sensing signals of both edge sensors to LED D0 and D1. Since the sensors are mounted and covered, we are unable to see the sensor's output signal. The only way is to send the signal of the sensors to LED D0 (right edge sensor) and D1 (left edge sensor).

Our objective is ensure the sensor gives High when it senses the white surface and gives Low when it senses the black surface. (Please observe the LEDs on D0 and D1 in the video below)

You can tune the variable resistor on the sensor using a screw driver via the hollow at the scoop until you get the result you want.

Programming

Since the URC10 Sumo Robot Controller is compatible with Arduino UNO, Arduino IDE will be used for the programming. You can use our sample code for this Sumo robot.

The only library that we're using in our example is the Cytron Motor Drivers Library.

Don't forget to include the header file and initialize the pins for the motor driver.


# include 
  
  
// Configure the motor driver.
CytronMD motorL(PWM_DIR, 5, 4);
CytronMD motorR(PWM_DIR, 6, 7);

To use this library to control the motor, we can simply call the setSpeed function.

// Move forward at full speed.
motorL.setSpeed(255);
motorR.setSpeed(255);
  
// Reverse at 50% speed.
motorL.setSpeed(-128);
motorR.setSpeed(-128);

If the motors move in opposite direction, you can just swap the wires for that motor.

You can refer to URC10's User Manual, if you do not know how to include the motor driver library or upload the sample code.

Game Strategy

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

  • Start Routine
  • Search
  • Attack
  • Back Off

All the functions in this example is implemented as non-blocking function and will get called repeatedly from the main loop.

/*******************************************************************************
  • Main program loop. */ void loop() { // Edge is detected on the left. if (!digitalRead(EDGE_L)) { // Back off and make a U-Turn to the right. backoff(RIGHT); // Toggle the search direction. searchDir = 1; } // Edge is detected on the right. else if (!digitalRead(EDGE_R)) { // Back off and make a U-Turn to the right. backoff(LEFT); // Toggle the search direction. searchDir = 1; } // Edge is not detected. else { // Keep searching if opponent is not detected. if ( digitalRead(OPPONENT_FC) && digitalRead(OPPONENT_FL) && digitalRead(OPPONENT_FR) && digitalRead(OPPONENT_L) && digitalRead(OPPONENT_R) ) { search(); } // Attack if opponent is in view. else { attack(); } } // Stop the robot if the button is pressed. if (!digitalRead(BUTTON)) { // Stop the motors. motorL.setSpeed(0); motorR.setSpeed(0); // Loop forever here. while (1); } } `
Start Routine 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 side way in a predefined "start zone". So, please plan your strategy accordingly. You can even use different strategy 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.
/*

  • Start Routine
  • This function should be called once only when the game start. */

    void startRoutine() { // Start delay. delay(1000);

    // Turn right around 45 degress. motorL.setSpeed(255); motorR.setSpeed(0); delay(180);

    // Go straight. motorL.setSpeed(255); motorR.setSpeed(255); delay(450);

    // Turn left until opponent is detected. motorL.setSpeed(-0); motorR.setSpeed(255); uint32_t startTimestamp = millis(); while (digitalRead(OPPONENT_FC)) {

    // Quit if opponent is not found after timeout.
    if (millis() - startTimestamp > 400) {
      break;
    }
    
    }

    }

    `

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.

/*******************************************************************************
  • Search */ void search() { // Move in circular motion. if (searchDir == LEFT) { motorL.setSpeed(100); motorR.setSpeed(255); } else { motorL.setSpeed(255); motorR.setSpeed(100); } } `
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 5 opponent sensors, the robot will turn into that direction and 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 manage to escape, the program will resume in searching mode.
/*

  • Attack
  • Track and attack the opponent in full speed.
  • Do nothing if opponent is not found. */

    void attack() { uint32_t attackTimestamp = millis(); // Opponent in front center. // Go straight in full speed. if (!digitalRead(OPPONENT_FC)) {

    motorL.setSpeed(255);
    motorR.setSpeed(255);
    
    }

    // Opponent in front left. // Turn left. else if (!digitalRead(OPPONENT_FL)) {

    motorL.setSpeed(0);
    motorR.setSpeed(255);
    
    }

    // Opponent in front right. // Turn right. else if (!digitalRead(OPPONENT_FR)) {

    motorL.setSpeed(255);
    motorR.setSpeed(0);
    
    }

    // Opponent in left side. // Rotate left until opponent is in front. else if (!digitalRead(OPPONENT_L)) {

    motorL.setSpeed(-150);
    motorR.setSpeed(150);
    while (digitalRead(OPPONENT_FC)) {
      // Quit if opponent is not found after timeout.
      if (millis() - attackTimestamp > 400) {
        break;
      }
    }
    
    }

    // Opponent in right side. // Rotate right until opponent is in front. else if (digitalRead(OPPONENT_R) == 0) {

    motorL.setSpeed(150);
    motorR.setSpeed(-150);
    while (digitalRead(OPPONENT_FC)) {
      // Quit if opponent is not found after timeout.
      if (millis() - attackTimestamp > 400) {
        break;
      }
    }
    
    } }

    `

Back Off

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

The last man stays on the ring wins. That's why this function has the highest priority of all functions and is the most important one. We should be ashamed if our robot run out of the ring on its own.

` /*

  • Back Off
  • This function should be called when the ring edge is detected. */

    void backoff(uint8_t dir) { // Stop the motors. motorL.setSpeed(0); motorR.setSpeed(0); delay(100);

    // Reverse. motorL.setSpeed(-255); motorR.setSpeed(-255); delay(200);

    // Stop the motors. motorL.setSpeed(0); motorR.setSpeed(0); delay(100);

    // Rotate.. if (dir == LEFT) {

    motorL.setSpeed(-150);
    motorR.setSpeed(150);
    
    } else {
    motorL.setSpeed(150);
    motorR.setSpeed(-150);
    
    } delay(100);

    // Start looking for opponent. // Timeout after a short period. uint32_t uTurnTimestamp = millis(); while (millis() - uTurnTimestamp < 300) {

    // Opponent is detected if either one of the opponent sensor is triggered.
    if ( !digitalRead(OPPONENT_FC) ||
         !digitalRead(OPPONENT_FL) ||
         !digitalRead(OPPONENT_FR) ||
         !digitalRead(OPPONENT_L) ||
         !digitalRead(OPPONENT_R) ) {
      // Stop the motors.
      motorL.setSpeed(0);
      motorR.setSpeed(0);
      delay(100);
    
      // Return to the main loop and run the attach program.
      return;
    }
    
    }

    // If opponent is not found, move forward and continue searching in the main loop.. motorL.setSpeed(255); motorR.setSpeed(255); delay(200); }

    `

Show Time!

Ok, it's show time! Let's see how our own robots are fighting with each other. Hope you enjoy and beneficial from this tutorial.