|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorbotix.robot.base.DriveControl
public class DriveControl
Singleton to manage driving a ball in touch(joystick) or with accelerometer data.
This class simplifies driving a robot by setting up input sensors and maintaining driving state through a simple interface.
Nested Class Summary | |
---|---|
static interface |
DriveControl.ConnectionListener
Interface to update a listener of connection events. |
Field Summary | |
---|---|
static DriveControl |
INSTANCE
Singleton instance of the class |
static int |
JOY_STICK
Constant for driving with a touch(joystick) algorithm |
static int |
RC
Constant for driving with an RC Car like interface |
static int |
TILT
Constant for driving with accelerometer data |
Method Summary | |
---|---|
void |
connectRobot()
Start game play. |
void |
disableDirectionalDrive(android.content.Context context)
Disables any active automatic heading correction based on the device's sensors. |
void |
disconnectRobot()
Stop game play. |
DriveAlgorithm |
driveAlgorithm()
Accessor to the DriveAlgorithm object used for driving the robot with the accelerometer or a touch based joy stick. |
void |
driveJoyStick(double x,
double y)
Method to update the position of a joy stick control and motion of a robot based on the new position. |
void |
driveRc(double x,
double y)
Method to update the motion of a robot based on the new gas and steering values. |
void |
enableDirectionalDrive(android.content.Context context)
Attempts to enable the automatic heading correction based on the device's sensors. |
android.content.Context |
getBroadcastContext()
Accessor to the context the framework uses for broadcasting events on. |
Robot |
getRobot()
The Robot object that is being controlled. |
RobotControl |
getRobotControl()
The RobotControl object that is being used to drive the device. |
RobotProvider |
getRobotProvider()
Accessor to the RobotProvider object. |
boolean |
hasRobotControl()
Test if a robot is under control. |
java.lang.Boolean |
isDriving()
Test if the game is in full stop. |
void |
onAccuracyChanged(android.hardware.Sensor sensor,
int accuracy)
Required by the SensorEventListener interface, however this method does nothing. |
void |
onSensorChanged(android.hardware.SensorEvent event)
Implementation of the SensorEventListener interface for receiving accelerometer data when driving in tilt mode. |
void |
setBroadcastContext(android.content.Context context)
Method for setting a context which is used by the framework to send broadcast messages for events. |
void |
setConnectionListener(DriveControl.ConnectionListener listener)
Method to register a ConnectionListener object to listen for connection events. |
void |
setJoyStickPadSize(double width,
double height)
Method to set the area used by a joy stick pad, which is used when creating the JoyStickDriveAlgorithm. |
void |
setOnConvertListener(DriveAlgorithm.OnConvertListener listener)
Method to register a DriveAlgorithm.OnConvertListener object that is passed to DriveAlgorithm objects that the DriveControll object creates. |
void |
setSpeedScale(double scale)
Method to set the speed scale which limits the maximum speed the device can travel at. |
void |
startDriving(android.content.Context context,
int driveMode)
Prepares to start driving a robot. |
void |
stopDriving()
Stop driving a robot by stopping the motor and accelerometer updates. |
void |
update(java.util.Observable observable,
java.lang.Object data)
Watches for changes in the robot state. |
void |
updateCalibratedHeading()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int JOY_STICK
public static final int TILT
public static final int RC
public static final DriveControl INSTANCE
Method Detail |
---|
public void setConnectionListener(DriveControl.ConnectionListener listener)
listener
- The ConnectionListener object.public void setBroadcastContext(android.content.Context context)
context
- The context to broadcast events.public android.content.Context getBroadcastContext()
public boolean hasRobotControl()
public RobotProvider getRobotProvider()
public RobotControl getRobotControl()
public Robot getRobot()
public void setOnConvertListener(DriveAlgorithm.OnConvertListener listener)
listener
- A DriveAlgorithm.OnConvertListener object.public void setJoyStickPadSize(double width, double height)
width
- The width of the joy stick area.height
- The height of the joy stick area.public void setSpeedScale(double scale)
scale
- A value from 0.0 to 1.0 which is multiplied with the driving speed.public DriveAlgorithm driveAlgorithm()
public void connectRobot()
public void disconnectRobot()
public void startDriving(android.content.Context context, int driveMode)
context
- The context for obtaining input resources from.public void enableDirectionalDrive(android.content.Context context)
SensorManager.getOrientation(float[], float[])
. If there is an accelerometer but
no magnetometer then a static heading will be set for the magnetometer data which will allow
for rough heading changes. As of June 2011, almost every Android device released with a
magnetometer also has at least an accelerometer, so a compass-only method of heading correction is
not currently implemented. If nothing is present, automatic heading correction
will be turned off.
context
- the context from which to get the sensors.public void disableDirectionalDrive(android.content.Context context)
context
- the context from which to get the sensors.public void driveJoyStick(double x, double y)
x
- The x value inside a joy stick control's view area.y
- The y value inside a joy stick control's view area.public void driveRc(double x, double y)
x
- The gas value from 0.0 to 1.0.y
- The steering value from -1.0 to 1.0.public void stopDriving()
public java.lang.Boolean isDriving()
public void onSensorChanged(android.hardware.SensorEvent event)
onSensorChanged
in interface android.hardware.SensorEventListener
public void updateCalibratedHeading()
public void onAccuracyChanged(android.hardware.Sensor sensor, int accuracy)
onAccuracyChanged
in interface android.hardware.SensorEventListener
public void update(java.util.Observable observable, java.lang.Object data)
update
in interface java.util.Observer
observable
- A robot whose state has changed.data
- not used
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |