Hi
I made myself a controller for a field sprayer with a few functions. I would like to do automatic pressure regulation, but I don't know how to go about it. I have a proportional valve and a flow meter installed in the sprayer. The valve is nothing more than a 12V DC motor which we turn once to one side or the other, increasing or decreasing the pressure. Changing the pressure, of course, changes the spray dose which is read by the flow meter.
The automatic would maintain the set dose at the appropriate level, regardless of the speed of the tractor. The data that I have at my disposal is the speed of the tractor, flow in l/min, after converting the currently read dose in l/ha. Motor control is done via L298n, i.e. I can control this motor by setting a specific voltage (PWM) and signal duration.
I have no idea for the algorithm that controls this motor. I only know that based on the difference between the set dose and the read dose, I can get values with different signs, then it would be possible to know which way to turn the motor so that the read dose is equal to the set one. But at what point to spin this motor, for how long, at what voltage, I have no idea. How to make this motor not react too nervous, but at the same time be able to maintain the dose at the set level.
If someone could come up with a concept, that would be great. The whole project is on atmega 328p
Greetings
Tryed PID controller but it's not suitable for my project. Generally I have 2 states: motor on and off, motor run forward or backward dependeng on dose value. Next question is how fast turn motor and how long?
It might be that you find the PID library difficult to understand and it might be that this PID-library is poorly documented.
You yourself mentioned PWM
And even in case of switching the motor on/off for some seconds all in all this IS PID-controlling.
The questions you have
including the question "How to make this motor not react too nervous?"
are ALL answered by a PID-control.
The answer is a PID-algorithm beeing "active"
to do exactly that.
It is not a must to use a PID-library to realise this.
If your code fullfills all the requirements you listed above this code represents a PID-algorithm.
My suggestion is that you post more details and the real numbers that you need for your project.
A L298-device can drive the motor but is pretty outdated.A L298 can drive only medium currents (1,5A per channel)
Using a sprayer on a tractor sounds like a big motor that will draw 5A maybe 10A or 20A)
in general, i believe you need to move the motor for a short period in one direction or the other, incrementally opening or closing the valve based on a fraction of the error between the desired flow and measured flow rates.
makes sense to start with a short on time for the motor and wait some period of time to allow the flow rate to change and for the measurement to be stable
of course, the time the motor is on can be made partially proportional to the error to reach equilibrium sooner. some tolerance seems necessary
A PID controller (or any closed-loop controller, for that matter), takes a desired output, compares it to the present output, and generates a new output that will get you to the desired point.
The actual quantities don't matter: the principle is the same. In your case, you have a desired flow rate, a measured flow rate and a valve that can control the flow. Now let's say that you limit the output of the PID controller to 0 - 100%. If you can convert this 0 - 100% to a set of PWM values that will determine how open the valve is, that will control the sprayer flow rate.
You do know that flow varies with the square root of pressure, if you want to double the flow, you have to increase pressure by 4 times. To halve the flow, decrease the pressure to 1/4 (25%).
I think you were using the PID wrong because it IS suitable for your project.
Set the OUTPUT limits to +/-255 (the default for the "PID_v1" library is 0-255). Then the SIGN of the output will tell you which direction to go and the MAGNITUDE of the output goes directly to your PWM value.
Hi guys, thx for that many answers, I was busy last 2 days. A little specyfications of valve, it's that yellow one
Motor inside valve start work at about 5V DC, in tractor I have about 14,4V so the range of speed is quiet big. I will try to make test stand for this procject. Actually can't use it on sparyer because we have winter in here ;(
Paul_KD7HB pressure depends on tractor speed, but when I drive tractor try to get constans speed
That was not my point. What I wanted to convey is that when you adjust ONE valve, the input pressure will change for ALL other valves. So all other valves will have to change their flow. And around and around we go!
A liquid cannot be compressed, unlike air. So you need a source that is NOT affected by any one or combination of your valves. Hydraulic systems are not compressed air systems.
Edit:
But the relatively easy fix it to add an air chamber to cushion the liquid pressure changes. Add a closed pipe to the fluid line. Position the pipe vertically so air in the pipe is compressed by the liquid. When the system is drained, the air will stay in the pipe. When one or more valve is opened, the compressed air will keep the fluid pressure from changing.
Your home water system has the same device to stop water hammer.
What you have posted is "some kind" of a datasheet but not with sufficient information.
What does
mean?
it takes 14 seconds for the valve to drive from totally closed to totally opened position?
or
maximum ON-time of the valve is 14 seconds and if yes how long must it be switched off to cool down?
If the 14 seconds are the opening/closing time I guess this is based on 12V.
You want to have a flow that creates constant dosing a constant number of liters per ha.
Which depends on the tractors speed.
You should specify:
Yes / No-question:
can you keep the tractorspeed constant enough so you don't need to measure tractor-speed and adjust liters per second to get in constant liter / ha dosing?
If tractor-speed varies too much so tractor-speed has to be included in the calculations.
What precision do you need: 0,1% or would be a deviation between optimum dosing and real dosing liter / ha of 10% accurate enough?
Commercial machines don't use air chamber as an external device, there is a place inside pupm playing same role
More complex photo of whole sprayer systems used in commercial machines
1- driver panel
2- speed sensor
3- filter
4- pump
5- pressure sensor
6- electrovalves on/off
7- flow meter
8- proportional valve, this is this I need to regaulate
9 - main electro valve on/off
10- sprayers
14sec. ON/OFF time means - 14 sec. from full open to full close, but mostly used is mid range
Exactly
Answer nope
When I set e.g. 210 litres/hectar it's acceptable range 205-215 Till now I manualy stayed with this range only affecting tractor speed.
A pump is pumping liquid. The liquid has to pass your proportional valve and has to pass a flow-meter. The speed of the tractor must be measured because the speed of the tractor can vary.
Then you have to do calculations based on speed and flowrate how much liters per hectar are sprayed out.
If there is deviation between wanted liters/ha (the setpoint) and real occuring liters/ha the microcontroller switches on the motor of the proportional valve to change the flowrate trying to match the setpoint-flowrate better.
You had a lot of initial questions. Most of them can't be answered from distance with generalised rules, because a lot of things depend on the real details.
The way to proceed is building up a first prototype of hardware and then starting with a prototype of software that works in principle.
And then doing measurements how your real system reacts.
Are you able to create a circular flow of water to build a test setup where you simply pump water from the tank through the system and after spraying the water is collected again to flow back into the tank?
Is the real liquid 95% water and because of this real liquid has almost the same viscosity as pure water?
Can you measure the tractor-speed how much the tractor-speed is varying ?
What
these questions can only be answered by measurings with the real system.
I would start with
maximum-voltage to be able to move the valve as quick as the valve can.
If something starts to oscillate the speed can always be reduced
I would build up a speed-sensor simulator with another a second microcontroller.
Take an ESP32 to have all options opened:
An ESP32 can be controlled by:
serial interface
bluetooth
WiFi (connecting your smartphone locally to a webinterface to adjust speed or speed-profiles)
potentiometer
The speed-sensor-simulator is then used to replay speed-profiles where the speed is varying in a reproducable way.
Your code will have serial output for debugging purposes printing measured numbers to the serial monitor or the serial plotter for analysing how the numbers stay constant or how the numbers deviate / oscillate
And then experimenting with the parameters to analyse what is the impact / the change
The great thing about PID is that inside a PID-algorithm the "P" the "I" and the "D" parameter can be adapted to achieve non oscillating still quick responses of the PID-controller to keep the dosing as constant as possible with the given components.
As you can see developping such a system is doable. It is exactly what engineers are doing.
But it will quite some time. As I have zero experience with such dosing systems I can't estimate how much time this will be and if your chosen components are really suitable for that purpose.
Here it might be good to do some duckduckgo-ing (instead of googling) for user-forums dedicated to agriculture and DIY-spraying systems
or for flow-controllers
can the valve turn 360 degrees into one direction multiple times without beeing damaged?
or
does the valve have mechanical endpositions ?
If yes what happens if the motor runs against the mechanical endstop and can't turn anymore?
post a picture and the datasheet of your speed-sensor
post a picture and the datasheet of your flowmeter
Having build a customised PCB in this early software-development-state seems unusual to me