Controlling Wheeled Vehicles
|
Controlling Wheeled Vehicles
A common type of robot is the two wheeled vehicle with independently controlled motors. This design uses differential steering and can turn in place. leJOS NXJ contains several classes that control it. PilotThe Pilot class steers the vehicle by controlling the speed and direction of rotation of its motors. The pilot needs to know the wiring diagram of the robot, i.e. which ports the motors are connected to and whether driving the motors forward makes the robot move forward or backward (reverse). It also needs to know the diameter of the wheels and the width of the track, i.e. the distance between the centres of the tracks of the two wheels. The Pilot uses the wheel diameter to calculate the distance it has traveled. It uses the ratio to calculate how far it has rotated. Obviously, both parameters must be in the same units, but they can be anything you wish. With proper adjustment of these parameters, errors in distance traveled and angle of rotation can be held do 2% or perhaps less. This information is passed to the pilot constructor. Constructors:
Straight line movementTo control the robot moving in a straight line, use:
To control the distance the robot moves, use:
Example:
You can cause the robot to rotate in place by a specified angle by using
Program SquareTracerWrite a program that uses a Pilot to trace out a square, using the travel and rotate methods. Program SquareTracer2Write a program that traces 2 squares with increasing angle at the corners, then retraces the same path in the opposite direction.. Modify the traceSquare method of program Pilot 1 so it can trace a square in either direction, and use it in this program. This is stringent test of the accuracy of the wheel diameter and track width constants you use in you pilot. Movement along a curved pathThe pilot can turn the robot in place by driving one wheel forward and the other backward. The methods that do it are:
The Pilot can also control the robot to move in a circular path using these methods:
The turnRate parameter determines the radius of the path. A positive value means that center of the circle is to the left of the robot (so the left motor drives the inside wheel). A negative value means the left motor is the outside wheel. The absolute value is between 0 and 200, and this determines the ratio of inside to outside motor speed. The outside motor runs at the set speed of the robot; the inner motor is slowed down to make the robot turn. At turn rate 0, the speed ratio is 1.0 and the robot travels in a straight line. At turn rate 200, the speed ratio is -1 and the robot turns in place. Turn rate 100 gives speed ratio 0, so the inside motor stops. The formula is: speed ratio = 100 - abs(turnRate). The angle parameter determines the rotation angle at which the robot stops. If the angle is negative, the robot follows the circular path defined by the turn rate, but it moves backwards.
Program SteerTesterWrite a program that uses the ButtonCounter to enter the turn rate and angle variables, and then calls the steer() method. It does this in a loop so you can try different values of these parameters to control the robot path. Other methods for Pilot
If you really need to deal with individual motors, you can use:
Compass PilotThe CompassPilot is an extension of the Pilot class. It implements the same methods, but uses a Compass Sensor to ensure that the pilot does not deviate from the correct angle of robot heading. It needs a HiTechnic or Mindsensors compass sensor plugged in to one of the sensor ports. Its constructors are similar those of Pilot, but with the additional information of the compass sensor port. Constructors:
Additional methods in CompassPilot:
Additional methods in CompassPilot:Write a program that does these steps:
Suggestion: while the robot is moving, nudge it off course and watch it steer back to the correct heading. Back to topTacho NavigatorThere are three abstraction layers of classes that control two wheeled vehicles. This architecture allows you to pick the layer that most useful for your application and not be concerned with the lower layers. The Tacho Navigator implements the Navigator interface which defines methods for the basic navigational tasks. The navigator keeps track of the robot’s coordinates (x, and y) and its heading angle (the direction it is facing ). It uses Cartesian coordinates, with angles in degrees; 0 degrees is the direction of the positive x axis, 90 degrees is the positive y axis. Since a TachoNavigator needs a Pilot to control the vehicle, it implements the common Pilot movement commands that you might want to use. Constructors:
Alternatively, you can use a constructor that creates a pilot from the information you supply. The parameter list is the same as in the Pilot constructors.
Basic navigational methodsMethods to set and get the robot position and its components:
Methods to get the angle and distance to a point with coordinates (x,y):
Updating the robot position (x,y and angle)
Controlling the robot movement in the planeAs with the Pilot class, the Navigator movement control methods have two versions. One version returns only after the movement is complete and the robot position has been updated. The other version has the option of initiating the movement and returning immediately. When you use this option, you must be sure the robot position is updated before it moves again. The methods that automatically call updatePosition() before returning are:
The methods that require you to call updatePosition when the movement is complete include the methods when called with immediateReturn set to true
Program: Tacho Navigator TestWrite a program that performs the following steps:
Compass NavigatorThe compass navigator is a sub class of TachoNavigator, and as such, implements all the TachoNavigator methods. Constructors:
Alternatively, you can use a constructor that creates a pilot from the information you supply. The parameter list is the same as in the CompassPilot constructors.
Other Methods:
Program: Compass Navigator TestWrite a program for the CompassNavigator that does the same steps as for the TachoNavigator. Back to top |