I’m in the process of using a mega 2560 board to control dual swing gates. The gates will be opened/closed by two gear motors. The motors will be controlled by an H gate motor driver(60 amp continuous 100 amp peak dual channel). There will be 4 limit switches(one set for closed and one set for open). The gates will also have to be timed. One will open a few seconds ahead of the other on the open command and the same on close command. There will be multiple “triggers” that prompt the gates to open(loop detectors, remote transmitter and receiver with clicker button…etc.)
I came across the following post…
Looking for general guidance for coding. Would the aforementioned post be a good starting point? Is there another method that would suffice? Any help is much appreciated.
Begin by producing a complete description of the task(s). It should be a design document using diagrams and words, no code at all. It should be as modular and heirarchical as possible, and leave out no details of the system. In your particular case, timing is important so you should make timing diagrams, showing all triggers, events and dependencies.
My coding skill level is solely based on what I’ve learned by lurking here and multiple other sites. No formal training. I can and have made the system work on a small scale. But the problem there is that I used a lot of delays and it was… well….ugly. Bull in a china shop approach if you will.
I’ve read up on state machines, switch case, millis and pretty much any other article that can be read. At this point, I’m trying to pick an approach and run with it.
It sounds like you are looking for examples to emulate, not approaches. Also you can never learn much from lurking. You need to make some serious study and independent practice. Avoid "pop" sites and go directly to authoritative references, especially for C++. Most of the information that is pushed out on popular platforms such as [sue me] is pure, unadulterated garbage. Recycling it won't look good on you.
I have written code for it(bread board prototype). But as stated before it was full of delays, and if and while statements. I guess the question is… is it worth pursuing another more efficient method when I carry it over into the actual project? Or take the “if it ain’t broke, don’t fix it” approach.
I have had a commercial version of your project for 15 years. The controller also checks for torque on the motors and stops that side of the gate when the torque reaches a limit. The gates sometime get blocked by snow.
Once you have an emergency stop of some type, how do you reset?
Also, another idea I have been kicking around is using switch case for two separate loops. The idea being that wind load could affect the timing of the gates. As in wind could inhibit one gate and assist the other if conditions were right with wind direction. This could possibly cause the two moving gates to jam against one another on the close sequence of timing tolerances were too tight.
Would it be possible to get a digital read from an Anemometer to change the variable for switch case? The idea being that case 1: would be normal operation and timing parameters and case 2: would only allow one gate at a time to operate.
I’ve thought about this scenario. What I had in mind is monitoring dc amps to correlate the relationship with torque. If x amount of amps is seen for x amount of time, stop.
As far as the reset, I think it would be best to physically be at the gates to inspect the reason for the stop condition.
MY gate system is a "Mighty Mule". The mechanical parts are DC motors driving a nut on a lead screw. The controller watches the RPM of each motor and counts the revolutions to know when to stop the movement. I suspect they detect a rapid decrease in RPM as a gate blockage. It may also watch the current to each motor, but I am not sure of that.