Dc motor position control

Hello. I am modelling a solar tracker in Simulink. I have 2 LDR sensors attaches on a pv panel, and they give a voltage output depending on the sun light each one receives. I want to write a function that will read the two voltages values and compute the difference and then command a DC motor(which rotate the panel) to rotate until that voltage difference becomes zero. My question is what should be the command to the motor? The motor simulink block I created has an input of voltage and outputs an angle. If I use a PID controller I have to specify the referenced desired angle but this is unknown. The desired angle is reached when the voltage difference of the sensors is zero. Whould it be correct if I use a PID controller to control the motor speed? And the output of the function will be the desired speed(to operate the motors) and 0 to stop the motors.

 Accepted Answer

Vasco Lenzi
Vasco Lenzi on 2 Jul 2020
Hi Eleni
I think the best approach would be to model the LDR sensors in Simulink as well. I believe you are using Simscape Multibody (from your previous questions) so you can place a "light source" approximating the sun and use the Transform Sensor to meaure angle and distance from this light source and then model their voltage behaviour. You can even move the light source using something akin the Point On Curve Constraint to mimick the day passing.
Then I would feed directly the the voltage difference of the sensors to the PID block. In the end the PID act on the DC motor and continue to act until the input to the PID block is 0. So I would simply use the voltage difference, but in order to model and tune it in Simulink with this approach you do need a model for the LDR sensors and the sun position.
Just my 2 cents, good luck.
Vasco

6 Comments

Hello Vasco. Thank you very much for the answers.
I already have a simulink model which contains an algorithm that calculates the sun position throughout the day, then calculates the sun radiation falling on the 2 sensors(based on the angle difference between the sun and each sensor) and then i use this radiation as an input to a photodiode in simscape to output a voltage, as shown in the figure :
So from there i compute the voltage difference and as you suggested i will then connect a PID and the DC motor to output the proper angle. That is for the simulink model. After that, i would like to use the multibody modelling to show the movement of the CAD model.
About the multibody modeling, i havent used simmechanics before and what you suggested sounds very useful, i wasn't aware of these cababilities. If I understood well i can model the sun movement (so tha will replace the algorithm i already have) and then use a transfrorm sensor to convert the distance and angles into voltage? So this means that i have to make the simulink model of LDRs to receive an angle/distance and output a voltage.?
About my previous question, is connecting the DC motor position from simulink to the CAD joints in multibody still needed or is this an alternative solution?
Thank you for your time
**Also, as i mentioned i was about to use an embedded matlab function (to be like a microcontroller) in order to make it more realistic concerning the hardware that is needed for the model. But if just taking the voltage difference into the PID has the same results i can use that.
Vasco Lenzi
Vasco Lenzi on 2 Jul 2020
Edited: Vasco Lenzi on 2 Jul 2020
Hi Eleni
great job on modeling the sensor and the sun position.
Your implementation seems fine as it is. Multibody model would do more than simpy showing the movement. It would allow you to add the proper inertia and loads to the DC motor, so that you can test your model in a more credible environment.
The transform sensor I mentioned is placed between two frames (let's say placed at the center of mass of two bodies) and will give you back measurement such as the angle and distance between the frames on the bodies. You would know for instance at which angle the normal vector of the panel is compared to the sun. You can then use this information to calculate irradiance and feed the irradiance in your simscape model of the sensor, that you already have.
I would use Simulink to model Embedded Software, because Simulink natively is used to model and generate C code for embedded software (instead of an embedded MATLAB function). You can model discrete time processing (as in a microcontroller), add discrete PID controllers and model even the ADC which is sampling the voltage of the LDR sensors. All of this is better done in Simulink, and put within a Model Reference or Atomic Subsystem to simulate discrete sampling time behaviour.
hope this helps
Vasco
PS: regarding model structure, your problem seems similar to what is presented in our getting started with Simulink:
Okay thank you very much. I already watched the video and have a model for the dc motors. I will watch the tutorial videos about multibody to be able to use the transform sensor and light source, and the connection of motors to joints.
As for the embedded software,am not sure if i understood. I am not going to use any hardware, i just want a realistic but simple way to model the microcontroller operation. I only know the basics of microcontroller, ADC, discrete time processing etc and am not quite sure how to model that in simulink. If there is any similar resource/tutorial/example that can help that would be great.
Otherwise, i will just use the PID control of the voltage reference directly.
Thank you
Vasco Lenzi
Vasco Lenzi on 6 Jul 2020
Edited: Vasco Lenzi on 6 Jul 2020
Simulink is really the best platform to model these basics such as ADC, discrete time etc. In this video they entered this discussion just superficially, by making the controller discrete:
You can model ADC by using blocks such as the Zero-Order Hold (continous to discrete transition) or Rate Transition block (continous to discrete or discrete-to-discrete with different sample times). DAC should be modeled from 2020a with the First-Order Hold block in the continous library. You can set the sampling time of a subsystem by making it an Atomic Subsystem or a Model Reference:
You can then graphically check how all discrete time in your controller play out by clicking on the Sample Time Legend:
Thank you very much, i am gonna try this.

Sign in to comment.

More Answers (0)

Asked:

on 29 Jun 2020

Commented:

on 10 Jul 2020

Community Treasure Hunt

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

Start Hunting!