5. Case 02: Speed Up Gradually

5.1. Introduction

Control the Cutebot to accelerate evenly until it reaches the maximum speed.

5.2. Programming Preparation

Please refer to: Preparing the Programming Environment

5.3. Sample code

from cutebot import *
from time import *

#  Create a sample for Cutebot category
cutebot = Cutebot()
#  Create the variable cutebot_speed to hold the speed value of the cutebot smart car
cutebot_speed = 0

# Set the speed of the cutebot smart car to accelerate evenly from 0 to 100
while True:
    if cutebot_speed > 100:
        cutebot_speed = 100
    cutebot.set_speed(cutebot_speed,cutebot_speed)
    cutebot_speed = cutebot_speed + 1
    sleep(0.02)

Code details

  1. Import the modules that we need: cutebotmodule contains the classes and functions for Cutebot smart car operation, time module contains the functions for time operation.
from cutebot import *
from time import *
  1. Create a sample for Cutebot category
cutebot = Cutebot()
  1. Create the variable cutebot_speed to hold the speed value of the cutebot.
cutebot_speed = 0
  1. Set the speed of the cutebot to accelerate evenly from 0 to 100.
while True:
    if cutebot_speed > 100:
        cutebot_speed = 100
        cutebot.set_speed(cutebot_speed,cutebot_speed)
        cutebot_speed = cutebot_speed + 1
    sleep(0.02)

5.4. Results

After turning on the power, the speed of cutebot accelerates evenly from 0~100.

5.5. Exploration

How to make the car accelerate evenly and then decelerate evenly?