Table of Contents

Robot Motion – Python

Robot Forward
Example Description
The example demonstrates how the robot moves forward, backward, left, and right using motor direction control in the Python Coding Environment.

Code

sprite = Sprite('Tobi')
quarky = Quarky()

# imported modules
import time

# User Defined Functions
def Forward():
  quarky.runmotor("L", "FORWARD", 100)
  quarky.runmotor("R", "FORWARD", 100)
  time.sleep(1)
  quarky.stopmotor("L")
  quarky.stopmotor("R")

def Backward():
  quarky.runmotor("L", "BACKWARD", 100)
  quarky.runmotor("R", "BACKWARD", 100)
  time.sleep(1)
  quarky.stopmotor("L")
  quarky.stopmotor("R")

def Left():
  quarky.runmotor("L", "BACKWARD", 100)
  quarky.runmotor("R", "FORWARD", 100)
  time.sleep(1)
  quarky.stopmotor("L")
  quarky.stopmotor("R")

def Right():
  quarky.runmotor("L", "FORWARD", 100)
  quarky.runmotor("R", "BACKWARD", 100)
  time.sleep(1)
  quarky.stopmotor("L")
  quarky.stopmotor("R")

Forward()
Backward()
Left()
Right()

Output

Robot Forward

Robot BackwardLeft RobotRight Robot