Command prompt

Python code and building instructions for the LEGO MINDSTORMS Robot Inventor Main Models (51515).

Command prompt
Image credit: LEGO

Control Gelo with the interactive command prompt


Using the command prompt

Python has an interactive command prompt. This is also sometimes called the REPL (Read Evaluate Print Loop). It can be used to run Python code as you type it in.

Save the program below as gelo_repl.py in Pybricks Code. And make sure you have the gelo.py saved there too.

Then connect to Gelo and run the program. In the terminal window in Pybricks Code, you will see a prompt like this:

>>>

Type in a command like this and press enter:

>>> gelo.walk()

Tips

  • To save some typing, after typing gelo., you can press the tab key to provide a list of available methods. Then type the first few letters and press tab again to complete the name.
  • To cancel a running command, you can press ctrl+c.

Program

from gelo import Gelo

gelo = Gelo()

# Normally, we don't call methods with
# double-underscores directly, but this
# is an exceptional case!
gelo.__enter__()

# A KeyboardInterrupt will stop the
# program and start the interactive
# prompt. You can also trigger this
# in any running program by pressing
# CTRL+C in the terminal.
raise KeyboardInterrupt


This project was submitted by The Pybricks Team.