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

Commit

Permalink
Format change: all code snippets are now formatted the same
Browse files Browse the repository at this point in the history
  • Loading branch information
zenelk committed Nov 18, 2013
1 parent a3a6b3a commit 3eedf01
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions samples/Collisions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Ball to ball collisions is a little bit tougher to determine, since Sphero may t
These values suggest a low collision threshold when you are not moving, and a higher one when Sphero is driving at full power. That way, we will minimize the false collisions when just driving around. This also will trigger collisions on both axis. We don't want the deadTime to be as high here, because if we get a false collision before an actual collision, we don't want to ignore the real one.

## Preparing the Collision Detection Listener
To start using collision detection, you must first make a listener object that conforms to the *CollisionListener* interface. Create a listener like so with the `collisionDetected(CollisionDetectedAsyncData collisionData)` method. This will automatically get called once a collision is detected once the listener is attached later.
To start using collision detection, you must first make a listener object that conforms to the `CollisionListener` interface. Create a listener like so with the `collisionDetected(CollisionDetectedAsyncData collisionData)` method. This will automatically get called once a collision is detected once the listener is attached later.

private final CollisionListener mCollisionListener = new CollisionListener() {
public void collisionDetected(CollisionDetectedAsyncData collisionData) {
Expand All @@ -29,7 +29,7 @@ To start using collision detection, you must first make a listener object that c

## Registering for Collision Async Data

As with data streaming, you have to register for async data notifications with this line after you configure the collision listener (assuming that mRobot is a *Sphero* object):
As with data streaming, you have to register for async data notifications with this line after you configure the collision listener (assuming that mRobot is a `Sphero` object):

mRobot.getCollisionControl().addCollisionListener(mCollisionListener);
## Enabling Collision Detection
Expand Down
6 changes: 3 additions & 3 deletions samples/HelloWorld/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#HelloWorld

This sample code demonstrates how to connect to a Sphero and blink it's RGB LED blue. This sample does not use the *SpheroConnectionView*, because we wanted it to be simple and pair to the first Sphero device that it finds paired to the phone. This sample is a good starting point if you want to make your own custom Connection View. Also, the code sample is the basis for the application created in the Quick Start Guide.
This sample code demonstrates how to connect to a Sphero and blink it's RGB LED blue. This sample does not use the `SpheroConnectionView`, because we wanted it to be simple and pair to the first Sphero device that it finds paired to the phone. This sample is a good starting point if you want to make your own custom Connection View. Also, the code sample is the basis for the application created in the Quick Start Guide.

The connection is made in your Activity by simply adding the following `onResume()` and wiring the `connected()` method. This is also the best place to save Sphero so that you do not have to find him again later.

Expand Down Expand Up @@ -39,11 +39,11 @@ The final call in `connected()` is to `blink(boolean enableLED)`, which is metho
mRobot.setColor(0,0,0);
Where mRobot is the reference to the *Sphero* object that the API uses determine which device to send a command to, and the last arguments set the brightness of red, green, and blue components of the LED. In this case, all color components are turned off. The method sets the blue LED component to full brightness with the following code line.
Where mRobot is the reference to the `Sphero` object that the API uses determine which device to send a command to, and the last arguments set the brightness of red, green, and blue components of the LED. In this case, all color components are turned off. The method sets the blue LED component to full brightness with the following code line.

mRobot.setColor(0, 0, 255);

It finally uses a *Handler* object to call it self after a 1 second delayed with the lit boolean parameter toggled, thus toggling the blue LED component on and off.
It finally uses a `Handler` object to call it self after a 1 second delayed with the lit boolean parameter toggled, thus toggling the blue LED component on and off.

When the application closes the connection is closed by the following line in the `onStop()` method.

Expand Down
2 changes: 1 addition & 1 deletion samples/Locator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Now you're set to receive locator data from the Sphero!
## Making the Most of the Locator
Depending on your needs there are a few ways to set up and use the Locator.1. Do you need to know position (go to 2) or just distance traveled (go to 3)?2. Do you want to use roll commands to move Sphero to specific locator positions (go to 4) or does it suffice to simply know where Sphero is (go to 5)?3. Do you want to know an arc length/odometer distance (go to 6) or do you want to the distance “as the crow flies” (go to 5)?4. See The Full Setup.5. See The Default Setup.6. See Distance Traveled.## The Default SetupSign up for locator position streaming. Leave the locator in its default configuration with flag 0 set to true. The application may use the standard joystick and calibration UI elements freely.## Distance TraveledSign up for locator velocity streaming. Leave the locator in its default configuration with flag 0 set to true. The application may use the standard joystick and calibration UI elements freely. If you want to keep track of distance in the odometer sense, when a data streaming callback comes in accumulate a total using the following formula:
Distance Traveled += √(Vx^2 + Vy^2 ) * dt
Where *Vx* and *Vy* are the x and y velocity components and *dt* is the time between data samples. Rather than actually measuring dt (and fighting with Bluetooth latency to get a good timestamp) it is better to synthesize it using the formula:
Where `Vx` and `Vy` are the x and y velocity components and `dt` is the time between data samples. Rather than actually measuring dt (and fighting with Bluetooth latency to get a good timestamp) it is better to synthesize it using the formula:
dt = N/420Where N is the divisor used in the Set Locator Streaming command.## The Full Setup
The easiest way to use locator coordinates and roll command headings together in your app is to turn auto-correction off (set the first flag bit to false) and avoid the Set Heading command altogether. You may freely use the Configure Locator command to set the location of Sphero as long as you always set yaw tare to zero. Again, do not use the Set Heading command!
Your app may freely use the standard joystick UI element. Unfortunately, the calibration UI element uses the Set Heading command and so should be avoided. To achieve the same effect one can use Roll commands with a speed of zero to rotate the ball. Of course, this does not change the meaning of yaw angles the same way Set Heading does. In order to simulate this effect, you must maintain a private yaw offset, which you set when reorienting the ball. Your joystick (or other control mechanism) must be modified to add this yaw offset to every outgoing roll command.In this way, the user gets all the functionality of the set heading command without altering the locator coordinate system or the IMU headings. If you want to drive from one location toward another the following formula gives the heading you should use:
Expand Down
4 changes: 2 additions & 2 deletions samples/MacroSample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Macro Sample

This sample demonstrates how to connect to multiple balls with the *SpheroConnectionView* and also how to programmatically create macros and run them on multiple Spheros.
This sample demonstrates how to connect to multiple balls with the `SpheroConnectionView` and also how to programmatically create macros and run them on multiple Spheros.

## Connecting to Multiple Spheros

Expand All @@ -11,7 +11,7 @@ Instead of having a member variable that holds a single Robot object, you now ha
/** The Sphero Robots */
private ArrayList<Robot> mRobots = new ArrayList<Robot>();

In previous samples, we have hidden the *SpheroConnectionView* after the first Robot connected. However, in this sample, we will continue to add Robots to the ArrayList until the user clicks the done button. The program code for this is below:
In previous samples, we have hidden the `SpheroConnectionView` after the first Robot connected. However, in this sample, we will continue to add Robots to the ArrayList until the user clicks the done button. The program code for this is below:

// Set the done button to make the connection view go away
mDoneButton = (Button)findViewById(R.id.done_button);
Expand Down
6 changes: 3 additions & 3 deletions samples/OptionFlags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ By default, your Sphero only has vector drive enabled.
## Get Current Option Flags


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

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*.
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`.

private DeviceMessenger.DeviceResponseListener mResponseListener = new DeviceMessenger.DeviceResponseListener() {
@Override
Expand All @@ -43,7 +43,7 @@ Here we are getting the state of each option flag in a boolean variable which wi

## Set Option Flags

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

mRobot.getConfiguration().setPersistentFlag(PersistentOptionFlags.PreventSleepInCharger, (cbPreventSleepInCharger.isChecked()));
mRobot.getConfiguration().setPersistentFlag(PersistentOptionFlags.EnableVectorDrive, cbEnableVectorDrive.isChecked());
Expand Down
4 changes: 2 additions & 2 deletions samples/OrbBasicSample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The sample programmatically loads the .orbbas files in this directory into the L

## Initializing an OrbBasic Program Object

In the sample, when you click an item in the ListView, you will initialize the *OrbBasicProgram* object. This is the first step in putting an OrbBasic program on the ball. At this point, you are only providing the object with the byte array of data, or the text file content. Here is the code:
In the sample, when you click an item in the ListView, you will initialize the `OrbBasicProgram` object. This is the first step in putting an OrbBasic program on the ball. At this point, you are only providing the object with the byte array of data, or the text file content. Here is the code:

// Retrieve byte array from file
Resources res = getResources();
Expand Down Expand Up @@ -60,7 +60,7 @@ You can run the program with the `executeProgram()` function. Depending on the

The AsyncDataListener set up is the same as the StreamingExample, Locator Sample, and a few others in our SDK.

In the *onRobotConnected* event of the *SpheroConnectionView* you should set up AsyncDataListening when you connect to a robot.
In the `onRobotConnected` event of the `SpheroConnectionView` you should set up AsyncDataListening when you connect to a robot.

@Override
public void onRobotConnected(Robot arg0) {
Expand Down
4 changes: 2 additions & 2 deletions samples/SelfLevel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This sample code demonstrates how to connect to a Sphero and perform the self le

## Default Self Level Command

A basic self level command can be performed by the developer by calling (assuming mRobot is a prepopulated *Sphero* object):
A basic self level command can be performed by the developer by calling (assuming mRobot is a prepopulated `Sphero` object):

mRobot.getConfiguration().performSelfLevel();

Expand All @@ -29,7 +29,7 @@ Additional settings include the options flag. This flag is a bitwise mask the s
3. **Sleep Bit**: 0 stays awake after leveling. 1 goes to sleep after leveling.
4. **Control System Bit**: 0 turns control system off after leveling. 1 turns control system on after leveling.

When you do *mRobot.getConfiguration.performSelfLevel()* the values for these settings it uses are, the **Stop Bit** = 1, **Final Angle Bit** = 1, **Sleep Bit** = 0, and **Control System Bit** = 0.
When you do `mRobot.getConfiguration.performSelfLevel()` the values for these settings it uses are, the **Stop Bit** = 1, **Final Angle Bit** = 1, **Sleep Bit** = 0, and **Control System Bit** = 0.

## Customized Self Level Command

Expand Down
8 changes: 4 additions & 4 deletions samples/StreamingAnimation/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![logo](http://update.orbotix.com/developer/sphero-small.png)

# Streaming Animation SampleStreamingAnimation demonstrates how to use Sphero as a controller to move and rotate a Sphero ball image around the screen. To control the image, we use asynchronous data streaming of the IMU values of **Roll, Pitch, and Yaw**. Roll and Pitch control x and y translation and Yaw controls rotating the image.## UI Elements
The samples has a *main.xml* resource file that contains the *SpheroConnectionView*, IMU TextViews, Calibrate Button, and Sphero Image. If you want the *SpheroConnectionView* explained in more detail, look at the Android SDK ReadMe.
The samples has a `main.xml` resource file that contains the `SpheroConnectionView`, IMU TextViews, Calibrate Button, and Sphero Image. If you want the `SpheroConnectionView` explained in more detail, look at the Android SDK ReadMe.

<RelativeLayout
android:id="@+id/relative_layout"
Expand Down Expand Up @@ -55,7 +55,7 @@ It is important to note the ImageView, because it is a little bit more advanced.

### Making the Sample Fullscreen

In the *AndroidManifest.xml* see the <Activity> tag for our *StreamingAnimationAcitivty*:
In the `AndroidManifest.xml` see the <Activity> tag for our `StreamingAnimationAcitivty`:

<activity android:name=".CoinCollectorActivity"
android:label="@string/app_name"
Expand All @@ -65,7 +65,7 @@ We simply added the theme attribute to make the game full screen (remove the tit

### Getting the Android Device Screen Size

Most Android devices have different screen sizes. To get the correct width and height of the screen (in pixels) we use the *DisplayMetrics* class. We will use this width and height to bound the Sphero image's movement. This code in the `onCreate()` method.
Most Android devices have different screen sizes. To get the correct width and height of the screen (in pixels) we use the `DisplayMetrics` class. We will use this width and height to bound the Sphero image's movement. This code in the `onCreate()` method.

// Get Screen width and height
DisplayMetrics displaymetrics = new DisplayMetrics();
Expand Down Expand Up @@ -129,7 +129,7 @@ Most Android devices have different screen sizes. To get the correct width and

### Calling the updateSpheroPosition Function

The *StreamingExample* set up the data for us, so all we need to do is get it to the function we created. We do this by replacing the code in `onDataReceived(DeviceAsyncData data)` to
The `StreamingExample` set up the data for us, so all we need to do is get it to the function we created. We do this by replacing the code in `onDataReceived(DeviceAsyncData data)` to

//get the frames in the response
List<DeviceSensorsData> data_list = ((DeviceSensorsAsyncData)data).getAsyncData();
Expand Down

0 comments on commit 3eedf01

Please sign in to comment.