Answers.Body: <p>Expanding on @zovits approach for a rubberband-based mechanical system: I'll suggest something like the following diagram, adding a rubber band between the bush and the belt wedge wheel:</p>
  <p><a href="https://i.sstatic.net/MOl3A.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MOl3A.png" alt="CAD drawing of rubberband mechanism" /></a></p>
  <p>That can technically be called a friction clutch. With something like that, it's possible to keep the motor turning more than needed: when the cyan liftarm hits the red corner beam, the axle will block and the rubber band will absorb the excess rotation (by means of slipping on the yellow bush).</p>
  <p>In order to minimize wear&amp;tear, you should adjust the rubberband tension so it provides just enough grip, but can slip easily.</p>
  <hr />
  <p>A similar approach is to use <a href="https://www.bricklink.com/v2/catalog/catalogitem.page?P=60c01" rel="nofollow noreferrer">60c01 Technic, Gear 24 Tooth Clutch</a> or <a href="https://www.bricklink.com/v2/catalog/catalogitem.page?P=6542" rel="nofollow noreferrer">6542 Technic, Gear 16 Tooth with Clutch</a>:</p>
  <p><a href="https://i.sstatic.net/6u4GP.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/6u4GP.png" alt="24-tooth gear with clutch" /></a></p>
  <p>I don't own any such pieces, and therefore I don't know how well they stand wear&amp;tear - I'd recommend a rubberband just for the ease of finding replacements.</p>
  <hr />
  <p>Another approach is to use a linear actuator:</p>
  <p><a href="https://i.sstatic.net/EB0FV.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/EB0FV.png" alt="CAD drawing of linear actuator mechanism" /></a></p>
  <p>A technic linear actuator has a built-in clutch, so will absorb extra rotation as well. That means you can run motor more than needed to get them into a known state (either fully retracted or fully extended).</p>
  <p>By building an assembly as shown above (and securing both the motor and the black axle, but letting the linear actuator swing around the motor's axle), extending the actuator will make the black axle rotate about 90 degrees. You'll need to adjust the system to get the desired rotation angle.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-09T12:56:14.690Z
Answers.Text: Thanks for the illustrations! Adding a clutch to enable driving up to (and over) an end position has not occurred to me but is indeed a good idea. In the sentence "Technic liftarms will absorb extra rotation" did you mean "Technic linear actuators" perhaps?
Answers.UserDisplayName: zovits
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-09T13:46:06.830Z
Answers.Text: Sorry, my english skills seem to be still on holiday, and couldn't recall the word "clutch".  Also fixed the liftarm→actuator bit.
Answers.UserDisplayName: IvanSanchez
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-09T12:35:23.050Z
Answers.LastActivityDate: 2023-01-09T14:13:07.787Z
Answers.LastEditDate: 2023-01-09T14:13:07.787Z
Answers.UserDisplayName: IvanSanchez
Answers.Body: <p>For an ordinary motor it is not possible, as the axle position can't be queried from the software. What you can do though is to write your software in a way to return to the starting position before ending the program (define a counter for the number of trigger events, increase it every time, then at an appropriate point apply the necessary amount of reverse movement).</p>
  <p>Another possibility is to build in a mechanical system that returns the axle to a pre-defined position (with force from gravity or a rubber band) and set the motor in feathering mode to let it turn without resistance until the starting position is reached.</p>
  <p>The most convoluted way is to build your own position encoder: set up a sensor (push button, colour sensor or ultrasonic) that can tell when the axle is in the starting position, then when resetting, turn the motor while querying the sensor until the starting position is reached.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-09T10:54:13.047Z
Answers.LastActivityDate: 2023-01-09T10:54:13.047Z
Answers.UserDisplayName: zovits
Answers.Body: <p>Drive the motor at low power for some length of time in a direction until the door jams against some obstacle. Set the position sensor of the motor. Drive the motor to the desired starting position relative to the jammed position.</p>
  <p>This violates one of the constraints of the questions, since this would run before you ran your code. However, it is simple.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-03T01:31:40.947Z
Answers.LastActivityDate: 2023-04-03T01:31:40.947Z
Answers.UserDisplayName: dfrevert
Body: <p>The motor is attached to a &quot;door&quot;, which rotates to block off an opening. I have it coded to manually go back 1/4 of a rotation, and the distance sensor attached will send it forwards 1/4 of a rotation. However, if it gets triggered twice, then it has to be triggered another two times in order to get back to the default position. I would like to avoid this. I am coding on a laptop, and there is no block that I have seen that can do this. Is this possible, or did I just miss the block?</p>
  <p><a href="https://i.sstatic.net/ZmMVA.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ZmMVA.png" alt="enter image description here" /></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-01-05T17:21:15.280Z
Comments.Text: Please add the code you have issues with.
Comments.UserDisplayName: Alex
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-01-05T21:19:32.630Z
Comments.Text: Done. I have edited the post.
Comments.UserDisplayName: BJF
Tags: <ev3><programming>
Title: Is it possible to have a motor default to a certain position at the start of the code? I'm trying to use the motor as a servo, and it's annoying
UserDisplayName: BJF
ThreadText: # Is it possible to have a motor default to a certain position at the start of the code? I'm trying to use the motor as a servo, and it's annoying
  
  (Asked by: username_0 on 2023-01-05)
  
  The motor is attached to a "door", which rotates to block off an opening. I have it coded to manually go back 1/4 of a rotation, and the distance sensor attached will send it forwards 1/4 of a rotation. However, if it gets triggered twice, then it has to be triggered another two times in order to get back to the default position. I would like to avoid this. I am coding on a laptop, and there is no block that I have seen that can do this. Is this possible, or did I just miss the block?
  
  [![enter image description here](https://i.sstatic.net/ZmMVA.png)](https://i.sstatic.net/ZmMVA.png)
  
  **Tags:** ev3, programming
  > **Comments:**
  > **username_1**: Please add the code you have issues with.  
  > **username_0**: Done. I have edited the post.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2023-01-09. Score: 3
  
  Expanding on @zovits approach for a rubberband-based mechanical system: I'll suggest something like the following diagram, adding a rubber band between the bush and the belt wedge wheel:
  
  [![CAD drawing of rubberband mechanism](https://i.sstatic.net/MOl3A.png)](https://i.sstatic.net/MOl3A.png)
  
  That can technically be called a friction clutch. With something like that, it's possible to keep the motor turning more than needed: when the cyan liftarm hits the red corner beam, the axle will block and the rubber band will absorb the excess rotation (by means of slipping on the yellow bush).
  
  In order to minimize wear&tear, you should adjust the rubberband tension so it provides just enough grip, but can slip easily.
  
  ---
  
  A similar approach is to use [60c01 Technic, Gear 24 Tooth Clutch](https://www.bricklink.com/v2/catalog/catalogitem.page?P=60c01) or [6542 Technic, Gear 16 Tooth with Clutch](https://www.bricklink.com/v2/catalog/catalogitem.page?P=6542):
  
  [![24-tooth gear with clutch](https://i.sstatic.net/6u4GP.png)](https://i.sstatic.net/6u4GP.png)
  
  I don't own any such pieces, and therefore I don't know how well they stand wear&tear - I'd recommend a rubberband just for the ease of finding replacements.
  
  ---
  
  Another approach is to use a linear actuator:
  
  [![CAD drawing of linear actuator mechanism](https://i.sstatic.net/EB0FV.png)](https://i.sstatic.net/EB0FV.png)
  
  A technic linear actuator has a built-in clutch, so will absorb extra rotation as well. That means you can run motor more than needed to get them into a known state (either fully retracted or fully extended).
  
  By building an assembly as shown above (and securing both the motor and the black axle, but letting the linear actuator swing around the motor's axle), extending the actuator will make the black axle rotate about 90 degrees. You'll need to adjust the system to get the desired rotation angle.
  
  > **Comments:**
  > **username_3**: Thanks for the illustrations! Adding a clutch to enable driving up to (and over) an end position has not occurred to me but is indeed a good idea. In the sentence "Technic liftarms will absorb extra rotation" did you mean "Technic linear actuators" perhaps?  
  > **username_2**: Sorry, my english skills seem to be still on holiday, and couldn't recall the word "clutch".  Also fixed the liftarm→actuator bit.  
  
  ---
  
  ### Answer by username_3 on 2023-01-09. Score: 1
  
  For an ordinary motor it is not possible, as the axle position can't be queried from the software. What you can do though is to write your software in a way to return to the starting position before ending the program (define a counter for the number of trigger events, increase it every time, then at an appropriate point apply the necessary amount of reverse movement).
  
  Another possibility is to build in a mechanical system that returns the axle to a pre-defined position (with force from gravity or a rubber band) and set the motor in feathering mode to let it turn without resistance until the starting position is reached.
  
  The most convoluted way is to build your own position encoder: set up a sensor (push button, colour sensor or ultrasonic) that can tell when the axle is in the starting position, then when resetting, turn the motor while querying the sensor until the starting position is reached.
  
  
  ---
  
  ### Answer by username_4 on 2023-04-03. Score: 0
  
  Drive the motor at low power for some length of time in a direction until the door jams against some obstacle. Set the position sensor of the motor. Drive the motor to the desired starting position relative to the jammed position.
  
  This violates one of the constraints of the questions, since this would run before you ran your code. However, it is simple.
  
  
  ---
  
  