Reputation: 45
I want to make the sphero move a given amount of centimeters ahead but so far i have not managed to get anything to work properly This is the code i have now:
EditText distanceText = (EditText) findViewById(R.id.distanceText);
int inputMSec = Integer.parseInt(distanceText.getText().toString());
int time = (inputMSec - inputMSec/2);
// The ball is given the RollCommand at half speed.
RollCommand.sendCommand(mRobot, heading,0.5f);
// A handler is created to delay the Stop command.
final Handler handler = new Handler();
handler.postDelayed(new Runnable(){
@Override
public void run() {
// Makes the ball stop
RollCommand.sendStop(mRobot);
}
// The variable 'time' defines how long the ball rolls until it is told to stop.
}, time);
Is there any other command i can send to the ball instead of RollCommand? Or can anyone find out what to do to the input from the EditText so that the distance turns out correct?
Upvotes: 3
Views: 3990
Reputation: 362
There's no API command that directly provides the ability to drive a given distance. The only way I now how is with an iterative strategy using the locator, which provides position information about the ball.
Here's an overview of the strategy. Let me know if you need more details.
The big question is: how do you decide what speed to command based on D? I had some success with a strategy something like this: (undoubtedly you can tune it up a lot better).
This worked pretty well. It would drive, slow down, and coast the last few inches to a stop. Problems with this algorithm include:
Good luck!
Upvotes: 6