MATLAB Answers

How to make a Simulink model that pans LEGO EV3 motor between 2 encoder positions

3 views (last 30 days)
Benjamin Wagner
Benjamin Wagner on 24 Jan 2018
Answered: jeff matejka on 16 Feb 2019
Hey,
I am trying to create a Simulink model that turns a motor one direction until the encoder reads a certain angle and then, once hit, turns the other direction until it hits a lower angle. At the end, I want to return to the 0 position but am having trouble getting the motor to switch directions.
I attached what I thought would work for just changing the direction of the motor, however, if the encoder blows past the desired angle it will continue to rotate in the same direction forever. I have the default speed of the motor block set to 15 and I am using a LEGO Medium motor.
Any help will be greatly appreciated!

  0 Comments

Sign in to comment.

Answers (1)

jeff matejka
jeff matejka on 16 Feb 2019
if you haven't figured thus out yet: Calculate the difference between where you want the encoder to be and where you are, use that to control the speed. Without more info on your goal, theres multiple ways to implement this, such as using a compare block where if the difference is greater than zero, it keeps moving at your speed and when it is zero, you could multiple 0 times the speed. Or use a proportional controller to slow the motor gradually as it closes in on zero.
hope this helps

  0 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by