Acceleration and Speed Limits

Acceleration is a measurement of how quickly something speeds up or slows down.  The ActivityBot's acceleration can be adjusted, which will be important in some robotic applications.  For example, if your ActivityBot is bringing you a drink, you could make the acceleration gradual to prevent spills.  Another example: if your ActivityBot is in a race, it might be more important to make it speed up as quickly as possible.

The ActivityBot robot's acceleration can be adjusted with the Robot set acceleration for block, which has settings for both distance and speed.  The acceleration setting for distance maneuvers is typically slower to help improve accuracy.  The acceleration setting for speed is usually a little faster to give the robot more peppy responses in sensor navigation. 

You can also configure the speed limits for speed and distance maneuvers.  The default speed limit for Robot drive distance maneuvers is 64 ticks per second.  That's the cruising speed the ActivityBot reaches while on its way to its distance goal.  For transporting a drink, it might be safer to pick a slower cruising speed.  In a timed dead reckoning navigation contest, you might want to experiment with higher cruising speeds.  The default speed limit for Robot drive speed is 128 ticks per second.  Even though your code can change the speed at any time, there are some cases when sensors and variables might work together to ask for some unreasonably high speeds.  Limiting the speed can prevent some "runaway" conditions.

 

Test Code

This example sets the acceleration and cruising speed for Robot drive distance blocks to high values and then makes the ActivityBot travel 265 ticks forward.  Then, it sets acceleration to a low value, cuts the cruising speed in half, and backs up the same distance.  As you watch the ActivityBot, pay close attention to two things: (1) acceleration - how quickly it speeds up and slows down, and (2) cruising speed - the top speed it runs at for most of the trip.

  • In your BlocklyProp account, make a new Propeller Activity Board WX program and name it: Set Drive Distance Acceleration and Speeds.
  • Build the project shown below, and save it.  
  • Be sure to set the Robot to initialize block's drop-down menu to your robot: ActivityBot or ActivityBot 360°.

  • Connect your ActivityBot to your computer and set the power switch to 1.
  • Set the COM port and click Load and run (save code to EEPROM).
  • Disconnect your robot and put it on the floor in an open area.
  • Press, hold and release the reset button as you set the power switch to 2.
  • Watch and verify that the ActivityBot has a high cruising speed on the way out and a lower one on the way back.  That is the effect of the Robot set speed (+/-) for distance blocks.
  • Also watch and verify that the ActivityBot abruptly sped up and slowed down on the way out, and gradually on the way back.  That is the effect of the Robot set acceleration for distance blocks.

 

How it Works

The first block in the program is a comment noting the project name.  The second block is frequency out, which makes a piezospeaker tone.  If that tone plays in the middle of the program instead of at the beginning, it could indicate that the batteries are low.  The third block is the required ActivityBot initialize. Make sure you set this one to match your particular robot - ActivityBot or ActivityBot 360.  These first three blocks are used in all example programs that make the ActivityBot move. 

Next, Robot set acceleration for distance blocks to 600 ticks/s2 uses a higher acceleration setting to make the ActivityBot speed up and slow down abruptly.  The Robot set speed (+/-) for distance blocks 128 sets the top speed.  That will be the Robot drive distance block's cruising speed, which is 2 full revolutions per second.  After these settings, the first Robot drive distance block makes the ActivityBot go 256 ticks forward.  The high acceleration setting causes the ActivityBot to speed up and slow down abruptly, while the high Robot set speed for distance setting directs the ActivityBot to use a high cruising speed to travel the distance.

When your robot completes the first maneuver, the next set of Robot set acceleration and Robot set max speed blocks has lower values.  Then, a Robot drive distance block tells the ActivityBot to back up the same distance it just went forward.  You will see that with the new acceleration setting, the ActivityBot gradually speeds up and slows down.  With the new speed setting, the cruising speed is slower.

 


Did You Know?

Step on the acceleratorAcceleration is the change in velocity over time.  When the robot speeds up or slows down, that's acceleration.  Keeping the ActivityBot's motions from being too jerky with sudden starts and stops, the Robot drive speed block gradually starts and stops maneuvers by accelerating and decelerating at a default rate of 600 ticks per second squared. You can change this default rate with the Robot set acceleration block. Be aware though, that it takes time for the robot to accelerate and decelerate, so changing this setting can change distance traveled.  Also, be aware that, for individual robots, some combinations of speed and acceleration work better together than others.

Acceleration rules for Robot drive distance — The default acceleration is 200 ticks/s2 when using the Robot drive distance block.  To change this default, use the Robot set acceleration for distance block. As above, be aware that increasing the acceleration may reduce distance accuracy.  We recommend 200 ticks/s2 for speeds at 64 ticks per second or below, but feel free to experiment with higher values. Of course, results may vary with driving surface and whether your ActivityBot is carrying anything. So, test and tune!


Try This

Setting the acceleration and speed limit for Robot drive speed blocks is about the same as it is for distance.  The main difference is that the Robot set max speed block can override a speed you set with the Robot drive speed block.  The second Robot drive speed block in this example program tries to set the speed to left -128 and right -128.  However, the Robot set max speed block immediately before it prevents the ActivityBot from ever going faster than 64 ticks per second.  

  • Click the top-right menu button in your BlocklyProp editor and select Save project as, naming it: Set Drive Speed Acceleration and Max Speeds.
  • Modify the code until it matches the program shown here.  
  • Be sure to set the Robot initialize block's drop-down menu to your robot: ActivityBot or ActivityBot 360°.

  • Connect your ActivityBot to your computer and set the power switch to 1.
  • Set the COM port and click Load and run (save code to EEPROM).
  • Disconnect your robot and put it on the floor in an open area.
  • Press, hold and release the reset button as you set the power switch to 2.
  • Verify that the ActivityBot's acceleration is abrupt during the forward maneuver and gradual during the backward one.
  • Can you see how the ActivityBot backs up at half speed (-64 ticks/second) even though the speed block is asking for full speed (-128 ticks per second)?  

 

Your Turn

Let's examine how the program can still think it is telling the ActivityBot to go a certain speed even though the Robot set max speed block has clamped the actual speed to a lower value.  The terminal will show the speeds that it's telling the ActivityBot to go, and you can watch and see which speed it reaches. 

 

  • Create an Activity Board WX project named Test Max Speed Override and build the block program shown below.
  • Run it as-is, and verify that your ActivityBot moves forward at all 7 speeds.
  • How do you think it will behave if you change the Robot set max speed block to 64?  Try it and see.