Class WheeledChassis

  • All Implemented Interfaces:
    Chassis

    public class WheeledChassis
    extends java.lang.Object
    implements Chassis
    Represents the chassis of a wheeled robot.

    The WheeledChassis provides a control system for driving a mobile robot with motorized wheels. Both differential and holonomic robots can be represented by the WheeledChassis class.

    How to create a WheeledChassis object
    The constructor of the DifferentialChassis class accepts an array of Wheel objects. Each of the wheel objects describes one of the motorized wheels on the chassis. A Description of a wheel consists of its diameter, its position, its motor and the gear train between wheel and motor. Wheel objects can be created using a modeler class. A modeler for traditional wheel can be obtained using the modelWheel(lejos.robotics.RegulatedMotor, double) method. A modeler for a holonomic wheel can be obtained using the modelHolonomicWheel(lejos.robotics.RegulatedMotor, double) method.

    .

    This example creates a WheeledChassis for a differential robot.

     Wheel wheel1 = WheeledChassis.modelWheel(Motor.A, 81.6).offset(-70);
     Wheel wheel2 = WheeledChassis.modelWheel(Motor.D, 81.6).offset(70);
     Chassis chassis = new WheeledChassis(new Wheel[] { wheel1, wheel2 }, WheeledChassis.TYPE_DIFFERENTIAL);
     

    This example creates a WheeledChassis for a holonomic robot.

        Wheel wheel1 = WheeledChassis.modelHolonomicWheel(Motor.A, 48).polarPosition(0, 135).gearRatio(2);
        Wheel wheel2 = WheeledChassis.modelHolonomicWheel(Motor.B, 48).polarPosition(120, 135).gearRatio(2);
        Wheel wheel3 = WheeledChassis.modelHolonomicWheel(Motor.C, 48).polarPosition(240, 135).gearRatio(2);
        Chassis chassis = new WheeledChassis(new Wheel[]{wheel1, wheel2, wheel3}, WheeledChassis.TYPE_HOLONOMIC);
     

    Please note that a Chassis can have an unlimited number of motorized wheels but a differential robot needs at least two wheels and a holonomic robot needs at least three wheels.

    See also the Chassis interface.

    *
    Author:
    Aswin Bouwmeester
    • Constructor Summary

      Constructors 
      Constructor Description
      WheeledChassis​(Wheel[] wheels, int dim)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void arc​(double radius, double angle)
      Moves the chassis in an arc
      protected Matrix copyAbsolute​(Matrix in)
      Make a copy of the source matrix, each of its element being the absolute value of the elements of the source matrix
      double getAngularAcceleration()
      Gets the setting for angular acceleration as is used in travel, arc, rotate and setvelocity methods
      double getAngularSpeed()
      Gets the setting for angular speed as is used in travel, arc, and rotate methods
      double getAngularVelocity()
      Returns the angular component of the current speed of the robot
      protected Matrix getAttribute​(int attribute)
      Helper method to get some dynamic attributes from each motor
      Matrix getCurrentSpeed()
      Returns a matrix containing the current speed of the robot.
      Move getDisplacement​(Move move)
      Method used by the MovePilot to update a move object that describes the move executed since the last call to startMove.
      Matrix getForward()  
      double getLinearAcceleration()
      Gets the setting for linear acceleration as is used in travel, arc, rotate and setvelocity methods
      double getLinearDirection()
      Returns the current direction of the linear speed component of the robot
      double getLinearSpeed()
      Gets the setting for linear speed as is used in moveTo, Arc, and Rotate methods
      double getLinearVelocity()
      Returns the linear component of the current speed of the robot
      protected double getMax​(Matrix a)
      Gets the biggest value from a matrix
      double getMaxAngularSpeed()
      Returns how fast the robot can rotate.
      double getMaxLinearSpeed()
      Returns the maximum speed of the robot.
      double getMinRadius()
      Returns the smallest possible radius this chassis is able turn
      PoseProvider getPoseProvider()
      Returns an Pose provider that uses odometry to keep track of the pose of the chassis
      Matrix getReverse()  
      boolean isMoving()
      Returns true if the robot is moving.
      boolean isStalled()
      Returns true if at least one of the wheels is stalled
      static WheeledChassis.HolonomicModeler modelHolonomicWheel​(RegulatedMotor motor, double diameter)
      Provides a modeler object to model a Holonomic motorized wheel on the chassis
      static WheeledChassis.Modeler modelWheel​(RegulatedMotor motor, double diameter)
      Provides a modeler object to model a Holonomic motorized wheel on the chassis
      void moveStart()
      Method used by the MovePilot to tell the chassis that a new move has started.
      void rotate​(double angular)
      Rotates the chassis for the specified number of degrees
      void setAcceleration​(double linearAcceleration, double angularAcceleration)
      Sets the acceleration of the chassis for the moveTo and travel methods
      void setAngularAcceleration​(double angularAcceleration)
      Sets the angular acceleration as is used in travel, arc, rotate and setvelocity methods
      void setAngularSpeed​(double angularSpeed)
      Sets the angular speed as is used in travel, arc, and rotate methods
      void setLinearAcceleration​(double linearAcceleration)
      Sets the linear acceleration as is used in travel, arc, rotate and setvelocity methods
      void setLinearSpeed​(double linearSpeed)
      Sets the linear speed as is used in travel, arc, and rotate methods
      protected void setMotors​(Matrix motorDelta, Matrix motorSpeed, Matrix motorAcceleration)
      Utility method to set distance, speed and acceleration for each motor
      void setSpeed​(double linearSpeed, double angularSpeed)
      Sets the speed of the chassis for the moveTo method
      void setVelocity​(double linearSpeed, double angularSpeed)
      Moves the chassis with specified speed
      void setVelocity​(double linearSpeed, double direction, double angularSpeed)
      Moves a holonomic chassis with specified speed
      void stop()
      Makes the robot stop and returns immediately.
      protected Matrix toCartesianMatrix​(double radius, double direction, double angular)  
      protected Matrix toMatrix​(double x, double y, double angular)
      Create a Matrix to store linear and angular components
      protected Matrix toPolar​(double x, double y, double angular)  
      void travel​(double linear)
      Moves the chassis the specified distance
      void travelCartesian​(double xSpeed, double ySpeed, double angularSpeed)
      Moves a holonomic robot with the specified speed.
      void waitComplete()
      Blocks while the chassis is moving, returns when all wheels have stopped (including stops caused by stalls)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • dummyWheels

        protected final int dummyWheels
        The program adds a dummy wheel to a differential chassis. This dummy wheel makes it possible to use linear algebra on three elements (x, y, angle) for the differential chassis. The y value is always zero for a differential chassis.
      • linearSpeed

        protected double linearSpeed
      • angularSpeed

        protected double angularSpeed
      • linearAcceleration

        protected double linearAcceleration
      • angularAcceleration

        protected double angularAcceleration
      • forward

        protected final Matrix forward
      • reverse

        protected final Matrix reverse
      • tachoAtMoveStart

        protected Matrix tachoAtMoveStart
      • forwardAbs

        protected final Matrix forwardAbs
      • reverseAbs

        protected final Matrix reverseAbs
      • odometer

        protected lejos.robotics.chassis.WheeledChassis.Odometer odometer
    • Constructor Detail

      • WheeledChassis

        public WheeledChassis​(Wheel[] wheels,
                              int dim)
    • Method Detail

      • getLinearSpeed

        public double getLinearSpeed()
        Description copied from interface: Chassis
        Gets the setting for linear speed as is used in moveTo, Arc, and Rotate methods
        Specified by:
        getLinearSpeed in interface Chassis
        Returns:
        Linear speed in robot units/second
      • setLinearSpeed

        public void setLinearSpeed​(double linearSpeed)
        Description copied from interface: Chassis
        Sets the linear speed as is used in travel, arc, and rotate methods
        Specified by:
        setLinearSpeed in interface Chassis
        Parameters:
        linearSpeed - Linear speed in robot units/second
      • getAngularSpeed

        public double getAngularSpeed()
        Description copied from interface: Chassis
        Gets the setting for angular speed as is used in travel, arc, and rotate methods
        Specified by:
        getAngularSpeed in interface Chassis
        Returns:
        Angular speed in degrees/second.
      • setAngularSpeed

        public void setAngularSpeed​(double angularSpeed)
        Description copied from interface: Chassis
        Sets the angular speed as is used in travel, arc, and rotate methods
        Specified by:
        setAngularSpeed in interface Chassis
        Parameters:
        angularSpeed - Angular speed in degrees/second.
      • getLinearAcceleration

        public double getLinearAcceleration()
        Description copied from interface: Chassis
        Gets the setting for linear acceleration as is used in travel, arc, rotate and setvelocity methods
        Specified by:
        getLinearAcceleration in interface Chassis
        Returns:
        Linear acceleration in robot units/second^2
      • setLinearAcceleration

        public void setLinearAcceleration​(double linearAcceleration)
        Description copied from interface: Chassis
        Sets the linear acceleration as is used in travel, arc, rotate and setvelocity methods
        Specified by:
        setLinearAcceleration in interface Chassis
        Parameters:
        linearAcceleration - Linear acceleration in robot units/second^2
      • getAngularAcceleration

        public double getAngularAcceleration()
        Description copied from interface: Chassis
        Gets the setting for angular acceleration as is used in travel, arc, rotate and setvelocity methods
        Specified by:
        getAngularAcceleration in interface Chassis
        Returns:
        Angular acceleration in degrees/second^2.
      • setAngularAcceleration

        public void setAngularAcceleration​(double angularAcceleration)
        Description copied from interface: Chassis
        Sets the angular acceleration as is used in travel, arc, rotate and setvelocity methods
        Specified by:
        setAngularAcceleration in interface Chassis
        Parameters:
        angularAcceleration - Angular Acceleration in degrees/second^2.
      • getForward

        public Matrix getForward()
      • getReverse

        public Matrix getReverse()
      • setSpeed

        public void setSpeed​(double linearSpeed,
                             double angularSpeed)
        Description copied from interface: Chassis
        Sets the speed of the chassis for the moveTo method
        Specified by:
        setSpeed in interface Chassis
        Parameters:
        linearSpeed - linear component of the robot speed, expressed in the same unit as the wheel diameter.
        angularSpeed - angular component of the robot speed expressed in degrees/second.
      • setAcceleration

        public void setAcceleration​(double linearAcceleration,
                                    double angularAcceleration)
        Description copied from interface: Chassis
        Sets the acceleration of the chassis for the moveTo and travel methods
        Specified by:
        setAcceleration in interface Chassis
        Parameters:
        linearAcceleration - linear component of the robot acceleration, expressed in robot units/second^2.
        angularAcceleration - angular component of the robot speed expressed acceleration, expressed in degrees/second^2.
      • isMoving

        public boolean isMoving()
        Description copied from interface: Chassis
        Returns true if the robot is moving.
        Specified by:
        isMoving in interface Chassis
        Returns:
        true if the robot is moving
      • waitComplete

        public void waitComplete()
        Description copied from interface: Chassis
        Blocks while the chassis is moving, returns when all wheels have stopped (including stops caused by stalls)
        Specified by:
        waitComplete in interface Chassis
      • isStalled

        public boolean isStalled()
        Description copied from interface: Chassis
        Returns true if at least one of the wheels is stalled
        Specified by:
        isStalled in interface Chassis
        Returns:
        true if at least one of the wheels is stalled
      • getMinRadius

        public double getMinRadius()
        Description copied from interface: Chassis
        Returns the smallest possible radius this chassis is able turn
        Specified by:
        getMinRadius in interface Chassis
        Returns:
        radius in robot units
      • stop

        public void stop()
        Description copied from interface: Chassis
        Makes the robot stop and returns immediately.
        Specified by:
        stop in interface Chassis
      • setVelocity

        public void setVelocity​(double linearSpeed,
                                double angularSpeed)
        Description copied from interface: Chassis
        Moves the chassis with specified speed
        Specified by:
        setVelocity in interface Chassis
        Parameters:
        linearSpeed - linear component of the robot speed, expressed in the same unit as the wheel diameter.
        angularSpeed - angular component of the robot speed expressed in degrees/second.
      • travelCartesian

        public void travelCartesian​(double xSpeed,
                                    double ySpeed,
                                    double angularSpeed)
        Description copied from interface: Chassis
        Moves a holonomic robot with the specified speed.
        The method will throw an exception when issued on a differential chassis.
        Specified by:
        travelCartesian in interface Chassis
        Parameters:
        xSpeed - speed along the robots x-axis
        ySpeed - speed along the robots y-axis
        angularSpeed - angular component of the robot speed expressed in degrees/second.
      • setVelocity

        public void setVelocity​(double linearSpeed,
                                double direction,
                                double angularSpeed)
        Description copied from interface: Chassis
        Moves a holonomic chassis with specified speed
        Specified by:
        setVelocity in interface Chassis
        Parameters:
        linearSpeed - linear component of the robot speed, expressed in the same unit as the wheel diameter.
        direction - The direction of the linear speed
        angularSpeed - angular component of the robot speed expressed in degrees/second.
      • travel

        public void travel​(double linear)
        Description copied from interface: Chassis
        Moves the chassis the specified distance
        Specified by:
        travel in interface Chassis
        Parameters:
        linear - linear component of the robot speed, expressed in the same unit as the wheel diameter.
      • rotate

        public void rotate​(double angular)
        Description copied from interface: Chassis
        Rotates the chassis for the specified number of degrees
        Specified by:
        rotate in interface Chassis
      • arc

        public void arc​(double radius,
                        double angle)
        Description copied from interface: Chassis
        Moves the chassis in an arc
        Specified by:
        arc in interface Chassis
        Parameters:
        radius - the radius of the arc. A positive radius means the center of the arc is on the left side of the robot, the center of a negative arc is on the right side of the robot. Infinite radius is not allowed. A radius of 0 makes the robot spin in place.
        angle - The number of degrees of the arc. A positive number of degrees makes the robot go forward, a negative number makes it go backward.
      • setMotors

        protected void setMotors​(Matrix motorDelta,
                                 Matrix motorSpeed,
                                 Matrix motorAcceleration)
        Utility method to set distance, speed and acceleration for each motor
        Parameters:
        motorDelta -
        motorSpeed -
        motorAcceleration -
      • getMaxLinearSpeed

        public double getMaxLinearSpeed()
        Description copied from interface: Chassis
        Returns the maximum speed of the robot.
        Specified by:
        getMaxLinearSpeed in interface Chassis
        Returns:
        Speed in robot units
      • getMaxAngularSpeed

        public double getMaxAngularSpeed()
        Description copied from interface: Chassis
        Returns how fast the robot can rotate.
        Specified by:
        getMaxAngularSpeed in interface Chassis
        Returns:
        Speed in degrees / second
      • getCurrentSpeed

        public Matrix getCurrentSpeed()
        Description copied from interface: Chassis
        Returns a matrix containing the current speed of the robot.
        Specified by:
        getCurrentSpeed in interface Chassis
        Returns:
        A matrix (3x1) containing the current speed of the robot. First row contains linear speed, second row contains direction of linear speed, third row contains angular speed.
      • getLinearVelocity

        public double getLinearVelocity()
        Description copied from interface: Chassis
        Returns the linear component of the current speed of the robot
        Specified by:
        getLinearVelocity in interface Chassis
        Returns:
        linear speed in robot units/second
      • getLinearDirection

        public double getLinearDirection()
        Description copied from interface: Chassis
        Returns the current direction of the linear speed component of the robot
        Specified by:
        getLinearDirection in interface Chassis
        Returns:
        direction in degrees
      • getAngularVelocity

        public double getAngularVelocity()
        Description copied from interface: Chassis
        Returns the angular component of the current speed of the robot
        Specified by:
        getAngularVelocity in interface Chassis
        Returns:
        Angular speed in degrees/second
      • moveStart

        public void moveStart()
        Description copied from interface: Chassis
        Method used by the MovePilot to tell the chassis that a new move has started. This method is used in conjuction with the getDisplacement method.
        Specified by:
        moveStart in interface Chassis
      • getDisplacement

        public Move getDisplacement​(Move move)
        Description copied from interface: Chassis
        Method used by the MovePilot to update a move object that describes the move executed since the last call to startMove.

        This method is only to be used by applications that apply just moves that meet the following conditions:

        • The move must start and end with the robot being motionless
        • The speed ratio between the wheels must be constant during the move
        Specified by:
        getDisplacement in interface Chassis
        Parameters:
        move - The move object to update
      • modelHolonomicWheel

        public static WheeledChassis.HolonomicModeler modelHolonomicWheel​(RegulatedMotor motor,
                                                                          double diameter)
        Provides a modeler object to model a Holonomic motorized wheel on the chassis
        Parameters:
        motor - The regulated motor that drives the wheel
        diameter - The diameter of the wheel in a unit of choice.
        Returns:
        the modeler
      • modelWheel

        public static WheeledChassis.Modeler modelWheel​(RegulatedMotor motor,
                                                        double diameter)
        Provides a modeler object to model a Holonomic motorized wheel on the chassis
        Parameters:
        motor - The regulated motor that drives the wheel
        diameter - The diameter of the wheel in a unit of choice.
        Returns:
        the modeler
      • getPoseProvider

        public PoseProvider getPoseProvider()
        Description copied from interface: Chassis
        Returns an Pose provider that uses odometry to keep track of the pose of the chassis
        Specified by:
        getPoseProvider in interface Chassis
        Returns:
        an Pose provider that uses odometry to keep track of the pose of the chassis
      • toMatrix

        protected Matrix toMatrix​(double x,
                                  double y,
                                  double angular)
        Create a Matrix to store linear and angular components
        Parameters:
        x -
        y -
        angular -
        Returns:
        the modeler
      • toCartesianMatrix

        protected Matrix toCartesianMatrix​(double radius,
                                           double direction,
                                           double angular)
      • toPolar

        protected Matrix toPolar​(double x,
                                 double y,
                                 double angular)
      • getAttribute

        protected Matrix getAttribute​(int attribute)
        Helper method to get some dynamic attributes from each motor
        Parameters:
        attribute -
        Returns:
        the mmatrix
      • getMax

        protected double getMax​(Matrix a)
        Gets the biggest value from a matrix
        Parameters:
        a -
      • copyAbsolute

        protected Matrix copyAbsolute​(Matrix in)
        Make a copy of the source matrix, each of its element being the absolute value of the elements of the source matrix
        Parameters:
        in -
        Returns:
        the matrix