curve.py — script to control a GoPiGo robot

Download the Python script below to your GoPiGo robot. You can do this as follows:
  1. Connect to your GoPiGo using its IP address, :148.137.something.something
    $  ssh -X 148.137.something.something
    
  2. Start a web broswer:
    $  chromium-browser  https://montcs.bloomu.edu/100/  & 
    
  3. Browse to the course webpage: "montcs.bloomu.edu/100/"
  4. Scroll down and find the link for "curve.py" Right-Click on this link, and choose "Save as..."

    The default location, "Downloads", is good enough, or you can put it somewhere else if you wish.

    Once it's downloaded you can close the browser window.

  5. Open a text editor (in the "background"):
    $  leafpad  &
    
  6. Try running the script:
    $  python  Downloads/curve.py
    

Explanation

This Python script attempts to draw a polygon such as a square, hexagon, etc. It makes the robot turn to the right by some amount, then drive forward by some amount, then wait for the operator to press the key.

Each time you press the robot drives one more side of the polygon. If you instead press "q" and then , the robot will quit.

Fix the polygon

In the "while" loop at the bottom, the "turn_right" value is 15 and the "go_straight" value is 10. These values don't work very well for drawing a polygon. Experiment with changing them to draw a polygon of your choice.

Create a path of your own

Once you can do this, can you make the robot follow a predetermined course, such as between the tables and back again? The commands you have available include: More basic commands, that continue in operation until you stop them, include: Download the "curve.py" script
#!/usr/bin/env python
# Draw a polygon?
# 2019-12-02
import gopigo
import sys

#
# First define some control functions:
#
def go_straight(steps):
    for step in range(steps):
        gopigo.fwd()
        gopigo.time.sleep(.1)
    gopigo.stop()
#--------

def turn_left(steps):
    for step in range(steps):
        gopigo.left()
        gopigo.time.sleep(.1)
    gopigo.stop()
#--------

def turn_right(steps):
    for step in range(steps):
        gopigo.right()
        gopigo.time.sleep(.1)
    gopigo.stop()
#--------

#
# Now go into an infinite loop, driving around in "circles":
#
while True:
    turn_right(15)
    go_straight(10)

    # a little back-and-forth jitter, to let you know it's waiting:
    gopigo.bwd()
    gopigo.time.sleep(.1)
    gopigo.fwd()
    gopigo.time.sleep(.1)
    gopigo.stop()
    keybd = raw_input("Press [Enter] to continue, press q[Enter] to quit:")
    if keybd == 'q':
        break
#--------

#
# Broke out of the infinite loop, so quit the program:
#
sys.exit()