MATLAB Answers

0

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

Asked by Benjamin Wagner on 24 Jan 2018
Latest activity Answered by 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.

1 Answer

Answer by 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.