I made a line follower program with leJos, it works pretty well; and I want to take it to the next level: I want to make it remember the line it followed; works like this: follow the line till the end, and store an image file with the path made by the robot. I've been doin some reading; and there was something like Navigation class, or Waypoint class available in leJos; not sure how it helps me... I have 2 motors, and a color sensor. In my program, i'm just usin something like Motor.A.forward(); and stuff like this (and not any Navigation methode..) I don't know where to start, and I don't have any leads. Any suggestions?

1 Answer 1


I will preface this by saying that I'm just going to summarize what I suggest you do, as writing out the code step-by-step would take quite a while, and you writing the code will help improve your skills. I recommend checking out the LeJOS API while I describe some of the classes, it is pretty easy to look them up there.

If you want to know the location of the robot, you need to use some sort of Pilot class. To me, it sounds like you want to use the DifferentialPilot (of course, use the Pilot class that controls your robot, for instance, a triangle robot). You create the DifferentialPilot with a wheel diameter, distance between the wheels, the Motor that is on the left, and the Motor that is on the right.

Create a Navigator, and give it the Pilot so that it can control the robot. Next, create a Timer that will poll the position of the robot however often you want (maybe something like every second?). I think you get the position from the Pilot. Call addWaypoint() on the Navigator with the x and y position (which I think you can pull the pose from the Pilot).

Now, modify your line-following code so that it uses the Pilot's controls (travel(), rotate(), etc.).

When you have followed the line, you should have a list of Waypoints that you can use to navigate the same path, without using the line-following code.

You can then call followPath() on the Navigator, and the robot should follow the path.

Of course, it is important to make sure that your DifferentialPilot or whatever is as precise as it can be, so measure and refine the wheel diameter until you get really good accuracy, using whatever surface you are going to be using in the end. If you have any questions about calibration, I would recommend a new question, but for now, I have a video here which covers it and shows the step-by-step process (hopefully this doesn't count as advertising, it is not intended to be any).

Hopefully I was clear, it can get a bit jumbled together after programming NXTs with LeJOS for a number of years!

  • Wow, thank you so much for this explanation. I will try it and I'll let you how it goes. Thank you so much.
    – DaPoox
    Feb 23, 2016 at 14:00
  • Sorry it took me some time to update the situation. I tried it, and it works fine. Again, thank you
    – DaPoox
    Mar 13, 2016 at 20:12
  • @user52713 Glad to hear!
    – Gliderman
    Mar 14, 2016 at 1:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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