lejos.robotics.navigation
Class Segoway

java.lang.Object
  extended by java.lang.Thread
      extended by lejos.robotics.navigation.Segoway
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
SegowayPilot

public class Segoway
extends Thread

This class balances a two-wheeled Segway-like robot. It works with almost any construction (tall or short) such as the Anyway or the HTWay. Wheel diameter is the most important construction variable, which is specified in the constructor.

To start the robot balancing:

  • 1. Run the program. You will be prompted to lay it down.
  • 2. Lay it down (orientation doesn't matter). When it detects it is not moving it will automatically calibrate the gyro sensor.
  • 3. When the beeping begins, stand it up so it is vertically balanced.
  • 4. When the beeping stops, let go and it will begin balancing on its own.

    Alternately you can lean the robot against a wall and run the program. After the gyro calibration, the robot backs up against the wall until it falls forward. When it detects the forward fall, it start the balance loop.

    NOTE: In order to make the robot move and navigate, use the SegowayPilot class.

    This code is based on the HTWay by HiTechnic.

    Author:
    BB

    Nested Class Summary
     
    Nested classes/interfaces inherited from class java.lang.Thread
    Thread.UncaughtExceptionHandler
     
    Field Summary
    protected  EncoderMotor left_motor
               
    protected  EncoderMotor right_motor
               
     
    Fields inherited from class java.lang.Thread
    MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
     
    Constructor Summary
    Segoway(EncoderMotor left, EncoderMotor right, Gyroscope gyro, double wheelDiameter)
              Creates an instance of the Segoway, prompts the user to lay Segoway flat for gyro calibration, then begins self-balancing thread.
     
    Method Summary
     void run()
              When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.
     void wheelDriver(int left_wheel, int right_wheel)
              This method allows the robot to move forward/backward and make in-spot rotations as well as arcs by varying the power to each wheel.
     
    Methods inherited from class java.lang.Thread
    currentThread, getDefaultUncaughtExceptionHandler, getName, getPriority, getUncaughtExceptionHandler, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, start, yield
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    left_motor

    protected EncoderMotor left_motor

    right_motor

    protected EncoderMotor right_motor
    Constructor Detail

    Segoway

    public Segoway(EncoderMotor left,
                   EncoderMotor right,
                   Gyroscope gyro,
                   double wheelDiameter)
    Creates an instance of the Segoway, prompts the user to lay Segoway flat for gyro calibration, then begins self-balancing thread. Wheel diameter is used in balancing equations.
  • NXT 1.0 wheels = 5.6 cm
  • NXT 2.0 wheels = 4.32 cm
  • RCX "motorcycle" wheels = 8.16 cm

    Parameters:
    left - The left motor. An unregulated motor.
    right - The right motor. An unregulated motor.
    gyro - A HiTechnic gyro sensor
    wheelDiameter - diameter of wheel, preferably use cm (printed on side of LEGO tires in mm)
  • Method Detail

    run

    public void run()
    Description copied from interface: Runnable
    When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

    Specified by:
    run in interface Runnable
    Overrides:
    run in class Thread

    wheelDriver

    public void wheelDriver(int left_wheel,
                            int right_wheel)
    This method allows the robot to move forward/backward and make in-spot rotations as well as arcs by varying the power to each wheel. This method does not actually apply direct power to the wheels. Control is filtered through to each wheel, allowing the robot to drive forward/backward and make turns. Higher values are faster. Negative values cause the wheel to rotate backwards. Values between -200 and 200 are good. If values are too high it can make the robot balance unstable.

    Parameters:
    left_wheel - The relative control power to the left wheel. -200 to 200 are good numbers.
    right_wheel - The relative control power to the right wheel. -200 to 200 are good numbers.