SK21 / AOG_RC

AgOpenGPS rate control.
Other
32 stars 8 forks source link

Relay-controlled valve #10

Closed mirh closed 1 year ago

mirh commented 3 years ago

Long story short, my flow valve has a motor that works with polarity reversal. And through the power of DPDT switches, we could just say it has two commands/states: "more" and "less".

I tried to half ass together something in Motor.ino, but clearly there's so much more to it. Would it be too hard and disruptive to add support for this?

SK21 commented 3 years ago

Are you using the motor option or the standard valve?

mirh commented 3 years ago

I tried to tinker with the standard valve code, after having retooled the PWM pin to be just a digital one outputting the opposite of the direction state... but it kinda failed. But I think this would be worth a new type of motor tbh (is "proportional" even the right word? I have no control on the velocity, maybe "linear valve" would be better?) since nothing in the PID settings tab would apply.

SK21 commented 3 years ago

I am not clear on how your motor works. A standard valve has more and less commands. The motor control varies the voltage from 0 to 12 v.

Do you have a model # or link to a page about the motor?

mirh commented 3 years ago

I have this brochure (last one) about the body, and this should be the valve-only.

A standard valve has more and less commands.

Yeah, but you also have PWM to regulate speed, while "effect direction" is the state of a single relay. Here instead, you just supply +12V or -12V (which at the end of the day I made to correspond to two separate relays) and that's about it.

SK21 commented 3 years ago

In the last brochure about the valve it looks like the motor only controls on/off, not flow.

Capture

mirh commented 3 years ago

It's on/off in a sense, yes. But the "obturator" can end up sitting in more than just two states, if I can explain. And this way (since polarity reversal makes for two separate "ON" eventually) you can control flow.

bduncan175 commented 3 years ago

It sounds like his valve is similar to a standard raven flow control valve that is plumbed as a bypass system, but can also completely shut off. https://www.spraysmarter.com/raven-precision-1-poly-control-valve-flanged.html?gclid=CjwKCAjw-ZCKBhBkEiwAM4qfF1c-M0oKpccFcGTAFIvWbRJOzAW5RACnZJ9z2HZ7LF6Ss77eIKoxUhoCoMEQAvD_BwE

mirh commented 3 years ago

Sorry, I snafued the valve brochure. This should be the right one. To reiterate again: with +12V (i.e. one relay) the ball rotates in one direction, with -12V (an other relay) the opposite one.

SK21 commented 3 years ago

So you would like to control the pressure with 2 relays, one for increase and one for decrease? A motor controller would not be used. I could change the code to add another control type that would use relays instead of a motor controller.

Motor.ino: Capture

SK21 commented 3 years ago

Should be:

Capture

SK21 commented 3 years ago

It could also work with a motor controller if the PWM is set to maximum. This would give 12V.

Capture

mirh commented 3 years ago

A motor controller would not be used.

I think the confusion is due to the valve mechanism technically having one, but the DPDT wiring I used making it logically be just two switches (I mean, I'm not sure how else I could have controlled polarity inversion otherwise).

Anyhow

// use 2 relays for flow control
if (FlowEnabled[i])
          {
              if (pwmSetting[i] > 0)
              {
                  // increase
                  digitalWrite(FlowDir[i], 1);
                  digitalWrite(FlowPWM[i], 0);
              }
              else if (pwmSetting[i] < 0)
              {
                  // decrease
                  digitalWrite(FlowDir[i], 0);
                  digitalWrite(FlowPWM[i], 1);
              }
              else
              {
                  // no change
                  digitalWrite(FlowDir[i], 0);
                  digitalWrite(FlowPWM[i], 0);
              }
          }
          break;

was exactly what I needed (at least when I replaced the fast close valve block for testing purposes).

I think maybe you could replace the PID tab in this case, and have some kind of "tolerance" value to be set? Without derivative control the relays aren't gonna have a good time otherwise when near the target rate.

SK21 commented 3 years ago

In the PID tab Deadband is the "tolerance" setting. In this example if the error is within 4% no adjustment is made. The other settings will just be ignored.

pid

This occurs in PID.ino. sDeadband is the 4 from the PID tab. The sub returns 0 if within the tolerance, so the relays should both be off in the your block above.

pidCal

mirh commented 3 years ago

I see, sorry (not that my coarse testing with the "manually spun" flowmeter could have shown it working probably, lol) I guess it would still be kinda more polished if the UI reflected the underlying enabled logic, but it's no biggie.

Btw while flow control responds and offset adequately when I turn off some section, when all of them are closed it seems like signals are still being sent to the valve.

SK21 commented 3 years ago

I think the "if (FlowEnabled[i])" statement needs to be removed in your block above to prevent signals still being sent. Just use:

Capture

mirh commented 3 years ago

Thank you so much! With combo close now everything is just right (I still have some idea for target rate adjustments on-screen buttons, and hooking the "master valve", but that will be for another time I guess)

Do you accept donations by any chance?

mirh commented 1 year ago

I'm once again in need of help, since my understanding skills are quite limited (and given every test involves wasting decalitres of water and stressing the valve, for once I don't exactly feel like trying too much)

I attempted to port the code above (no FlowEnabled, all digitalWrite, only 0s and 1s) to the new Motor.ino. But I could never get both to work independently of each other (i.e. even when I managed to have both "do anything", they either stuck together enabled or disabled depending on the situation). Moreover (at least when trying the "motor" control type) the max/min PWM values still seem to have an effect And last I even took take a stab at using the original pin values, only finding that then I had FlowOnDirection to keep an eye on too.

mirh commented 1 year ago

Ok well, I quite literally just re-repeated the code above and it worked this time. If the merit wasn't to be with some of your latest commits, I suppose it could be with me possibly having mixed up the pin numbers due to the different order the original lines have. https://github.com/SK21/AOG_RC/blob/feeb3e6a7ddbb1c69c3beb8bc7b5be15e5b7a55b/Modules/Nano/RCnano/Motor.ino#L24-L32 The only "novelty" is that I also have to remember to set PWM maximum to 255.