Answers.Body: <p>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 <a href="http://www.lejos.org/nxt/nxj/api/index.html" rel="nofollow">LeJOS API</a> while I describe some of the classes, it is pretty easy to look them up there.</p>
  
  <p>If you want to know the location of the robot, you need to use some sort of <code>Pilot</code> class.  To me, it sounds like you want to use the <code>DifferentialPilot</code> (of course, use the <code>Pilot</code> class that controls your robot, for instance, a triangle robot).  You create the <code>DifferentialPilot</code> with a wheel diameter, distance between the wheels, the <code>Motor</code> that is on the left, and the <code>Motor</code> that is on the right.</p>
  
  <p>Create a <code>Navigator</code>, and give it the <code>Pilot</code> so that it can control the robot.  Next, create a <code>Timer</code> 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 <code>Pilot</code>.  Call <code>addWaypoint()</code> on the <code>Navigator</code> with the x and y position (which I think you can pull the pose from the <code>Pilot</code>).</p>
  
  <p>Now, modify your line-following code so that it uses the <code>Pilot</code>'s controls (<code>travel()</code>, <code>rotate()</code>, etc.).</p>
  
  <p>When you have followed the line, you should have a list of <code>Waypoint</code>s that you can use to navigate the same path, without using the line-following code.</p>
  
  <p>You can then call <code>followPath()</code> on the <code>Navigator</code>, and the robot <em>should</em> follow the path.</p>
  
  <p>Of course, it is important to make sure that your <code>DifferentialPilot</code> 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 <a href="https://youtu.be/mMvg4xdXGDI" rel="nofollow">here</a> which covers it and shows the step-by-step process (hopefully this doesn't count as advertising, it is not intended to be any).</p>
  
  <p>Hopefully I was clear, it can get a bit jumbled together after programming NXTs with LeJOS for a number of years!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-23T14:00:40.483Z
Answers.Text: Wow, thank you so much for this explanation.
  I will try it and I'll let you how it goes.
  Thank you so much.
Answers.UserDisplayName: DaPoox
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-13T20:12:44.297Z
Answers.Text: Sorry it took me some time to update the situation.
  I tried it, and it works fine. Again, thank you
Answers.UserDisplayName: DaPoox
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-14T01:33:27.310Z
Answers.Text: @user52713 Glad to hear!
Answers.UserDisplayName: Gliderman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-23T03:03:12.820Z
Answers.LastActivityDate: 2016-02-23T03:03:12.820Z
Answers.UserDisplayName: Gliderman
Body: <p>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?</p>
  
Tags: <mindstorms><nxt><lejos>
Title: LEGO Mindstorm NXT memorize line followed (LeJos)
UserDisplayName: DaPoox
ThreadText: # LEGO Mindstorm NXT memorize line followed (LeJos)
  
  (Asked by: username_0 on 2016-02-22)
  
  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?
  
  **Tags:** mindstorms, nxt, lejos
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-02-23. Score: 1 | Accepted answer
  
  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](http://www.lejos.org/nxt/nxj/api/index.html) 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 `Waypoint`s 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](https://youtu.be/mMvg4xdXGDI) 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!
  
  > **Comments:**
  > **username_0**: Wow, thank you so much for this explanation. I will try it and I'll let you how it goes. Thank you so much.  
  > **username_0**: Sorry it took me some time to update the situation. I tried it, and it works fine. Again, thank you  
  > **username_1**: @user52713 Glad to hear!  
  
  ---
  
  