When facing an opponent in the sumo ring, your SumoBot WX will have to execute a variety of maneuvers. Examples include:
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.
You will need:
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.
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.
Follow the steps below to create a program to center the servos.
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.
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.
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:
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.
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.
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.
If the other wheel turns, it means that the servo cables connected to P26 and P27 are reversed and need to be swapped.
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.
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.
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.
Now, let’s test the right wheel.
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.
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.
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.
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.
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...
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.
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.
Let’s take a closer look at how changing the maneuver times changes the distances traveled and angles turned.
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.
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.
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.
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.
Links
[1] https://www.parallax.com/product/sumobot-wx
[2] https://learn.parallax.com/tutorials/robot/sumobot-wx/build-your-sumobot-wx