Compass Guided Robot

Compass Guided Robot

This is an advanced project with the GoPiGo to create a compass guided robot . In this example we use a Grove Compass module with the GoPiGo.

You can enter simple commands on the command line and the GoPiGo follows the command to move and turns according to the commands received and the from the angle sensed from the compass module.

As a bonus, we have added commands with Python Turtle, so that you can visualize the movement of the GoPiGo too.

Compass guided bot with compass module

Hardware needed:

  • A fully assembled GoPiGo
  • A decent battery pack providing atleast 9V (recommended 12V battery pack of 8AA cells )
  • Wifi Adapter for connecting and controlling
  • Grove Compass module

Connecting the Compass module

  • Attach the Grove connector to the compass module and connect it to the I2C port on the bottom left side of the GoPiGo board.
  • NOTE: Keep the compass module as far away ( at least 6 inches) from the Raspberry Pi using some kind of overhang because the magnetic interference from the Raspberry Pi and the motors causes the compass to lose the accuracy in heading.

Setting up the GoPiGo

Make sure that the GoPiGo is set up properly and you have the updated software and firmware. If you are not sure about this, follow the guide here.

If the GoPiGo is properly set up, connect to the GoPiGo via VNC and open terminal.

Running the example:

  1. Open VNC and go to the compass bot example folder:
      cd Desktop/GoPiGo/Software/Python/Examples/Compass Robot/

    Changing the path to the compass bot folder

  2. Start the compass_bot example
    sudo python compass_bot.py

    You can give the following commands to the compass bot:

    • f dist : move forward by “dist” (distance = dist/4 encoder counts. 1 rotation=18 encoder counts) e.g.: f 100
    • l deg : rotate left by “deg” (l 45)
    • r deg : rotate right by “deg” (r 45)

    It will move the GoPiGo and also show the output on the Turtle prompt.

    Compass guided bot output

    Compass bot responding to commands and showing the output on Turtle

You can easily adapt this example to any interactive project that you have in mind with the GoPiGo and the compass module.

Have a question? Go check out our support page here or post it on the forums here