Answers.Body: <p>If I were you, I'd make it this way:</p>
  
  <p>The leader robot has a very bright light shining backwards, but not in a tight beam, rather a wide cone, so it can be seen from the back easily.</p>
  
  <p>The follower robot has the light sensor facing forward, with a cowl around and in front of the sensor in order to narrow its sensing angle. In other words, the sensor is modified in such a way that it only picks up anything if the light source is directly in front of it, not to the sides. This will help filtering out background "noises" (ambient light and other light sources).</p>
  
  <p>Then the follower robot runs this pseudocode:</p>
  
  <pre><code>while true // enter stopping condition here if required
    while light is visible // current light value is over a threshold - experiment with this value
      go forward some amount
    // if light is not visible the while loop exits and we need to find the light
    store current light level to variable FRONT
    rotate 10 degrees to the right // experiment with various values, maybe less is enough, maybe more is needed
    store current light level to variable RIGHT
    if RIGHT &lt; FRONT // the light probably moved to the left
      rotate 20 degrees to the left // twice the amount in the previous turn
    // else the light probably moved to the right, where we are currently headed
    // so there is no need to rotate further, just continue with the next iteration, 
    // checking if we see the light now
  </code></pre>
  
  <p>This way the follower will go after the leader while it is headed in the right way, but when the follower loses the leader, it stops and turns around to look for the light.</p>
  
  <p>This method however has a drawback. If the follower is slower than the leader, it will be left behind during the "stop and look around" phases, but if the follower is faster, it will run into the leader from the back.</p>
  
  <p>You could remedy this by giving the leader a bumper on the back connected to a push button (pressure sensor), and program the leader to only move forward when something (probably the follower) has pushed into its back bumper.</p>
  
  <p>Let me know if you need additional help.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-14T13:18:23.437Z
Answers.LastActivityDate: 2014-11-14T13:18:23.437Z
Answers.UserDisplayName: zovits
Body: <p>Cannot figure out how to simply program Lego Mindstorm NXT robot to follow another moving robot that has a bright LED light attached to it.</p>
  
  <p>Currently my programme looks like this:</p>
  
  <p><img src="https://i.sstatic.net/WkLgF.jpg" alt="Follow Light"></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-12T16:20:05.303Z
Comments.Text: It sounds like you are unfamiliar with how the light sensor works.  First off, it's not directional.  Secondly, it detects all light, including ambient light, so your LED may not be bright enough to even register on the light sensor.
Comments.UserDisplayName: Nick2253
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-11-13T02:35:56.417Z
Comments.Text: A few things:  The light sensor has to be pretty close to something in order to be very functional.  How close will the other robot be?  How much ambient light would there be in the room?  Do you have more than one light sensor?  Also, you would probably get much more reliable/feasible results using an ultrasonic sensor.  Is there a reason why you must use light?
Comments.UserDisplayName: PGmath
Tags: <nxt><programming>
Title: How to program light sensor to follow moving light using NXT
UserDisplayName: user4161
ThreadText: # How to program light sensor to follow moving light using NXT
  
  (Asked by: username_0 on 2014-11-12)
  
  Cannot figure out how to simply program Lego Mindstorm NXT robot to follow another moving robot that has a bright LED light attached to it.
  
  Currently my programme looks like this:
  
  ![Follow Light](https://i.sstatic.net/WkLgF.jpg)
  
  **Tags:** nxt, programming
  
  > **Comments:**
  > **username_1**: It sounds like you are unfamiliar with how the light sensor works.  First off, it's not directional.  Secondly, it detects all light, including ambient light, so your LED may not be bright enough to even register on the light sensor.  
  > **username_2**: A few things:  The light sensor has to be pretty close to something in order to be very functional.  How close will the other robot be?  How much ambient light would there be in the room?  Do you have more than one light sensor?  Also, you would probably get much more reliable/feasible results using an ultrasonic sensor.  Is there a reason why you must use light?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2014-11-14. Score: 2
  
  If I were you, I'd make it this way:
  
  The leader robot has a very bright light shining backwards, but not in a tight beam, rather a wide cone, so it can be seen from the back easily.
  
  The follower robot has the light sensor facing forward, with a cowl around and in front of the sensor in order to narrow its sensing angle. In other words, the sensor is modified in such a way that it only picks up anything if the light source is directly in front of it, not to the sides. This will help filtering out background "noises" (ambient light and other light sources).
  
  Then the follower robot runs this pseudocode:
  
  ```
  while true // enter stopping condition here if required
    while light is visible // current light value is over a threshold - experiment with this value
      go forward some amount
    // if light is not visible the while loop exits and we need to find the light
    store current light level to variable FRONT
    rotate 10 degrees to the right // experiment with various values, maybe less is enough, maybe more is needed
    store current light level to variable RIGHT
    if RIGHT < FRONT // the light probably moved to the left
      rotate 20 degrees to the left // twice the amount in the previous turn
    // else the light probably moved to the right, where we are currently headed
    // so there is no need to rotate further, just continue with the next iteration, 
    // checking if we see the light now
  
  ```
  
  This way the follower will go after the leader while it is headed in the right way, but when the follower loses the leader, it stops and turns around to look for the light.
  
  This method however has a drawback. If the follower is slower than the leader, it will be left behind during the "stop and look around" phases, but if the follower is faster, it will run into the leader from the back.
  
  You could remedy this by giving the leader a bumper on the back connected to a push button (pressure sensor), and program the leader to only move forward when something (probably the follower) has pushed into its back bumper.
  
  Let me know if you need additional help.
  
  
  ---
  
  