distance - Sphero: How to make it move a given length -
i want make sphero move given amount of centimeters ahead far have not managed work code have now:
edittext distancetext = (edittext) findviewbyid(r.id.distancetext); int inputmsec = integer.parseint(distancetext.gettext().tostring()); int time = (inputmsec - inputmsec/2); // ball given rollcommand @ half speed. rollcommand.sendcommand(mrobot, heading,0.5f); // handler created delay stop command. final handler handler = new handler(); handler.postdelayed(new runnable(){ @override public void run() { // makes ball stop rollcommand.sendstop(mrobot); } // variable 'time' defines how long ball rolls until told stop. }, time); is there other command can send ball instead of rollcommand? or can find out input edittext distance turns out correct?
there's no api command directly provides ability drive given distance. way how iterative strategy using locator, provides position information ball.
here's overview of strategy. let me know if need more details.
- turn on data streaming , request locator position data. should have callback giving sphero position ~20x sec. positions (x, y) coordinates on floor in centimeters.
- record starting position of ball (x0, y0).
- at each point in time, compute distance ball has traveled far using pythagorean theorem/distance formula.
- use figure out how far ball has left go. call distance d.
- give roll command speed computed d.
the big question is: how decide speed command based on d? had success strategy this: (undoubtedly can tune lot better).
- if remaining distance d > 100cm, command full speed.
- between d = 10cm , d = 100cm, command power ranging 30% 100% (linearly).
- if d < 10cm, command 0 speed make sphero stop.
this worked pretty well. drive, slow down, , coast last few inches stop. problems algorithm include:
- you have tune prevent overshoot/undershoot.
- when want command ball move short distance doesn't work well, might have tweak cover cases.
good luck!
Comments
Post a Comment