5. Case 03: Dance in Figure-of-eight#

5.1. Introduction#

Make Cutebot travel along a figure-of-8 track.

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()

# Turnning by adjusting the different speed of the left and right wheels of the cutebot. 
while True:
    cutebot.set_speed(100,50)
    sleep(2)
    cutebot.set_speed(50,100)
    sleep(2)

Code details#

  1. Import the modules that we need: cutebot module contains classes and functions for Cutebot smart car operations, and time module contains functions for time operations.

from cutebot import *
from time import *
  1. Create a sample for Cutebot category

cutebot = Cutebot()
  1. Directions turning is done by controlling the speed difference between the left and right wheels of the cutebot smart car.

while True:
    cutebot.set_speed(100,50)
    sleep(2)
    cutebot.set_speed(50,100)
    sleep(2)

5.4. Results#

After turning on the power, the cutebot smart car travels in a figure of 8 trajectory.

5.5. Exploration#

How should I program the car if I want it to travel in a square trajectory?