Class WheeledChassis
- java.lang.Object
-
- lejos.robotics.chassis.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 themodelWheel(lejos.robotics.RegulatedMotor, double)method. A modeler for a holonomic wheel can be obtained using themodelHolonomicWheel(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
*Chassisinterface.- Author:
- Aswin Bouwmeester
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWheeledChassis.HolonomicModelerThe Modeler class helps to model a wheel.static classWheeledChassis.ModelerThe Modeler class helps to model a wheel.
-
Field Summary
Fields Modifier and Type Field Description protected doubleangularAccelerationprotected doubleangularSpeedprotected intdummyWheelsThe program adds a dummy wheel to a differential chassis.protected Matrixforwardprotected MatrixforwardAbsprotected doublelinearAccelerationprotected doublelinearSpeedprotected RegulatedMotormasterprotected static intMAXSPEEDprotected RegulatedMotor[]motorprotected lejos.robotics.chassis.WheeledChassis.Odometerodometerprotected Matrixreverseprotected MatrixreverseAbsprotected static intROTATIONSPEEDprotected MatrixtachoAtMoveStartprotected static intTACHOCOUNTstatic intTYPE_DIFFERENTIALstatic intTYPE_HOLONOMIC
-
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 voidarc(double radius, double angle)Moves the chassis in an arcprotected MatrixcopyAbsolute(Matrix in)Make a copy of the source matrix, each of its element being the absolute value of the elements of the source matrixdoublegetAngularAcceleration()Gets the setting for angular acceleration as is used in travel, arc, rotate and setvelocity methodsdoublegetAngularSpeed()Gets the setting for angular speed as is used in travel, arc, and rotate methodsdoublegetAngularVelocity()Returns the angular component of the current speed of the robotprotected MatrixgetAttribute(int attribute)Helper method to get some dynamic attributes from each motorMatrixgetCurrentSpeed()Returns a matrix containing the current speed of the robot.MovegetDisplacement(Move move)Method used by the MovePilot to update a move object that describes the move executed since the last call to startMove.MatrixgetForward()doublegetLinearAcceleration()Gets the setting for linear acceleration as is used in travel, arc, rotate and setvelocity methodsdoublegetLinearDirection()Returns the current direction of the linear speed component of the robotdoublegetLinearSpeed()Gets the setting for linear speed as is used in moveTo, Arc, and Rotate methodsdoublegetLinearVelocity()Returns the linear component of the current speed of the robotprotected doublegetMax(Matrix a)Gets the biggest value from a matrixdoublegetMaxAngularSpeed()Returns how fast the robot can rotate.doublegetMaxLinearSpeed()Returns the maximum speed of the robot.doublegetMinRadius()Returns the smallest possible radius this chassis is able turnPoseProvidergetPoseProvider()Returns an Pose provider that uses odometry to keep track of the pose of the chassisMatrixgetReverse()booleanisMoving()Returns true if the robot is moving.booleanisStalled()Returns true if at least one of the wheels is stalledstatic WheeledChassis.HolonomicModelermodelHolonomicWheel(RegulatedMotor motor, double diameter)Provides a modeler object to model a Holonomic motorized wheel on the chassisstatic WheeledChassis.ModelermodelWheel(RegulatedMotor motor, double diameter)Provides a modeler object to model a Holonomic motorized wheel on the chassisvoidmoveStart()Method used by the MovePilot to tell the chassis that a new move has started.voidrotate(double angular)Rotates the chassis for the specified number of degreesvoidsetAcceleration(double linearAcceleration, double angularAcceleration)Sets the acceleration of the chassis for the moveTo and travel methodsvoidsetAngularAcceleration(double angularAcceleration)Sets the angular acceleration as is used in travel, arc, rotate and setvelocity methodsvoidsetAngularSpeed(double angularSpeed)Sets the angular speed as is used in travel, arc, and rotate methodsvoidsetLinearAcceleration(double linearAcceleration)Sets the linear acceleration as is used in travel, arc, rotate and setvelocity methodsvoidsetLinearSpeed(double linearSpeed)Sets the linear speed as is used in travel, arc, and rotate methodsprotected voidsetMotors(Matrix motorDelta, Matrix motorSpeed, Matrix motorAcceleration)Utility method to set distance, speed and acceleration for each motorvoidsetSpeed(double linearSpeed, double angularSpeed)Sets the speed of the chassis for the moveTo methodvoidsetVelocity(double linearSpeed, double angularSpeed)Moves the chassis with specified speedvoidsetVelocity(double linearSpeed, double direction, double angularSpeed)Moves a holonomic chassis with specified speedvoidstop()Makes the robot stop and returns immediately.protected MatrixtoCartesianMatrix(double radius, double direction, double angular)protected MatrixtoMatrix(double x, double y, double angular)Create a Matrix to store linear and angular componentsprotected MatrixtoPolar(double x, double y, double angular)voidtravel(double linear)Moves the chassis the specified distancevoidtravelCartesian(double xSpeed, double ySpeed, double angularSpeed)Moves a holonomic robot with the specified speed.voidwaitComplete()Blocks while the chassis is moving, returns when all wheels have stopped (including stops caused by stalls)
-
-
-
Field Detail
-
TACHOCOUNT
protected static final int TACHOCOUNT
- See Also:
- Constant Field Values
-
MAXSPEED
protected static final int MAXSPEED
- See Also:
- Constant Field Values
-
ROTATIONSPEED
protected static final int ROTATIONSPEED
- See Also:
- Constant Field Values
-
TYPE_DIFFERENTIAL
public static final int TYPE_DIFFERENTIAL
- See Also:
- Constant Field Values
-
TYPE_HOLONOMIC
public static final int TYPE_HOLONOMIC
- See Also:
- Constant Field Values
-
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.
-
motor
protected final RegulatedMotor[] motor
-
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
-
master
protected RegulatedMotor master
-
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:ChassisGets the setting for linear speed as is used in moveTo, Arc, and Rotate methods- Specified by:
getLinearSpeedin interfaceChassis- Returns:
- Linear speed in robot units/second
-
setLinearSpeed
public void setLinearSpeed(double linearSpeed)
Description copied from interface:ChassisSets the linear speed as is used in travel, arc, and rotate methods- Specified by:
setLinearSpeedin interfaceChassis- Parameters:
linearSpeed- Linear speed in robot units/second
-
getAngularSpeed
public double getAngularSpeed()
Description copied from interface:ChassisGets the setting for angular speed as is used in travel, arc, and rotate methods- Specified by:
getAngularSpeedin interfaceChassis- Returns:
- Angular speed in degrees/second.
-
setAngularSpeed
public void setAngularSpeed(double angularSpeed)
Description copied from interface:ChassisSets the angular speed as is used in travel, arc, and rotate methods- Specified by:
setAngularSpeedin interfaceChassis- Parameters:
angularSpeed- Angular speed in degrees/second.
-
getLinearAcceleration
public double getLinearAcceleration()
Description copied from interface:ChassisGets the setting for linear acceleration as is used in travel, arc, rotate and setvelocity methods- Specified by:
getLinearAccelerationin interfaceChassis- Returns:
- Linear acceleration in robot units/second^2
-
setLinearAcceleration
public void setLinearAcceleration(double linearAcceleration)
Description copied from interface:ChassisSets the linear acceleration as is used in travel, arc, rotate and setvelocity methods- Specified by:
setLinearAccelerationin interfaceChassis- Parameters:
linearAcceleration- Linear acceleration in robot units/second^2
-
getAngularAcceleration
public double getAngularAcceleration()
Description copied from interface:ChassisGets the setting for angular acceleration as is used in travel, arc, rotate and setvelocity methods- Specified by:
getAngularAccelerationin interfaceChassis- Returns:
- Angular acceleration in degrees/second^2.
-
setAngularAcceleration
public void setAngularAcceleration(double angularAcceleration)
Description copied from interface:ChassisSets the angular acceleration as is used in travel, arc, rotate and setvelocity methods- Specified by:
setAngularAccelerationin interfaceChassis- 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:ChassisSets the speed of the chassis for the moveTo method
-
setAcceleration
public void setAcceleration(double linearAcceleration, double angularAcceleration)Description copied from interface:ChassisSets the acceleration of the chassis for the moveTo and travel methods- Specified by:
setAccelerationin interfaceChassis- 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:ChassisReturns true if the robot is moving.
-
waitComplete
public void waitComplete()
Description copied from interface:ChassisBlocks while the chassis is moving, returns when all wheels have stopped (including stops caused by stalls)- Specified by:
waitCompletein interfaceChassis
-
isStalled
public boolean isStalled()
Description copied from interface:ChassisReturns true if at least one of the wheels is stalled
-
getMinRadius
public double getMinRadius()
Description copied from interface:ChassisReturns the smallest possible radius this chassis is able turn- Specified by:
getMinRadiusin interfaceChassis- Returns:
- radius in robot units
-
stop
public void stop()
Description copied from interface:ChassisMakes the robot stop and returns immediately.
-
setVelocity
public void setVelocity(double linearSpeed, double angularSpeed)Description copied from interface:ChassisMoves the chassis with specified speed- Specified by:
setVelocityin interfaceChassis- 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:ChassisMoves a holonomic robot with the specified speed.
The method will throw an exception when issued on a differential chassis.- Specified by:
travelCartesianin interfaceChassis- Parameters:
xSpeed- speed along the robots x-axisySpeed- speed along the robots y-axisangularSpeed- angular component of the robot speed expressed in degrees/second.
-
setVelocity
public void setVelocity(double linearSpeed, double direction, double angularSpeed)Description copied from interface:ChassisMoves a holonomic chassis with specified speed- Specified by:
setVelocityin interfaceChassis- Parameters:
linearSpeed- linear component of the robot speed, expressed in the same unit as the wheel diameter.direction- The direction of the linear speedangularSpeed- angular component of the robot speed expressed in degrees/second.
-
travel
public void travel(double linear)
Description copied from interface:ChassisMoves the chassis the specified distance
-
rotate
public void rotate(double angular)
Description copied from interface:ChassisRotates the chassis for the specified number of degrees
-
arc
public void arc(double radius, double angle)Description copied from interface:ChassisMoves the chassis in an arc- Specified by:
arcin interfaceChassis- 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:ChassisReturns the maximum speed of the robot.- Specified by:
getMaxLinearSpeedin interfaceChassis- Returns:
- Speed in robot units
-
getMaxAngularSpeed
public double getMaxAngularSpeed()
Description copied from interface:ChassisReturns how fast the robot can rotate.- Specified by:
getMaxAngularSpeedin interfaceChassis- Returns:
- Speed in degrees / second
-
getCurrentSpeed
public Matrix getCurrentSpeed()
Description copied from interface:ChassisReturns a matrix containing the current speed of the robot.- Specified by:
getCurrentSpeedin interfaceChassis- 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:ChassisReturns the linear component of the current speed of the robot- Specified by:
getLinearVelocityin interfaceChassis- Returns:
- linear speed in robot units/second
-
getLinearDirection
public double getLinearDirection()
Description copied from interface:ChassisReturns the current direction of the linear speed component of the robot- Specified by:
getLinearDirectionin interfaceChassis- Returns:
- direction in degrees
-
getAngularVelocity
public double getAngularVelocity()
Description copied from interface:ChassisReturns the angular component of the current speed of the robot- Specified by:
getAngularVelocityin interfaceChassis- Returns:
- Angular speed in degrees/second
-
moveStart
public void moveStart()
Description copied from interface:ChassisMethod used by the MovePilot to tell the chassis that a new move has started. This method is used in conjuction with the getDisplacement method.
-
getDisplacement
public Move getDisplacement(Move move)
Description copied from interface:ChassisMethod 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:
getDisplacementin interfaceChassis- 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 wheeldiameter- 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 wheeldiameter- The diameter of the wheel in a unit of choice.- Returns:
- the modeler
-
getPoseProvider
public PoseProvider getPoseProvider()
Description copied from interface:ChassisReturns an Pose provider that uses odometry to keep track of the pose of the chassis- Specified by:
getPoseProviderin interfaceChassis- 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-
-
-