Skip to content
This repository has been archived by the owner on Dec 31, 2019. It is now read-only.

Commit

Permalink
Made all Sphero objects referenced by mRobot for consistency.
Browse files Browse the repository at this point in the history
  • Loading branch information
zenelk committed Nov 18, 2013
1 parent d8cb84e commit 6d5e6b3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions samples/ButtonDrive/README.md
Expand Up @@ -11,9 +11,9 @@ You can see from the diagram how Sphero's roll commands correspond to its headin
This code sample demonstrates driving a Sphero by sending roll commands at 0°, 90°, 180°, and 270°. The roll command
takes a heading from 0° to 360°, and a relative speed from 0.0 to 1.0. Assuming you have a Sphero object called myRobot that is initialized, to command the ball to go 90° at half speed would be:

myRobot.drive(90.0, 0.5);
mRobot.drive(90.0, 0.5);

The ball is stopped with the `myRobot.stop()` call.
The ball is stopped with the `mRobot.stop()` call.

## Questions

Expand Down
4 changes: 2 additions & 2 deletions samples/Locator/README.md
Expand Up @@ -15,13 +15,13 @@

Assuming you already have a Sphero object that is connected, attaching the listener is done with this line.

mSphero.getSensorControl().addLocatorListener(mLocatorListener);
mRobot.getSensorControl().addLocatorListener(mLocatorListener);

## Configuring the Data Streaming Listener

Now that the listener is connected, you must set the data streaming rate (at the least). The maximum sensor sampling rate is ~420 Hz, but we recommend using a value in the 20-40Hz range for Android devices. At 20 Hz, virtually every device will not see a slowdown from the packet detection. However, 40 Hz is only viable when targeting only high-end devices. To set the streaming value, use the `setRate(int hz)` member method of the *SensorControl* class of the Sphero.

mSphero.getSensorControl().setRate(20 /*Hz*/);
mRobot.getSensorControl().setRate(20 /*Hz*/);

Now you're set to receive locator data from the Sphero!
## Interpreting Locator DataThe locator treats the ground as a 2D plane and provides Sphero’s position in X,Y coordinates. By default, roll heading 0, points down the positive Y-axis with positive X-axis to the right. So, if you shake Sphero awake and send a roll command with heading 0, you will see the Sphero’s Y coordinate counting up. If you then send a roll command with heading 90, Sphero’s X coordinate will count up.
Expand Down
28 changes: 14 additions & 14 deletions samples/Locator/src/com/orbotix/sample/locator/LocatorActivity.java
Expand Up @@ -21,7 +21,7 @@ public class LocatorActivity extends Activity {

private static final String TAG = "OBX-LocatorSample";
/** Robot to from which we are streaming */
private Sphero mSphero = null;
private Sphero mRobot = null;

/** The Sphero Connection View */
private SpheroConnectionView mSpheroConnectionView;
Expand Down Expand Up @@ -54,11 +54,11 @@ public void onCreate(Bundle savedInstanceState) {
mSpheroConnectionView.addConnectionListener(new ConnectionListener() {
@Override
public void onConnected(Robot sphero) {
mSphero = (Sphero) sphero;
mRobot = (Sphero) sphero;
// Skip this next step if you want the user to be able to connect multiple Spheros
mSpheroConnectionView.setVisibility(View.INVISIBLE);
mSphero.getSensorControl().addLocatorListener(mLocatorListener);
mSphero.getSensorControl().setRate(5);
mRobot.getSensorControl().addLocatorListener(mLocatorListener);
mRobot.getSensorControl().setRate(5);
}

@Override
Expand Down Expand Up @@ -86,9 +86,9 @@ protected void onResume() {
protected void onPause() {
super.onPause();
//Set the AsyncDataListener that will process each response.
if (mSphero != null) {
mSphero.getSensorControl().removeLocatorListener(mLocatorListener);
mSphero.disconnect(); // Disconnect Robot properly
if (mRobot != null) {
mRobot.getSensorControl().removeLocatorListener(mLocatorListener);
mRobot.disconnect(); // Disconnect Robot properly
}
}

Expand All @@ -99,7 +99,7 @@ protected void onPause() {
*/
public void configurePressed(View v) {

if (mSphero == null) return;
if (mRobot == null) return;

int newX = 0; // The locator's current X position value will be set to this value
int newY = 0; // The locator's current Y position value will be set to this value
Expand Down Expand Up @@ -128,26 +128,26 @@ public void configurePressed(View v) {
ConfigureLocatorCommand.ROTATE_WITH_CALIBRATE_FLAG_ON :
ConfigureLocatorCommand.ROTATE_WITH_CALIBRATE_FLAG_OFF;

ConfigureLocatorCommand.sendCommand(mSphero, flag, newX, newY, newYaw);
ConfigureLocatorCommand.sendCommand(mRobot, flag, newX, newY, newYaw);
}

public void upPressed(View v) {
mSphero.drive(0, .6f);
mRobot.drive(0, .6f);
}

public void rightPressed(View v) {
mSphero.drive(90, .6f);
mRobot.drive(90, .6f);
}

public void downPressed(View v) {
mSphero.drive(180, .6f);
mRobot.drive(180, .6f);
}

public void leftPressed(View v) {
mSphero.drive(270, .6f);
mRobot.drive(270, .6f);
}

public void stopPressed(View v) {
mSphero.stop();
mRobot.stop();
}
}
12 changes: 6 additions & 6 deletions samples/OptionFlags/README.md
Expand Up @@ -21,7 +21,7 @@ By default, your Sphero only has vector drive enabled.

To get the populate the current state of the persistent option flags, you now need only call `update()` on the *ConfigurationControl* of Sphero.

mSphero.getConfiguration().update();
mRobot.getConfiguration().update();

This will get the flags as soon as it can. To avoid a race condition, a listener for the response is needed. Setup a listener to listen for the *GetOptionFlagsResponse*.

Expand All @@ -37,18 +37,18 @@ This will get the flags as soon as it can. To avoid a race condition, a listener
Once the flags are populated, get a flag's state by using the `isPersistentFlagEnabled()` method like so:

// This gets the "prevent sleep in charger" flag, and returns true if it's enabled, saving it to the boolean.
Boolean preventSleepInChargerSet = mSphero.getConfiguration().isPersistentFlagEnabled(PersistentOptionFlags.PreventSleepInCharger);
Boolean preventSleepInChargerSet = mRobot.getConfiguration().isPersistentFlagEnabled(PersistentOptionFlags.PreventSleepInCharger);

Here we are getting the state of each option flag in a boolean variable which will be either false (off) or true (on).

## Set Option Flags

You can change the value of the option flags by using *ConfigurationControl*'s method `setPersistentFlag(PersistentOptionFlags flags, bool enabled)` like so:

mSphero.getConfiguration().setPersistentFlag(PersistentOptionFlags.PreventSleepInCharger, (cbPreventSleepInCharger.isChecked()));
mSphero.getConfiguration().setPersistentFlag(PersistentOptionFlags.EnableVectorDrive, cbEnableVectorDrive.isChecked());
mSphero.getConfiguration().setPersistentFlag(PersistentOptionFlags.DisableSelfLevelInCharger, (cbPreventSleepInCharger.isChecked()));
mSphero.getConfiguration().setPersistentFlag(PersistentOptionFlags.EnablePersistentTailLight, cbEnableTailPersistent.isChecked());
mRobot.getConfiguration().setPersistentFlag(PersistentOptionFlags.PreventSleepInCharger, (cbPreventSleepInCharger.isChecked()));
mRobot.getConfiguration().setPersistentFlag(PersistentOptionFlags.EnableVectorDrive, cbEnableVectorDrive.isChecked());
mRobot.getConfiguration().setPersistentFlag(PersistentOptionFlags.DisableSelfLevelInCharger, (cbPreventSleepInCharger.isChecked()));
mRobot.getConfiguration().setPersistentFlag(PersistentOptionFlags.EnablePersistentTailLight, cbEnableTailPersistent.isChecked());


Here we set the value of each flag to the value of a UI CheckBox. We then send the command to ball to set the option flags.
Expand Down

0 comments on commit 6d5e6b3

Please sign in to comment.