Running the GoPiGo3 BalanceBot

Running the GoPiGo3 BalanceBot

GoPiGo3 BalanceBot Raspberry Pi RobotIn this section, we will show how to run the GoPiGo3 BalanceBot, and how to adjust the various constants in the python program that control the balancing algorithm.  The GoPiGo3 can be transformed from a car, into a Balancing Raspberry Pi Robot.  In this tutorial we walk you through how to setup and run you balancing Raspberry Pi robot.

Before you Begin

You should already have assembled the GoPiGo3 BalanceBot robot; if not, see our directions here.

Running the BalanceBot Program

We will go over running the BalanceBot for the first time.

  1. Assemble the BalanceBot.  Pay special attention to how the sensors are attached: if they are backwards, the BalanceBot will not balance.  Balancing Raspberry Pi Robot
  2. Power up the robot.  We recommend using an 8xAA battery pack.  If you are using a different power source, you may need to adjust the constants in the program to balance your robot.
  3. Login to the GoPiGo3 Robot.  In this example, we use Raspbian for Robots.  Since you will want your BalanceBot to roam free, we recommend connecting your robot to your local WiFi network.
  4. Find the file.  The file is located in ~/Dexter/GoPiGo3/Projects/BalanceBot directory.   If you can’t find it, do a Git update on the directory:  cd ~/Dexter/GoPiGo3 && sudo git fetch --all  Setting up the BalanceBot Robot
  5. Run the program:  sudo python BalanceBot.py  
  6. Stand the GoPiGo3 BalanceBot upright.  With the program running, the robot should almost balance on its own.  
  7. Press the OK button.  You will be Prompted to press the OK button on your IR remote.  Once you press the button  you should feel the robot begin to balance on its own.  
  8. Drive Around!  You can now use the Up, Down, Left, and Right buttons on the IR Remote to move the robot around.
  9. It fell!  No problem.  You should be able to stand it back up, bring it to balanced, and press the OK button again.  You robot will keep going!

 

Understanding the K-Constants

A balanced robot relies on the constants in the PID control algorithm. These constants work for a certain environment: the size of the wheels, the weight of the battery pack, the surface that your BalanceBot is working on.  If you scroll through the BalanceBot.py program, stop at lines 50-70.

The balance behavior of the balancing Raspberry Pi Robot will be most significantly affected by KGYROANGLE and KGYROSPEED.  If you feel you need to change the constants because your robot is not balancing or having trouble, start with these constants and adjust.

Most Important PID Constants:

KGYROANGLE – How much the robot responds to the overall angle integrated from the Gyro. Increasing this will cause the robot to respond more aggressively to overall robot angle. Increasing too much will cause the robot to oscillate and fall. Decreasing too much will cause the robot to not respond enough, and will cause the robot to fall.
KGYROSPEED – How much the robot responds to changes in angle (rate of rotation i.e. fall). Increasing this will cause the robot to respond more aggressively to changes in robot angle. Increasing too much will cause the robot to oscillate and fall. Decreasing too much will cause the robot to not respond enough, and will cause the robot to fall.

Other PID Constants:

KPOS – How much the robot attempts to stay in place (so it doesn’t wander off). Also how aggressively it will try to drive to the specified position (when driving with remote). Increasing this will make the robot try to stay in place better, but if it’s too high the robot won’t be able to stay upright, since it will be focused on staying in place. Decreasing this will allow the robot to wander a little, and can make balancing more stable (since it won’t be as focused on staying in place).

KSPEED – How much the current motor speed effects the motor power.

KDRIVE– Prevents the robot from starting/stopping aggressively. Used for driving the robot with remote.
KSTEER – Not used for the balance algorithm, but used to tell the motors how much to respond to a difference between left and right speed (for turning). Increasing this will make turns more responsive, but could throw the robot off balance if set too high. Decreasing too much will make turning less responsive.
KVOLTAGE– Scales the motor power according to the battery voltage so that it automatically “re-tunes” for dying batteries. Don’t change this constant.
The user can also adjust DRIVE_SPEED and STEER_SPEED to change how fast the robot will drive/steer with the remote. Setting these too high will cause the robot to be unstable, as it will focus too much on driving, and not enough on balancing.

Other Constants

TIME_FALL_LIMIT – sets the timeout after which the robot assumes it fell and needs to be restarted.
WHEEL_DIAMETER, WHEEL_RATIO, and LOOP_TIME should not be change.  Also note that the sensor port definitions should not be changed either.

Questions?

Ask on our forums!