Computer Controlled Quadruped

Example Description
In this tutorial, you will learn how to control a quadruped robot using arrow keys.

Introduction

In this example, we will make the computer program that controls a “quadruped” (a four-legged robot). It’s like a remote control car, except with four legs instead of four wheels. You can press different keys on the keyboard to make the quadruped move forward, backward, turn left and turn right.

Logic

The Quadruped will move according to the following logic:

  1. Quadruped will move forward When the “UP” key is pressed.
  2. Quadruped will move backward When the “DOWN” key is pressed.
  3. Quadruped will turn left When the “LEFT” key is pressed.
  4. When the “RIGHT” key is pressed – Quadruped will turn right.

Code

The program uses the up, down, left, and right arrows to control the robot and make it move forward, backward, left, and right. Every time you press one of the arrows, Quadruped will move in the direction you choose for specific steps.

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

quad=Quadruped(4,1,8,5,3,2,7,6)
quad.home()

while True:
  if sprite.iskeypressed("up arrow"):
    quad.move("forward",1000,1)
    time.sleep(1)
    
  if sprite.iskeypressed("down arrow"):
    quad.move("backward",1000,1)
    
  if sprite.iskeypressed("left arrow"):
    quad.move("turn left",1000,1)
    
  if sprite.iskeypressed("right arrow"):
    quad.move("turn right",1000,1)

Output

Table of Contents