Answers.Body: <p>You have two options.</p>
  
  <p>You can use an accelerometer. Lego sells one that can be found <a href="http://shop.lego.com/en-US/Accelerometer-Sensor-2852724" rel="nofollow">here</a>. There are also aftermarket ones at mindsensors.com.  This allows you to independently measure the acceleration of the robot. You have to then integrate this information twice to get positional change. The way to do this is to put it in your control loop and sum up 0.5*dt*dt*a where a is the accelerometer reading (there will be one for each axis of motion) and dt is the time between samples. This nice thing about this is it gives you absolute displacement. That is it accounts for motions that cancel out so you can set a straight line path back.</p>
  
  <p>You can record each displacement into a variable for x and y directions using the servo readings from the motors - remember to reset the encoder value from the servos after each reading. This is harder because you have to account for the geometry of the wheels and keep track of the robot heading - lego also sells a compass sensor if you don't want to deal with finding your heading, but you'll still have to deal with non-spinning turns. It's also prone to accumulation of errors. (the accelerometer is too but not as bad I think.)</p>
  
  <p>Your admonition of 'no other helpers' could be interpreted to mean you don't want the first solution in which case you are left with using the encoders and figuring out the differential motion of your chassis design (which may be non trivial).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-03-06T15:33:33.223Z
Answers.LastActivityDate: 2014-03-06T15:33:33.223Z
Answers.UserDisplayName: mostlyWright
Answers.Body: <h2><strong>Get the initial position of an EV3 Motor and return to it.</strong></h2>
  
  <p><strong>Setup:</strong>  I installed Debian Linux on the Mindstorms EV3 brick and I'm using Python 2 to use the ev3.lego package to use the method: <code>run_position_limited(... , ...)</code> to spin the motor to a certain angle position.</p>
  
  <p><strong>Python 2 code</strong>: which gets the initial position of the Motor on program start:</p>
  
  <pre><code>from ev3.lego import Motor 
  c = Motor(port = Motor.PORT.C)
  
  initialMotorLocation= c.read_value("position")
  c.run_position_limited(
      position_sp = int(initialMotorLocation) + 150, 
      speed_sp = 150)
  </code></pre>
  
  <p><strong>What it does</strong></p>
  
  <p>First we import the Motor library from ev3.lego.  Then we instantiate a new connection to the Motor on Port C.  Then we read the current position of the angle of the motor on start.  Store this value permanently so every time we want to move ahead by 150, we add that value to the location it was at start.</p>
  
  <p><strong>Result:</strong></p>
  
  <p>If you run this python program many times, the motor will rotate forward by exactly 150 each time, rather than the default behavior: "rotating to exactly position 150", which only holds true until the EV3 brick is rebooted."</p>
  
  <p><strong>What did we learn:</strong></p>
  
  <p>We need to learn to read and comprehend the source code ev3.lego documention, Defined here: <a href="https://github.com/topikachu/python-ev3" rel="nofollow">https://github.com/topikachu/python-ev3</a></p>
  
  <p>If you scroll down that page you see this command:</p>
  
  <pre><code>from ev3.lego import MediumMotor
  d = MediumMotor()
  d.reset()
  </code></pre>
  
  <p>So the method called <code>reset</code> is an additional way to cause the motor to reset it's internal tachometer to 0 at the current location.</p>
  
  <p><strong>Full Example:</strong></p>
  
  <pre><code>from ev3.lego import Motor
  c = Motor(port = Motor.PORT.C)
  c.reset()  #Set the internal tachometer back to 0
  c.run_position_limited(position_sp = 150, speed_sp = 150)
  </code></pre>
  
  <p><strong>How to get to these answers on your own:</strong></p>
  
  <p>You got told that the <code>reset()</code> and <code>read_value</code> methods will solve your problem.  This is not an example of you finding things out for yourself.  </p>
  
  <p>Go to the source code: <a href="https://github.com/topikachu/python-ev3" rel="nofollow">https://github.com/topikachu/python-ev3</a></p>
  
  <p>Under <code>python-ev3/ev3/ev3dev.py</code> you'll see the source code that does the work I've explained above.  Notice the properties.  You see the integer value called <code>position</code> that you were querying above.</p>
  
  <p>Being able to recompile and understand how the library is working from source is the better part of the education the mindstorms EV3 brick aims to teach you.  Dig in.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-17T21:36:22.910Z
Answers.LastActivityDate: 2015-05-17T21:57:54.530Z
Answers.LastEditDate: 2015-05-17T21:57:54.530Z
Answers.UserDisplayName: Eric Leschinski
Answers.Body: <p>You should look up 'Dead Reckoning'.  It is a method where you always know (or guess) your current position by tracking all your previous moves.  Knowing your current position, you can then retrace your steps backward or reach any position back calculating a straight line to it (hoping that there's nothing in the way).</p>
  
  <p>Here's the Wikipedia on the subject: <a href="http://en.wikipedia.org/wiki/Dead_reckoning" rel="nofollow">Dead reckoning</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-03-05T13:51:09.973Z
Answers.LastActivityDate: 2014-03-05T13:51:09.973Z
Answers.UserDisplayName: pcantin
Body: <p>I have an EV3 robot with motors, like a car, that can move forward/backward and left/right and have some sensors attached. I want it to remember its initial position by remembering all the movements of motors when robot starts moving, then after some movements, that can be random in time, distance and direction, I want to return it back home.</p>
  
  <p>How can I do this? What is the principle of returning "home" knowing there are no GPS or other helpers?</p>
  
Tags: <ev3>
Title: How to remember initial position of a robot and return to it
UserDisplayName: Sergei Basharov
ThreadText: # How to remember initial position of a robot and return to it
  
  (Asked by: username_0 on 2014-03-05)
  
  I have an EV3 robot with motors, like a car, that can move forward/backward and left/right and have some sensors attached. I want it to remember its initial position by remembering all the movements of motors when robot starts moving, then after some movements, that can be random in time, distance and direction, I want to return it back home.
  
  How can I do this? What is the principle of returning "home" knowing there are no GPS or other helpers?
  
  **Tags:** ev3
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2014-03-06. Score: 4
  
  You have two options.
  
  You can use an accelerometer. Lego sells one that can be found [here](http://shop.lego.com/en-US/Accelerometer-Sensor-2852724). There are also aftermarket ones at mindsensors.com. This allows you to independently measure the acceleration of the robot. You have to then integrate this information twice to get positional change. The way to do this is to put it in your control loop and sum up 0.5\*dt\*dt\*a where a is the accelerometer reading (there will be one for each axis of motion) and dt is the time between samples. This nice thing about this is it gives you absolute displacement. That is it accounts for motions that cancel out so you can set a straight line path back.
  
  You can record each displacement into a variable for x and y directions using the servo readings from the motors - remember to reset the encoder value from the servos after each reading. This is harder because you have to account for the geometry of the wheels and keep track of the robot heading - lego also sells a compass sensor if you don't want to deal with finding your heading, but you'll still have to deal with non-spinning turns. It's also prone to accumulation of errors. (the accelerometer is too but not as bad I think.)
  
  Your admonition of 'no other helpers' could be interpreted to mean you don't want the first solution in which case you are left with using the encoders and figuring out the differential motion of your chassis design (which may be non trivial).
  
  
  ---
  
  ### Answer by username_2 on 2015-05-17. Score: 3
  
  Get the initial position of an EV3 Motor and return to it.
  Setup:  I installed Debian Linux on the Mindstorms EV3 brick and I'm using Python 2 to use the ev3.lego package to use the method: run_position_limited(... , ...) to spin the motor to a certain angle position.
  Python 2 code: which gets the initial position of the Motor on program start:
  from ev3.lego import Motor 
  c = Motor(port = Motor.PORT.C)
  
  initialMotorLocation= c.read_value("position")
  c.run_position_limited(
      position_sp = int(initialMotorLocation) + 150, 
      speed_sp = 150)
  
  What it does
  First we import the Motor library from ev3.lego.  Then we instantiate a new connection to the Motor on Port C.  Then we read the current position of the angle of the motor on start.  Store this value permanently so every time we want to move ahead by 150, we add that value to the location it was at start.
  Result:
  If you run this python program many times, the motor will rotate forward by exactly 150 each time, rather than the default behavior: "rotating to exactly position 150", which only holds true until the EV3 brick is rebooted."
  What did we learn:
  We need to learn to read and comprehend the source code ev3.lego documention, Defined here: https://github.com/topikachu/python-ev3
  If you scroll down that page you see this command:
  from ev3.lego import MediumMotor
  d = MediumMotor()
  d.reset()
  
  So the method called reset is an additional way to cause the motor to reset it's internal tachometer to 0 at the current location.
  Full Example:
  from ev3.lego import Motor
  c = Motor(port = Motor.PORT.C)
  c.reset()  #Set the internal tachometer back to 0
  c.run_position_limited(position_sp = 150, speed_sp = 150)
  
  How to get to these answers on your own:
  You got told that the reset() and read_value methods will solve your problem.  This is not an example of you finding things out for yourself.  
  Go to the source code: https://github.com/topikachu/python-ev3
  Under python-ev3/ev3/ev3dev.py you'll see the source code that does the work I've explained above.  Notice the properties.  You see the integer value called position that you were querying above.
  Being able to recompile and understand how the library is working from source is the better part of the education the mindstorms EV3 brick aims to teach you.  Dig in.
  
  
  ---
  
  ### Answer by username_3 on 2014-03-05. Score: 2
  
  You should look up 'Dead Reckoning'. It is a method where you always know (or guess) your current position by tracking all your previous moves. Knowing your current position, you can then retrace your steps backward or reach any position back calculating a straight line to it (hoping that there's nothing in the way).
  
  Here's the Wikipedia on the subject: [Dead reckoning](http://en.wikipedia.org/wiki/Dead_reckoning)
  
  
  ---
  
  