~ubuntu-branches/ubuntu/oneiric/electric/oneiric

« back to all changes in this revision

Viewing changes to com/sun/electric/tool/simulation/test/PowerChannelResistorVoltageReadable.java

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2010-01-09 16:26:04 UTC
  • mfrom: (1.1.4 upstream) (3.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100109162604-1ypvmy8ijmlc6oq7
Tags: 8.10-1
* New upstream version.
* debian/control
  - Add libjava3d-java and quilt build dependencies.
  - Update standards version to 3.8.3.
  - Add libjava3d-java as recommends to binary package.
* debian/rules
  - Use quilt patch system instead of simple patchsys.
  - Add java3d related jar files to DEB_JARS.
* debian/patches/*
  - Update as per current upstream source. Convert to quilt.
* debian/ant.properties
  - Do not disable 3D plugin anymore.
  - Use new property to disable compilation of OS X related classes.
* debian/wrappers/electric
  - Add java3d related jar files to runtime classpath.
* debian/README.source
  - Change text to the appropriate one for quilt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.sun.electric.tool.simulation.test;
 
2
 
 
3
/**
 
4
 * Assuming you have a PowerChannel with a resistor attached to the
 
5
 * output and a VoltageReadable across the resistor, this will act
 
6
 * like a PowerChannel+CurrentReadable that lets you set the voltage
 
7
 * across the load as long as it maintains a reasonably stable current
 
8
 * draw.
 
9
 *
 
10
 *    +--------------+         resistor         +------+
 
11
 * +--| PowerChannel |---------/\/\/\/\---------| load |---+
 
12
 * |  +--------------+  ^                   ^   +------+   |
 
13
 * |                    |                   |              |
 
14
 * |                    +- VoltageReadable -+              |
 
15
 * |                                                       |
 
16
 * +-------------------------------------------------------+
 
17
 *
 
18
 * @author md227184 (wrote FastProxEquipment, from which this is derived)
 
19
 * @author megacz
 
20
 */
 
21
public class PowerChannelResistorVoltageReadable extends PowerChannel {
 
22
 
 
23
    private boolean fastConvergence;
 
24
    private PowerChannel pc;
 
25
    private double ohms;
 
26
    private VoltageReadable vr;
 
27
    private static float EPSILON_VOLTS = 0.01f;
 
28
 
 
29
    public void setCurrent(float amps) { pc.setCurrent(amps); }
 
30
    public float getCurrentSetpoint() { return pc.getCurrentSetpoint(); }
 
31
    public float readCurrent() {
 
32
        double pc_current = pc.readCurrent();
 
33
        double vr_current = vr.readVoltage() / ohms;
 
34
        if (Math.abs(pc_current - vr_current) > EPSILON_VOLTS * ohms)
 
35
            throw new RuntimeException("PowerChannel and VoltageReadable disagree on current; perhaps you gave the wrong resistor value?\n" +
 
36
                                       "  PowerChannel    says: " + pc_current + "\n" +
 
37
                                       "  VoltageReadable says: " + vr_current);
 
38
        return (float)vr_current;
 
39
    }
 
40
    public float readVoltage() {
 
41
        readCurrent();  // to force the sanity check
 
42
        return pc.readVoltage() - vr.readVoltage();
 
43
    }
 
44
    public void setVoltageNoWait(float volts) { throw new RuntimeException("cannot do this in a "+this.getClass().getName()); }
 
45
    public void waitForVoltage(float setVolts) { throw new RuntimeException("cannot do this in a "+this.getClass().getName()); }
 
46
    public float getVoltageSetpoint() { throw new RuntimeException("cannot do this in a "+this.getClass().getName()); }
 
47
    public void setVoltageWait(float v) {
 
48
        readCurrent();  // to force the sanity check
 
49
        while(true) {
 
50
            double vs = pc.readVoltage();
 
51
            double vread = vr.readVoltage();
 
52
            double i = vread/1000;
 
53
            double vl = (vs-ohms*i);
 
54
            System.err.print("\r\033[0K\r");
 
55
            System.err.print(this.getClass().getSimpleName()+
 
56
                             ".setVoltageWait():"+
 
57
                             " desired/actual="+v+"/"+vl);
 
58
            if (vl+EPSILON_VOLTS < v || vl-EPSILON_VOLTS > v) {
 
59
                if (fastConvergence) {
 
60
                    double delta = v+i*ohms - vs;
 
61
                    delta *= 1.5;
 
62
                    vs = vs + delta;
 
63
                } else {
 
64
                    vs = v+i*ohms;
 
65
                }
 
66
                pc.setVoltageWait((float)vs);
 
67
            } else {
 
68
                readCurrent();  // to force the sanity check
 
69
                System.err.print("\r\033[0K\r");
 
70
                break;
 
71
            }
 
72
        }
 
73
    }
 
74
 
 
75
    public PowerChannelResistorVoltageReadable(PowerChannel pc,
 
76
                                               float ohmsOfResistor,
 
77
                                               VoltageReadable voltMeterAcrossResistor,
 
78
                                               boolean fastConvergence) {
 
79
        this.pc = pc;
 
80
        this.ohms = ohmsOfResistor;
 
81
        this.vr = voltMeterAcrossResistor;
 
82
        this.fastConvergence = fastConvergence;
 
83
    }
 
84
 
 
85
}