Python program to move forward and return with LEGO Education SPIKE Prime

This program makes the robot move forwards and then backwards using LEGO Education SPIKE App Python.

from spike import PrimeHub, LightMatrix, Button, StatusLight, ForceSensor, MotionSensor, Speaker, ColorSensor, App, DistanceSensor, Motor, MotorPair
from spike.control import wait_for_seconds, wait_until, Timer
from math import *

hub = PrimeHub() 

motor_pair = MotorPair('A', 'B') # Set the motor ports in the motor_pair.
motor_pair.set_default_speed(50) # Set the default speed of the the motor_pair.
motor_pair.set_motor_rotation(17.6, 'cm') # Set the distance that the robot travel for one rotation of its wheels. The value 17.6 comes from
                                          # the diameter of the wheel (5.6cm) multiplied by "π" (3.14).

motor_pair.move(40,'cm', 0, 50) # Start moving for 40cm with NO Steering '0' with 50% speed.
motor_pair.move(40,'cm', 0, -50) # Start moving backward for 40cm with NO Steering '0' with 50% speed. -50 for speed means: rotate with 50% seed backward.

raise SystemExit # Close the program.

Download
  • #s3c8dj
  • 11 Mar 2021

Courses and lessons with this Program

This Program is used in the following courses and lessons

Image for FIRST LEGO League with LEGO Education SPIKE Prime. "Challenge" competition for 9-16 years old
  • 40
  • 127:22
  • 24
Image for FIRST LEGO League with LEGO Education SPIKE Prime. "Challenge" competition for 9-16 years old
  • 40
  • 127:22
  • 24
Image for FIRST LEGO League with LEGO Education SPIKE Prime. "Challenge" competition for 9-16 years old
  • 40
  • 127:22
  • 24
Image for Move with SPIKE Prime
  • 1
  • 0
  • 1
  • 3d_rotation 1
Image for FIRST LEGO League with LEGO Education SPIKE Prime. "Challenge" competition for 9-16 years old
  • 40
  • 127:22
  • 24
Image for FIRST LEGO League with LEGO Education SPIKE Prime. "Challenge" competition for 9-16 years old
  • 40
  • 127:22
  • 24
Image for Automatically detached attachments
  • 2
  • 0
  • 1
  • 3d_rotation 3