⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplezonecontroller.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
字号:
package net.sf.dz.device.model.impl;import java.io.IOException;import java.util.Map;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.Set;import org.freehold.jukebox.conf.Configurable;import org.freehold.jukebox.conf.Configuration;import org.freehold.jukebox.logger.LogAware;import org.freehold.jukebox.logger.LogChannel;import net.sf.dz.device.actuator.Damper;import net.sf.dz.device.model.DamperController;import net.sf.dz.device.model.Thermostat;import net.sf.dz.device.model.Unit;/** * A simple A/C zone controller. * * <p> * * Doesn't do anything fancy, just switches on the A/C when one or more of * the thermostats issues the signal with the value more than 1.0, and shuts * it off when all the thermostats issue the signal less than -1.0. As the * value of the signal raises above 1.0, the dampers are being open, as it * falls below -1.0, the dampers are being closed. * * <p> * * <strong>Correction:</strong> those -1.0 and 1.0 not absolute, but * relative - they have to be adjusted depending on the A/C mode. * * @author Copyright &copy; <a href="mailto:vt@freehold.crocodile.org">Vadim Tkachenko</a> 2001 * @version $Id: SimpleZoneController.java,v 1.3 2004/01/20 02:40:34 vtt Exp $ */public class SimpleZoneController extends AbstractZoneController {    public static final LogChannel CH_SZC = new LogChannel("ZCTL/Simple");        protected DamperController dc;        protected void configure() throws Throwable {            super.configure();            }        public void attach(Unit unit) {            super.attach(unit);            this.dc = unit.getDamperController();    }        protected Double controlSignalChanged(Thermostat source, double signal, Double currentDemand) {            int mode = unit.getAC().getMode();            // If the signal is within ctl_happy to ctl_unhappy range, nothing        // happens.            if ( unhappy(signal) ) {                    if ( unhappyTs.contains(source) ) {                            // Don't do anything                                return null;            }                    // See if this room is allowed to switch on the A/C                        if ( !source.isVoting() && !unit.getAC().isRunning() ) {                            // Don't do anything                                complain(LOG_INFO, CH_SZC, "Not voting: " + source.getName());                return null;            }                        // OK, we're allowed to vote ;)                        unhappyTs.add(source);                        complain(LOG_INFO, CH_SZC, "Unhappy: " + source.getName());                        // Ask the other thermostats if they want the A/C and open their            // dampers for them if so                        // Implicitly, our damper will be open as well                        for ( Iterator i = tsSignalMap.keySet().iterator(); i.hasNext(); ) {                            Thermostat ts = (Thermostat)i.next();                                if ( wantsPiggyback(ts.getControlSignal() * -mode) ) {                                    damperController.set(dc.getDamper(ts), 1);                    unhappyTs.add(source);                                        //complain(LOG_INFO, CH_SZC, ts.getName() + ": ac on: damper 1");                }            }            // Turn on the A/C (this is done implicitly in super.commit())            // The return is not really needed here, I just want to            // emphasize that nothing else happens                        return currentDemand;                    } else if ( happy(signal) ) {                    if ( unhappyTs.isEmpty() ) {                            // The A/C is already off                                // Shut the damper anyway                                damperController.set(dc.getDamper(source), 0);                                return null;            }                    // OK, *we* are satisfied.                        unhappyTs.remove(source);            damperController.set(dc.getDamper(source), 0);                        // Let's check if all the thermostats are satisfied                        if ( unhappyTs.isEmpty() ) {                            // Everybody's happy, turn off the A/C                currentDemand = new Double(0);                                // Future: open all the dampers and allow the air handler                // to run until the exhaust air temperature gets close to                // intake air temperature                //complain(LOG_NOTICE, CH_SZC, "Switching the A/C OFF");                for ( Iterator i = tsSignalMap.keySet().iterator(); i.hasNext(); ) {                                    Thermostat ts = (Thermostat)i.next();                                        damperController.set(dc.getDamper(ts), 0);                }            }                        return currentDemand;        }                // Again, if the signal is between "unhappy" and "happy", nothing        // happens                return null;    }        /**     * Check if the signal is "unhappy".     *     * For cooling, it would be above 1.0, for heating, below -1.0.  If the     * A/C is off, the signal is never unhappy.     *     * @param signal Signal to check.     */    protected boolean unhappy(double signal) {            return signal >= ctl_unhappy;    }    /**     * Check if the signal is "happy".     *     * For cooling, it would be below -1.0, for heating, above 1.0.  If the     * A/C is off, the signal is always happy.     *     * @param signal Signal to check.     */    protected boolean happy(double signal) {            return signal <= ctl_happy;    }    /**     * Check if the signal is "wants piggyback".     *     * For cooling, it would be above 0, for heating, below 0.  If the     * A/C is off, the signal never wants the piggyback.     *     * @param signal Signal to check.     */    protected boolean wantsPiggyback(double signal) {            return signal > 0;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -