public class WheeledChassis extends java.lang.Object implements Chassis
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
WheeledChassis.HolonomicModeler
The Modeler class helps to model a wheel.
|
static class |
WheeledChassis.Modeler
The Modeler class helps to model a wheel.
|
| Modifier and Type | Field and Description |
|---|---|
protected double |
angularAcceleration |
protected double |
angularSpeed |
protected int |
dummyWheels
The program adds a dummy wheel to a differential chassis.
|
protected Matrix |
forward |
protected Matrix |
forwardAbs |
protected double |
linearAcceleration |
protected double |
linearSpeed |
protected RegulatedMotor |
master |
protected static int |
MAXSPEED |
protected RegulatedMotor[] |
motor |
protected lejos.robotics.chassis.WheeledChassis.Odometer |
odometer |
protected Matrix |
reverse |
protected Matrix |
reverseAbs |
protected static int |
ROTATIONSPEED |
protected Matrix |
tachoAtMoveStart |
protected static int |
TACHOCOUNT |
static int |
TYPE_DIFFERENTIAL |
static int |
TYPE_HOLONOMIC |
| Constructor and Description |
|---|
WheeledChassis(Wheel[] wheels,
int dim) |
| Modifier and Type | Method and 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)
|
protected static final int TACHOCOUNT
protected static final int MAXSPEED
protected static final int ROTATIONSPEED
public static final int TYPE_DIFFERENTIAL
public static final int TYPE_HOLONOMIC
protected final int dummyWheels
protected final RegulatedMotor[] motor
protected double linearSpeed
protected double angularSpeed
protected double linearAcceleration
protected double angularAcceleration
protected final Matrix forward
protected final Matrix reverse
protected RegulatedMotor master
protected Matrix tachoAtMoveStart
protected final Matrix forwardAbs
protected final Matrix reverseAbs
protected lejos.robotics.chassis.WheeledChassis.Odometer odometer
public WheeledChassis(Wheel[] wheels, int dim)
public double getLinearSpeed()
ChassisgetLinearSpeed in interface Chassispublic void setLinearSpeed(double linearSpeed)
ChassissetLinearSpeed in interface ChassislinearSpeed - Linear speed in robot units/secondpublic double getAngularSpeed()
ChassisgetAngularSpeed in interface Chassispublic void setAngularSpeed(double angularSpeed)
ChassissetAngularSpeed in interface ChassisangularSpeed - Angular speed in degrees/second.public double getLinearAcceleration()
ChassisgetLinearAcceleration in interface Chassispublic void setLinearAcceleration(double linearAcceleration)
ChassissetLinearAcceleration in interface ChassislinearAcceleration - Linear acceleration in robot units/second^2public double getAngularAcceleration()
ChassisgetAngularAcceleration in interface Chassispublic void setAngularAcceleration(double angularAcceleration)
ChassissetAngularAcceleration in interface ChassisangularAcceleration - Angular Acceleration in degrees/second^2.public Matrix getForward()
public Matrix getReverse()
public void setSpeed(double linearSpeed,
double angularSpeed)
Chassispublic void setAcceleration(double linearAcceleration,
double angularAcceleration)
ChassissetAcceleration in interface ChassislinearAcceleration - 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.public boolean isMoving()
Chassispublic void waitComplete()
ChassiswaitComplete in interface Chassispublic boolean isStalled()
Chassispublic double getMinRadius()
ChassisgetMinRadius in interface Chassispublic void stop()
Chassispublic void setVelocity(double linearSpeed,
double angularSpeed)
ChassissetVelocity in interface ChassislinearSpeed - 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.public void travelCartesian(double xSpeed,
double ySpeed,
double angularSpeed)
ChassistravelCartesian in interface ChassisxSpeed - speed along the robots x-axisySpeed - speed along the robots y-axisangularSpeed - angular component of the robot speed expressed in degrees/second.public void setVelocity(double linearSpeed,
double direction,
double angularSpeed)
ChassissetVelocity in interface ChassislinearSpeed - 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.public void travel(double linear)
Chassispublic void rotate(double angular)
Chassispublic void arc(double radius,
double angle)
Chassisarc in interface Chassisradius - 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.protected void setMotors(Matrix motorDelta, Matrix motorSpeed, Matrix motorAcceleration)
motorDelta - motorSpeed - motorAcceleration - public double getMaxLinearSpeed()
ChassisgetMaxLinearSpeed in interface Chassispublic double getMaxAngularSpeed()
ChassisgetMaxAngularSpeed in interface Chassispublic Matrix getCurrentSpeed()
ChassisgetCurrentSpeed in interface Chassispublic double getLinearVelocity()
ChassisgetLinearVelocity in interface Chassispublic double getLinearDirection()
ChassisgetLinearDirection in interface Chassispublic double getAngularVelocity()
ChassisgetAngularVelocity in interface Chassispublic void moveStart()
Chassispublic Move getDisplacement(Move move)
ChassisThis method is only to be used by applications that apply just moves that meet the following conditions:
getDisplacement in interface Chassismove - The move object to updatepublic static WheeledChassis.HolonomicModeler modelHolonomicWheel(RegulatedMotor motor, double diameter)
motor - The regulated motor that drives the wheeldiameter - The diameter of the wheel in a unit of choice.public static WheeledChassis.Modeler modelWheel(RegulatedMotor motor, double diameter)
motor - The regulated motor that drives the wheeldiameter - The diameter of the wheel in a unit of choice.public PoseProvider getPoseProvider()
ChassisgetPoseProvider in interface Chassisprotected Matrix toMatrix(double x, double y, double angular)
x - y - angular - protected Matrix toCartesianMatrix(double radius, double direction, double angular)
protected Matrix toPolar(double x, double y, double angular)
protected Matrix getAttribute(int attribute)
attribute - protected double getMax(Matrix a)
a -