Answers.Body: <p>There are a few different but related problems here.</p>
  
  <ul>
  <li><strong>Position</strong> Your robot should be able to know where it is in the room. This can be achieved in a few ways:
  
  <ul>
  <li>Using the ultrasonic sensor as a sonar, rotating it around and storing the readouts, then calculating based on the known map of the room (if the layout is fixed and known in advance).</li>
  <li>Tracking the movements and calculating from the last known position. This method depends on how accurate are the starting data and the measurement of the movement. This also loses accuracy over time.</li>
  <li>Placing unique markers along the floor or the wall that the robot can read. I don't know how could this be accomplished using LEGO pieces, but I wouldn't say it's impossible to do. However, you could mark the two important locations (the green box and the center) to have an easy way to tell if you're at them.</li>
  </ul></li>
  <li><strong>Orientation</strong> Your robot should also know which direction is it facing. Most of the above methods offer a way to calculate this, but you could also use a compass sensor.</li>
  <li><strong>Knowledge of the environment</strong> Your robot should know if there is an obstacle in its way. The random obstacles are by definition impossible to know in advance, so you'll need to detect them somehow.
  
  <ul>
  <li>You could use the aforementioned ultrasonic sonar if the obstacles provide a good enough acho.</li>
  <li>If the obstacles are made of a suitable material, you could try to use a color sensor to see if there is one in front of the robot</li>
  <li>In theory, you could try to measure the resistance of the motors when you try to drive into an obstacle but this might prove impossible, depending on the capabilities of the hardware and software you are using. This method also makes it impossible to use the incremental location method.</li>
  </ul></li>
  </ul>
  
  <p>Given these problems in my opinion your best bet would be a simpler, more brute force approach. Outlined in highly abstract pseudocode below:</p>
  
  <pre><code>going to the green target box:
  while not in target area
    while not at wall
      if obstacle is in front of me: get around
      else: move forward
    end while // now you're at the wall
    move forward along the wall
  end while // now you're at the target
  
  going to the center: // assuming you're at the green box
  turn towards the center
  while not at center:
    if obstacle is in front of me: get around
    else: move forward
    if moved more than the journey should have taken: announce that you're stuck
  end while // now you're at the center or lost
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-04-30T20:18:59.727Z
Answers.Text: I would like to simplify my question. Im in the center, I made some movements, I just want to return to my starting position. I dont have a compass sensor. I read this could be possible with motor decoding but Im lost in this area...
Answers.UserDisplayName: Anarkie
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-05-02T12:27:11.070Z
Answers.Text: I can't seem to find the related documentation on retrieving the measurements of the encoders on the motors. But you could always approach the problem by keeping track of every movement the robot has made from the known starting position. Then when you have to turn around, you can simply replay the stored movements with the rotations inversed. So for example if you stored F10, R90, F25, L60, F20, you'd have to turn around (L180) and then follow your way back: F20, R60, F25, L90, F10.
Answers.UserDisplayName: zovits
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2014-04-30T19:37:22.800Z
Answers.LastActivityDate: 2020-05-02T03:05:07.270Z
Answers.LastEditDate: 2020-05-02T03:05:07.270Z
Answers.UserDisplayName: zovits
Body: <p>I have LEGO NXT and a square room of 100x100cm. I would like to use the center of the room always as my starting point(the black box). The green box is going to be my park area. Circles can be the randomly placed obstacles on my way. Red is the walls of the room. Objectives:</p>
  
  <ul>
  <li>When starting no matter where the robot is, it should return to the center, afterwards it should be able to park into the green box when requested.</li>
  <li>In its returning center/home progress there can be obstacles on the way, I should try to overcome these obstacles and park successfully. The obstacles don't have to be circular, they can be square as well.</li>
  <li>If there is an obstacle in the park/center area I should give an error not possible to park or abort the parking...</li>
  </ul>
  
  <p>Worst-case scenarios: Robot starting from the corner and obstacles on the way to park.
  I'm using for the time being the color sensor and ultrasonic sensor, I can also add a gyro sensor but haven't made yet deep search about it. I also have an RFID sensor but I think only with 2 transponders it won't help much.</p>
  
  <p>My first challenge is without any obstacles for starters would be identifying the center to the robot, and it knows where it has to come from a random position. Any tips?</p>
  
  <p><img src="https://i.sstatic.net/s9FUJ.png" alt="Robot room"></p>
  
Tags: <nxt><mindstorms><sensor-ultrasonic>
Title: Finding certain positions in a room?
UserDisplayName: Anarkie
ThreadText: # Finding certain positions in a room?
  
  (Asked by: username_0 on 2014-04-26)
  
  I have LEGO NXT and a square room of 100x100cm. I would like to use the center of the room always as my starting point(the black box). The green box is going to be my park area. Circles can be the randomly placed obstacles on my way. Red is the walls of the room. Objectives:
  
  * When starting no matter where the robot is, it should return to the center, afterwards it should be able to park into the green box when requested.
  * In its returning center/home progress there can be obstacles on the way, I should try to overcome these obstacles and park successfully. The obstacles don't have to be circular, they can be square as well.
  * If there is an obstacle in the park/center area I should give an error not possible to park or abort the parking...
  
  Worst-case scenarios: Robot starting from the corner and obstacles on the way to park.
  I'm using for the time being the color sensor and ultrasonic sensor, I can also add a gyro sensor but haven't made yet deep search about it. I also have an RFID sensor but I think only with 2 transponders it won't help much.
  
  My first challenge is without any obstacles for starters would be identifying the center to the robot, and it knows where it has to come from a random position. Any tips?
  
  ![Robot room](https://i.sstatic.net/s9FUJ.png)
  
  **Tags:** nxt, mindstorms, sensor-ultrasonic
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-04-30. Score: 2
  
  There are a few different but related problems here.
  
  * **Position** Your robot should be able to know where it is in the room. This can be achieved in a few ways:
    + Using the ultrasonic sensor as a sonar, rotating it around and storing the readouts, then calculating based on the known map of the room (if the layout is fixed and known in advance).
    + Tracking the movements and calculating from the last known position. This method depends on how accurate are the starting data and the measurement of the movement. This also loses accuracy over time.
    + Placing unique markers along the floor or the wall that the robot can read. I don't know how could this be accomplished using LEGO pieces, but I wouldn't say it's impossible to do. However, you could mark the two important locations (the green box and the center) to have an easy way to tell if you're at them.
  * **Orientation** Your robot should also know which direction is it facing. Most of the above methods offer a way to calculate this, but you could also use a compass sensor.
  * **Knowledge of the environment** Your robot should know if there is an obstacle in its way. The random obstacles are by definition impossible to know in advance, so you'll need to detect them somehow.
    + You could use the aforementioned ultrasonic sonar if the obstacles provide a good enough acho.
    + If the obstacles are made of a suitable material, you could try to use a color sensor to see if there is one in front of the robot
    + In theory, you could try to measure the resistance of the motors when you try to drive into an obstacle but this might prove impossible, depending on the capabilities of the hardware and software you are using. This method also makes it impossible to use the incremental location method.
  
  Given these problems in my opinion your best bet would be a simpler, more brute force approach. Outlined in highly abstract pseudocode below:
  
  ```
  going to the green target box:
  while not in target area
    while not at wall
      if obstacle is in front of me: get around
      else: move forward
    end while // now you're at the wall
    move forward along the wall
  end while // now you're at the target
  
  going to the center: // assuming you're at the green box
  turn towards the center
  while not at center:
    if obstacle is in front of me: get around
    else: move forward
    if moved more than the journey should have taken: announce that you're stuck
  end while // now you're at the center or lost
  
  ```
  
  > **Comments:**
  > **username_0**: I would like to simplify my question. Im in the center, I made some movements, I just want to return to my starting position. I dont have a compass sensor. I read this could be possible with motor decoding but Im lost in this area...  
  > **username_1**: I can't seem to find the related documentation on retrieving the measurements of the encoders on the motors. But you could always approach the problem by keeping track of every movement the robot has made from the known starting position. Then when you have to turn around, you can simply replay the stored movements with the rotations inversed. So for example if you stored F10, R90, F25, L60, F20, you'd have to turn around (L180) and then follow your way back: F20, R60, F25, L90, F10.  
  
  ---
  
  