LEGO® Answers is a question and answer site for LEGO® and building block enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a LEGO NXT robot, and after some movements I would like it to return back where it started. After some research, it looks like my best option is to revert the motors. To decode their movements but I couldn't find any examples for it, could someone give me a hand? I'm using leJOS for programming.

share|improve this question
This is fundamentally a variant of How to remember initial position of a robot and return to it albeit with the NXT. – Zhaph - Ben Duguid Feb 4 '15 at 21:24

You can read the tacho count and rotate a negative amount of degrees. Or you may want to use the Navigation class and create a path while you move, then you just need to follow the path back.

But unless the robot is perfectly calibrated it will fail miserably. I explain it all here

share|improve this answer
The robot is way too far from perfect calibration :) because it has lots of sensors and cables on it unfortunately it isn't well calibrated. Im thinking of other ways like calculating the distance to walls and finding the center, when the distances are equal I assume I will be in the middle, but an assumption... – Anarkie Jun 2 '14 at 9:13
It isn't a bad idea... in fact Montecarlo localization works with a similar idea... just rememeber EV3/NXT Ultrasonic sensors only reach 2m at most. – Miguel Jun 2 '14 at 20:10
The room is a square 90 x 90 cm, another mate on the project is trying to implement the Montecarlo but till now no success... – Anarkie Jun 2 '14 at 20:37

Are you programming your robot to move? If so, then you could just keep a running log in your code of how far did each of the motors turn. Based on this log you could replay the whole log backwards to return to the starting point (with the approppriate precision of course). If your robot is moving due to external forces (e.g. someone is pushing it) then you can only rely on the decoding that you mentioned above.

For code references see these resources:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.