LEARN.PARALLAX.COM
Published on LEARN.PARALLAX.COM (https://learn.parallax.com)

Home > SumoBot WX Movement Basics

SumoBot WX Movement Basics

What it's about

When facing an opponent in the sumo ring, your SumoBot WX will have to execute a variety of maneuvers.  Examples include:

  • Scanning for an opponent by moving and turning in different directions so the sensors can see as much as possible
  • Detecting the edge of the ring and turning away from it
  • Turning toward and rushing at an opponent to push it out of the ring

Before practicing maneuvers, this tutorial starts with a one-time adjustment to make the SumoBot’s servos stay still when your program tells them to.  The adjustment is called “centering” the servos, and without it, they might turn slowly instead of staying still.  Next, you will write programs to test and verify that each servo responds correctly to blocks that set speed and direction.  
After centering and testing, you will create programs that make the SumoBot perform a variety of maneuvers.  This will provide some good practice since your own custom maneuvers might just give you an edge over your opponent.

Before you start

You will need:

  • A computer with a USB 2.0 compatible port and Chrome browser
  • USB A to micro-B cable
  • A SumoBot WX [1], built up at least through the end of the Build your SumoBot WX pages
  • Parallax Screwdriver
  • 4 AA batteries in the SumoBot WX robot’s battery pack
    • 1.2V Tenergy NiMH rechargeable batteries, recommended for the longest run time
      — or —
    • 1.5 V Alkaline batteries, about 30 minutes run time

After you finish

You will understand how to control the wheel speeds and directions to create maneuvers for forward, backward, and variations on turning that include in-place, pivot, and curve.  You will also be able to adjust maneuver times and speeds to adjust distance traveled and angle turned.  With this, you will be ready to move on to the tutorial where you build, test, and navigate wtih QTIs.  In that tutorial, you will program the SumoBot to cross the sumo ring, detect the edge, and execute a maneuver to turn away from the edge and go in a new direction.

Center the Servos

In this activity, you will run a BlocklyProp program that tells the SumoBot’s servo motors to stay still.  When you load that program into the SumoBot, its servos will probably move slowly.  If that’s the case, you can “center” each servo by adjusting its set screw with a screwdriver to make it stay still.  

When the servos are centered, it will allow your SumoBot to briefly stop moving during competitions.  It will also reduce its tendency to curve in one direction in response to a program that’s telling it to travel in a straight line.  

Over time, motor vibration can cause the servo’s set screw to drift away from the center setting you adjusted.  If that ever happens, just repeat this activity to re-center the servos.

Parts

  • SumoBot, built up at least through the end of the Build your SumoBot WX tutorial [2]
  • USB A to micro-B cable
  • Parallax Screwdriver
  • 4 AA batteries, fresh or freshly recharged


Prep

  • Put 4 AA batteries into the battery pack, and plug the pack into the board.
  • Set the 3-position POWER switch to 1 for now.
  • Make sure the BATT LOW light off.  If it’s on, that means it’s time for fresh batteries!

  • Connect the SumoBot WX to your computer’s USB port.
  • BlocklyProp Launcher running, BlocklyProp Solo open, and Port set to your SumoBot WX.

 

Servo Centering Program

Program

Follow the steps below to create a program to center the servos.

  • In BlocklyProp Solo, create a New Project named
  • Name it Center Servos with a Board Type of Propeller FLiP or Project Board
  • Place two CR servo PIN speed blocks on the canvas.  You can find them in the Servo category.  
  • Set one block’s PIN dropdown to 26, and the other to 27.  Leave the speed values for each block at zero.
  • Snap the block with PIN set to 27 underneath the one with PIN set to 26.
  • Optionally, snap a comment on top that matches the project name: Center Servos.  
  • Click Save and save your program to your computer.

 

Procedure

  • For each servo, you will make a small adjustment to its set screw. This will match its stay-still behavior to the zero-speed signal sent by a CR servo block.
  • Click the Load & Run (Save code to EEPROM)  button to load the program into your SumoBot.  The button looks like this:
  • Set the SumoBot face down on the table so that its wheels do not touch the surface.
  • Set the POWER switch to 2.  If you don't, the servos will not get any power, and this procedure will not work!


If your servos are new, they should start moving slowly at this point.  If they were used in a previous term at your school, they might or might not already be centered, and so may or may not turn.  

If you turn the screwdriver slightly in one direction, the servo should speed up, and in the other, it should slow down.  It might even stop and then start turning the opposite directions if the set screw passes the center (stay still position) as you adjust it.

CAUTION - BE GENTLE!  The set screw is part of a potentiometer and it is very delicate.  Do not press hard on the screwdriver, and only turn it slightly and gently.

  • Use the Parallax screwdriver’s Phillips end to adjust the set screw in one of the servos.
  • Carefully adjust each screw until you find the setting that makes the servo not turn.
  • Repeat for the other servo.

 

How the Centering Program Works

The topmost block is called a comment. It’s a block where you can notes that don’t have any other effect on the program.  This comment just contains text to record the Project name.  

There are two CR servo PIN speed blocks in the program.  CR stands for continuous rotation, which is different from the Servo block, which is made for a standard servo that simply holds certain angles instead of turning at certain speeds.

The CR servo PIN 26 speed 0 block tells the Propeller to send servo control signals to its P26 servo port.  Those signals tell the continuous rotation servo connected to that port to hold a speed of zero.  The last block is CR servo PIN 27 speed 0, which tells the Propeller to send those same zero speed signals to the servo connected to the P27 servo port.


Did You Know?

The POWER switch is designed so that 0 shuts everything off.  This includes the Propeller FLiP.  Even if it’s connected to USB, it will not accept a program until you set POWER to 1 or 2.  The POWER 1 setting turns everything on except the servos.  The POWER 2 setting turns everything on, including the servos.  


You will typically use POWER 1 to load programs at your computer.  Since the POWER 1 doesn’t supply the servos, it will prevent your SumoBot WX from trying to roll away and off the table when the code starts. 

If you used the Load & run (store in EEPROM) button to load the program into the SumoBot, you can take it to your SumoRing and then start the program from the beginning like this:

  • Press and hold the (RST) reset button.
  • Switch POWER to 2.  
  • Release the reset button.

After you release the reset button, the program will start from the beginning.

The signal that controls a servo’s speed and direction is a brief high signal that has to be repeated every 20 ms.  That’s 50 times per second.  The stay-still signal stays high for 1.5 ms and low for the remaining 18.5 ms.   If you connected a light emitting diode (LED) circuit’s input to the P26 pin and the other end to ground, the light would glow during those brief 1.5 ms high signals and stay off the rest of the time.


 

Test Motor Speeds & Directions

Now that the servos are centered, the CR servo PIN speed blocks can set rotation speeds and directions.  This test will make the right servo turn at half speed counterclockwise, then half speed clockwise, then stop. 

After testing the right servo that’s connected to P27, you will change all the PIN values from 27 to 26 to test the left servo. You can also try increasing and decreasing the +/- 50 speed values to increase or decrease the wheel speeds.

Parts

  • SumoBot, built up at least through the end of the Build your SumoBot WX pages
  • USB A to micro-B cable
  • Parallax Screwdriver
  • 4 AA batteries (in the SumoBot Robot’s battery pack)

Prep

  • 4 AA batteries in the battery pack.
  • 3-position POWER switch set to 1.  (You will set it to 2 after loading the program.)
  • BATT LOW light off.  If it’s on, that means it’s time for fresh batteries!
  • SumoBot connected to your computer’s USB port.
  • BlocklyProp Launcher running, and BlocklyProp Solo launched.
  • Ports dropdown set to your SumoBot’s port number like you did in Connect, Power & Run.

 

Speed & Direction Program

  • In BlocklyProp Solo, create a New Project named CCW CW Stop with a Board Type of Propeller FLiP or Project Board.
  • Create this block program and save it.
  • (If you are unsure where to find certain blocks or how to make them match this picture, check the animated and checklist steps below.)

Animated Steps

Checklist  Steps

  • Place an add comment block from the Control category, and type CCW CW Stop into the text field.
  • Place a CR servo PIN...speed block from the Servo category, and set its PIN dropdown to 27 and its speed value to 50.  Connect it below the comment block.
  • Place a pause (ms) block from the Control category and change the value from 1000 to 3000.  Connect it below the CR servo PIN 27 speed 50 block.
  • Right-click and duplicate the CR servo speed block.  Change the speed in the duplicated block to -50, and connect it below the pause (ms) 3000 block.
  • Richt-click and duplicate the pause (ms) 3000 block, and connect it below the CR servo PIN 27 speed -50 block.
  • Right-click and duplicate the CR servo PIN 27 speed -50 block, and connect it below the pause (ms) 3000 block you just placed.  Then, change its speed value to 0.

Procedure

For this test, we’ll keep the SumoBot WX face down on the table so that the wheels can spin freely.  With the POWER switch set to 2 and the program running, the robot’s right wheel should turn counterclockwise for 3 seconds, then clockwise for three seconds, then stop.

  • Set the SumoBot WX face down on the table so that its wheels do not touch the surface.
  • Make sure it’s right wheel is facing you, as shown here.

  • Set the POWER switch to 2.
  • Click Load & Run (Save code to EEPROM) to load the program into your SumoBot.  
  • Verify that the right wheel rotates counterclockwise for 3 seconds, then clockwise for 3 seconds, and then stops.
  • Press/release the SumoBot board’s reset (RST) button to start restart the program from the beginning and see the wheel motions again.


If the other wheel turns, it means that the servo cables connected to P26 and P27 are reversed and need to be swapped.

 

How the Wheel Test Works

The Propeller FLiP executes blocks starting at the top and works its way downward.  So, the first block it executes is CR servo PIN 27 speed 50, which makes the servo turn at about half speed counterclockwise. 

The pause (ms) 3000 makes the Propeller FLiP do nothing for 3 seconds.  During that time, the wheel continues to turn. 

Next, CR servo PIN 27 speed -50 makes the servo turn at half speed clockwise, and the pause (ms) 3000 block below it allows it to continue turning for another 3 seconds. 

Last but not least, CR servo PIN 27 speed 0 makes the servo turn at 0 speed, and since there’s nothing after it, it continues to hold that (zero) speed indefinitely.  


When the Propeller executes code from a CR servo PIN….speed… block, another one of the Propeller microcontroller’s 8 cores steps in and starts sending repeated signals to make a continuous rotation servo turn at a certain speed.  It will keep sending those signals and the servo will keep turning until another CR servo PIN...speed… block asks for a different speed.  At that point, the Propeller core that is sending the servo control signals updates them for the new behavior.

This “set it and forget it” response to CR servo PIN...speed… blocks is very useful. Your program can do other things while the servos are turning, like check sensors, calculate, decide, and more.  Instead of doing that here, the program uses pause (ms) 3000 blocks to just do nothing for 3 seconds.  Those pause (ms) blocks allow you to see the servos turn one direction, and then the other before stopping.  Without the pause (ms) blocks, all you’d see would be a twitch, and the program would be over in the blink of an eye.

 

Try This: RPM

Full speed for a Parallax CR servo powered by 5 V is typically a little over 50 RPM, so 50% speed would be about 25 RPM.  We can use these numbers to calculate roughly how far the wheel should turn.  


     

Keep in mind that 1.25 revolutions is an approximate value.  It will vary with how fresh your batteries are, and even which direction the servo turns.  So long as each servo turns somewhere in the 1.1 to 1.6 revolutions range, you’re in good shape.

As with the center signal from the previous activity, the brief high times still repeat every 20 ms.  The difference is that for 50% of full speed counterclockwise, the brief high signals last for 1.55 ms instead of 1.50 ms.  For clockwise, instead of the high times lasting 0.05 ms longer than the 1.50 ms center signal, they last 1.45 ms, which is 0.05 ms shorter.
.


This graph is called a transfer function.  It shows typical servo speed vs. pulse duration.  The pulse durations are in terms of μs (millionths of a second) instead of ms (thousandths of a second).  So, instead of 1.5 ms, the graph shows 1500 μs.  

  • Find 50 on the x axis.
  • Follow the vertical line up from on the x axis to where it intersects the graph.  
  • Imagine a level line from that point to the y axis.  It should intersect just at a value of just over 25 RPM.
  • Repeat this for x axis values of -200, -100, -75, -50, -25, 0, 25, 50, 75, 100, and 200.
  • Make a list of y axis RPM speeds you’d expect for each x axis % of full speed value.

Those percent-of-full-speed x axis values actually describe how many microseconds above or below 1.5 ms each control pulse lasts.  The graph shows the servo rotational velocity response in terms of RPM.  The graph speeds do not exactly match % full speed, but it’s close enough to use as a way of thinking about how the numbers from -100 to 0 to 100 correspond result in certain servo speeds.


Try This

Now, let’s test the right wheel.

  • Turn the SumoBot around so that you are viewing its right wheel.  (It should still be face down on the table.)

  • Change all the PIN settings from 27 to 26. Make sure to change all three!

  • Click Load & Run (Save code to EEPROM) to load the program into your SumoBot.  
  • Verify that the left wheel rotates counterclockwise for 3 seconds, then clockwise for 3 seconds, and then stops.
  • Optionally, press/release the SumoBot board’s reset (RST) button to start restart the program from the beginning and see the wheel motions again.


Your Turn

  • Test one of the servos at different speeds: -200, -100, -75, -50, -25, 25, 50, 75, 100, and 200.  Observe the wheel speed at each setting.  

Each servo is unique. Even though 100 is approximately 100% of full speed, it varies from one servo to the next.  A speed of 200 essentially ensures that the servo will turn at top speed.

 

Maneuver Basics

For the SumoBot WX to roll forward, the left and right wheels have to turn in opposite directions.  It may sound counterintuitive, but take a look at the left side of your SumoBot.  See how the left wheel has to roll counterclockwise if it’s going forward?  Now, look at the right side.  The right wheel has to turn clockwise for forward motion.  



Each wheel is independently controlled by its own block.  The next diagram shows some examples of wheel speeds and how they relate to forward and backward with speed control. 

For example, to make the SumoBot roll full speed forward, one block has to have its PIN set to 26 to control the left servo, with a speed of 100 for counterclockwise wheel rotation.  A second block with its PIN set to 27 to control the right servo and speed -100 for clockwise rotation.  For full speed reverse, one block would need PIN 26 and speed -100 for the left servo and PIN 27 and speed 100 for the right servo.  To make the SumoBot stop, set both P26 and P27 block speeds to 0.


Since the wheels are controlled independently, you can get pretty creative with maneuvers.  This animation shows the results of various combinations using -100, -50, 0, 50, and 100 for speed.  Watch it carefully, and think about which direction and how fast each wheel turns in response to the speed values.


In this activity, you will test some of the pin and speed combinations.


Parts

  • SumoBot, built up at least through the end of the Build your SumoBot WX pages
  • USB A to micro-B cable
  • 4 AA batteries (in the SumoBot Robot’s battery pack)

Prep

  • 3-position POWER switch set to 1.  (You will set it to 2 after loading the program.)
  • 4 AA batteries in the battery pack.
  • BATT LOW light off.  If it’s on, that means it’s time for fresh batteries!
  • SumoBot connected to your computer’s USB port.
  • BlocklyProp Launcher running, and BlocklyProp Solo launched.
  • Ports dropdown set to your SumoBot’s port number like you did in Connect, Power & Run.

Looking at the SumoBot from the above, its plow is attached to the front.  If the SumoBot board is mounted correctly, the POWER switch should be at the back, and the SumoBot WX label should be at the front-right.

  •  Verify that your board is mounted correctly, with the POWER switch at the back and the SumoBot WX logo at the front-right.
  • If the SumoBot WX board is not mounted correctly, take a few minutes to detach the board and mount it correctly.

 

Maneuver Program

Program

  • In BlocklyProp Solo, create a New Project named Forward Left Right Backward Stop with a Board Type of Propeller FLiP or Project Board.
  • Build the program shown below, and then Save.

Procedure

This program will make the SumoBot execute this sequence of 3-second maneuvers: roll forward, spin left, spin right, roll backward, stop.  In addition to getting familiar with using speeds and times for maneuvers, it will also help verify that the serovs are connected properly with the left servo connected to the P26 port and the right to P27.

  • Set the POWER switch to 1.
  • Click Load & Run (Save code to EEPROM) to load the program into your SumoBot.  
  • When the program is done loading, set the POWER switch to 0, and disconnect the SumoBot from the USB cable.
  • Seet an empty floor that’s smooth, or a large table.
  • Press the RST button, set the POWER switch to 2, and let go of the RST button.
  • Verify that the SumoBot starts by rolling forward (toward the plow) for three seconds.
  • If the SumoBot’s first maneuver was rolling backward instead of forward, it means the servo cables are swapped.  In other words, the cable that should be plugged into P26 is plugged into P27 and vice versa.
  • Verify that after rolling forward, the SumoBot spins in place, turning left for 3 seconds, then right for 3 seconds before backing up for 3 seconds and stopping.

If you noticed that your SumoBot was veering slightly to the right or left at top speed, the trick to correcting it is to figure out which wheel is turning faster and slow it down with a lower speed value.  More about that in the Your Turn section...
 

How the Maneuver Code Works

These blocks make the SumoBot roll forward at full speed, by making the left (P26) servo turn counterclockwise with a speed of 100 and the right P27 servo turn clockwise with a speed of -100.  This maneuver continues for 3 seconds.  It could potentially go longer than that if the next blocks are not CR servo PIN...speed… blocks.


These blocks make the SumoBot turn in place to the left at half speed, by making both the left (P26) and right P27 servo both turn clockwise with a speed of -50.  The result is that the SumoBot spins in place turning left, and the maneuver also continues for 3 seconds.  


These two blocks are almost identical to the previous ones.  The only difference is that the speed values are both 50 instead of -50.  Since both blocks are positive instead of negative, both wheels turn counterclockwise instead of clockwise.  The result is that the SumoBot turns in place to the right (instead of to the left).  


Compare these blocks to the full speed forward blocks at the beginning of this program.  See how the negative signs are swapped?  That’s a sure sign that the SumoBot will roll in the opposite direction—backward in this case.  The P26 left wheel turns at a speed of -100, which is full speed clockwise, and the P27 right wheel turns at a speed of 100, which is full speed counterclockwise.  As with the other maneuvers, this one continues for 3 seconds.


These two blocks set the servos to zero speed, and since no other blocks are below it, the program ends.  Since another processor is managing the servo signals, it continues to send the zero speed signal to both servos.

 

Try This: Time and Distance

Each maneuver involves two wheel speeds and an amount of time.  

To decrease the distance of a forward or backward maneuver, you have a choice of decreasing either the speed or the time.  Likewise, distance will increase with either a longer time traveled or a higher speed.  Increasing the speed to increase distance only works if the servos are not already going at top speed though.

Turns can also be greater or smaller angles, and speed and time are the two variables that can be adjusted.  If speed remains the same, but time is reduced, the angle turned will be less.  Alternatively, the maneuver time can be left unchanged and the wheel speeds can be increased or decreased for smaller or larger angle turns.  

When the SumoBot can “see” its opponent, top speed maneuvers to either start pushing or get out of the way are common.  If the SumoBot is searching for its opponent, it is sometimes better to move slower while scanning left and right with sensors.

Try This

Let’s take a closer look at how changing the maneuver times changes the distances traveled and angles turned.

  • Modify your maneuver program so that instead of taking 3 seconds for each maneuver, it takes 2 seconds for the forward and backward maneuvers and 0.75 seconds for each turn.  
  • Test the program, and verify that it travels about ⅔ of the previous forward/backward distances and much shorter turns.
  • Tune the 750 times so that the SumoBot executes a 90⁰ left turn followed by a 90⁰ right turn.

 

Your Turn: Maneuver Challenges

As mentioned at the beginning, the more practice you get with maneuvers, the better.  So, here are some challenges to help build your maneuver creating and building skills.

Tuning: Straighten Forward and Backward

If your SumoBot curved when you expected it to go straight, the solution is simple: slow down the faster wheel.  Here are three short example programs.  The top-center one is the test to see if your SumoBot curves.  If it curves to the left, the first step is to change the CR servo PIN 27 block’s speed value from 100 to 90.  If it curves to the right, the first step is to change the CR servo PIN 26 block’s speed value from 100 to 90.  

  • Enter and run the first program to see if your SumoBot curves to the right or left.
  • If your SumoBot curved, take the first step shown below to correct the curve, and re-test it.

 

  • If the first try corrected it, then great! 
  • If the SumoBot curves less in the same direction as before, increase your adjustment, to maybe PIN 27 speed -85 to correct left curves or PIN 26 speed 85 to correct right curves. 
  • Keep on adjusting until you find the best value. 

Also, keep in mind that making the SumoBot go perfectly straight is not nearly as important in the Sumo ring as it would be in a dead reckoning contest where every little error adds up. 

Pivots and Curves

This activity began with an explanation of the variety of maneuvers two independent drive wheels could execute.  Some examples we haven’t tried yet include pivots, where one wheel is set to speed zero, and curves, where the two wheel speeds are different, like one wheel with speed 100, and the other with speed 50.

  • Save Forward Left Right Backward Stop as Pivots and Curves.
  • Modify the program so that it executes two forward pivots, two backward pivots, two forward curves, and two backward curves.

Shapes

  • Use masking tape on a desk or smooth floor to create shapes, then write BlocklyProp programs to make the SumoBot navigate over each shape without going off the tape.

 

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2022


Source URL: https://learn.parallax.com/tutorials/robot/sumobot-wx/sumobot-wx-movement-basics

Links
[1] https://www.parallax.com/product/sumobot-wx
[2] https://learn.parallax.com/tutorials/robot/sumobot-wx/build-your-sumobot-wx