summaryrefslogtreecommitdiffstats
path: root/pressure_control
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2009-06-13 15:04:02 +0200
committerMichael Buesch <mb@bu3sch.de>2009-06-13 15:04:02 +0200
commitfc3276d57c54af5929b1f02f2c271058e025d163 (patch)
tree62d07d582db2538aaf144019370f452eaaed2119 /pressure_control
parentf78d0963af065e55a64c383d2ad8b00247f75977 (diff)
downloadcnc-fc3276d57c54af5929b1f02f2c271058e025d163.tar.xz
cnc-fc3276d57c54af5929b1f02f2c271058e025d163.zip
pressure_control: Add support for two control circuits
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Diffstat (limited to 'pressure_control')
-rw-r--r--pressure_control/firmware/main.c72
-rw-r--r--pressure_control/firmware/main.h16
-rw-r--r--pressure_control/firmware/remote.c120
-rw-r--r--pressure_control/firmware/remote.h17
-rwxr-xr-xpressure_control/remote/pctl-remote282
5 files changed, 316 insertions, 191 deletions
diff --git a/pressure_control/firmware/main.c b/pressure_control/firmware/main.c
index 65443cc..0534231 100644
--- a/pressure_control/firmware/main.c
+++ b/pressure_control/firmware/main.c
@@ -33,18 +33,20 @@
struct eeprom_data {
- struct pressure_config cfg;
+ struct pressure_config cfg_xy;
+ struct pressure_config cfg_z;
};
/* The pressure configuration data. */
-struct pressure_config cfg;
+struct pressure_config cfg_xy;
+struct pressure_config cfg_z;
/* The pressure state data. */
struct pressure_state state;
/* The 1000Hz jiffies counter */
static jiffies_t jiffies_counter;
DEFINE_VALVE(xy_control_valves, VALVES_2MAG, D, 6, 7, 4, 5);
-DEFINE_VALVE(z_control_valves, VALVES_1MAG, C, 2, 3, 4, 5);
+DEFINE_VALVE(z_control_valves, VALVES_1MAG, C, 2, -1, 3, -1);
static DEFINE_SENSOR(xy_control_sensor, 0, 245, 4400, 10000);
static DEFINE_SENSOR(z_control_sensor, (1<<MUX0), 245, 4400, 10000);
@@ -53,9 +55,14 @@ static uint8_t sensor_cycle;
/* EEPROM contents */
static struct eeprom_data EEMEM eeprom = {
- .cfg = {
+ .cfg_xy = {
.desired = 2500, /* Millibar */
- .hysteresis = 200, /* Millibar */
+ .hysteresis = 150, /* Millibar */
+ .autoadjust_enable = 1,
+ },
+ .cfg_z = {
+ .desired = 1500, /* Millibar */
+ .hysteresis = 150, /* Millibar */
.autoadjust_enable = 1,
},
};
@@ -65,7 +72,8 @@ static struct eeprom_data EEMEM eeprom = {
static void eeprom_load_config(void)
{
eeprom_busy_wait();
- eeprom_read_block(&cfg, &eeprom.cfg, sizeof(cfg));
+ eeprom_read_block(&cfg_xy, &eeprom.cfg_xy, sizeof(cfg_xy));
+ eeprom_read_block(&cfg_z, &eeprom.cfg_z, sizeof(cfg_z));
eeprom_busy_wait();
}
@@ -73,25 +81,30 @@ static void eeprom_load_config(void)
static void eeprom_store_config(void)
{
eeprom_busy_wait();
- eeprom_write_block(&cfg, &eeprom.cfg, sizeof(cfg));
+ eeprom_write_block(&cfg_xy, &eeprom.cfg_xy, sizeof(cfg_xy));
+ eeprom_write_block(&cfg_z, &eeprom.cfg_z, sizeof(cfg_z));
eeprom_busy_wait();
}
-void get_pressure_config(struct pressure_config *ret)
+void get_pressure_config(struct pressure_config *xy,
+ struct pressure_config *z)
{
uint8_t sreg;
sreg = irq_disable_save();
- memcpy(ret, &cfg, sizeof(*ret));
+ memcpy(xy, &cfg_xy, sizeof(*xy));
+ memcpy(z, &cfg_z, sizeof(*z));
irq_restore(sreg);
}
-void set_pressure_config(struct pressure_config *new_cfg)
+void set_pressure_config(struct pressure_config *new_xy,
+ struct pressure_config *new_z)
{
uint8_t sreg;
sreg = irq_disable_save();
- memcpy(&cfg, new_cfg, sizeof(cfg));
+ memcpy(&cfg_xy, new_xy, sizeof(cfg_xy));
+ memcpy(&cfg_z, new_z, sizeof(cfg_z));
eeprom_store_config();
irq_restore(sreg);
}
@@ -143,7 +156,10 @@ void system_timer_init(void)
/* Check the current pressure value against the desired value and
* adjust the pressure if needed. */
-static void do_check_pressure(struct valves *valves, uint16_t mbar)
+static void do_check_pressure(struct valves *valves,
+ struct pressure_config *cfg,
+ uint16_t mbar,
+ uint16_t *reported_mbar)
{
int32_t offset;
uint16_t abs_offset;
@@ -151,20 +167,20 @@ static void do_check_pressure(struct valves *valves, uint16_t mbar)
bool report_change = 0;
uint8_t cur_state;
- if (cfg.autoadjust_enable) {
- offset = (int32_t)mbar - (int32_t)cfg.desired;
+ if (cfg->autoadjust_enable) {
+ offset = (int32_t)mbar - (int32_t)cfg->desired;
abs_offset = abs(offset);
is_too_big = (offset >= 0);
cur_state = valves_get_global_state(valves);
- if (abs_offset > cfg.hysteresis) {
+ if (abs_offset > cfg->hysteresis) {
/* Adjust the pressure */
report_change = (cur_state == VALVES_IDLE);
if (is_too_big)
valves_global_switch(valves, VALVES_FLOW_OUT);
else
valves_global_switch(valves, VALVES_FLOW_IN);
- } else if (abs_offset > cfg.hysteresis / 4) {
+ } else if (abs_offset > cfg->hysteresis / 4) {
/* If we're idle, stay idle.
* If we're increasing or decreasing pressure,
* keep on doing this to reach the desired center value
@@ -186,11 +202,12 @@ static void do_check_pressure(struct valves *valves, uint16_t mbar)
valves_disarm_auto_idle(valves);
}
}
- if (abs((int32_t)mbar - (int32_t)state.reported_mbar) >= 100)
+ if (abs((int32_t)mbar - (int32_t)(*reported_mbar)) >= 100)
report_change = 1;
if (report_change) {
- remote_pressure_change_notification(mbar);
- state.reported_mbar = mbar;
+ remote_pressure_change_notification(state.measured_mbar_xy,
+ state.measured_mbar_z);
+ *reported_mbar = mbar;
}
}
@@ -198,10 +215,20 @@ static void check_pressure(void)
{
switch (sensor_cycle) {
case SENSOR_CYCLE_XY:
- do_check_pressure(&xy_control_valves, state.measured_mbar);
+ state.measured_mbar_xy = state.measured_mbar;
+ if (state.device_enabled) {
+ do_check_pressure(&xy_control_valves, &cfg_xy,
+ state.measured_mbar_xy,
+ &state.reported_mbar_xy);
+ }
break;
case SENSOR_CYCLE_Z:
- do_check_pressure(&z_control_valves, state.measured_mbar);
+ state.measured_mbar_z = state.measured_mbar;
+ if (state.device_enabled) {
+ do_check_pressure(&z_control_valves, &cfg_z,
+ state.measured_mbar_z,
+ &state.reported_mbar_z);
+ }
break;
default:
BUG_ON(1);
@@ -281,8 +308,7 @@ int main(void)
mb();
now = get_jiffies();
if (state.needs_checking) {
- if (state.device_enabled)
- check_pressure();
+ check_pressure();
/* Trigger another measurement in
* a few milliseconds. */
if (++sensor_cycle == __NR_SENSOR_CYCLE)
diff --git a/pressure_control/firmware/main.h b/pressure_control/firmware/main.h
index 279b7e0..28b15c1 100644
--- a/pressure_control/firmware/main.h
+++ b/pressure_control/firmware/main.h
@@ -44,10 +44,16 @@ struct pressure_config {
struct pressure_state {
/* Sensing and adjustment logic enabled? */
bool device_enabled;
- /* The last measured pressure (in mBar) */
+ /* The last measured pressure (in mBar).
+ * It depends on sensor_cycle which valves this
+ * value belongs to. */
uint16_t measured_mbar;
+ /* The current pressure for the individual valves */
+ uint16_t measured_mbar_xy;
+ uint16_t measured_mbar_z;
/* Reported pressure via RS232 */
- uint16_t reported_mbar;
+ uint16_t reported_mbar_xy;
+ uint16_t reported_mbar_z;
/* True, if the current pressure value needs checking against
* the desired pressure config. */
bool needs_checking;
@@ -58,8 +64,10 @@ struct pressure_state {
int8_t sensor_trigger_cnt;
};
-void get_pressure_config(struct pressure_config *cfg);
-void set_pressure_config(struct pressure_config *cfg);
+void get_pressure_config(struct pressure_config *xy,
+ struct pressure_config *z);
+void set_pressure_config(struct pressure_config *xy,
+ struct pressure_config *z);
void get_pressure_state(struct pressure_state *state);
void prepare_turn_on(void);
void prepare_shutdown(void);
diff --git a/pressure_control/firmware/remote.c b/pressure_control/firmware/remote.c
index b6d6141..1945ef4 100644
--- a/pressure_control/firmware/remote.c
+++ b/pressure_control/firmware/remote.c
@@ -29,8 +29,8 @@
#include <avr/io.h>
-#define BAUDRATE 38400 /* Error = 0.2% */
-#define USE_2X 0
+#define BAUDRATE 115200
+#define USE_2X 1
static struct remote_message rx_msg;
@@ -119,95 +119,123 @@ static void handle_received_message(void)
case MSG_GET_CURRENT_PRESSURE: {
struct pressure_state state;
-//FIXME
get_pressure_state(&state);
reply.id = MSG_CURRENT_PRESSURE;
- reply.pressure.mbar = state.measured_mbar;
+ reply.pressure.mbar[0] = state.measured_mbar_xy;
+ reply.pressure.mbar[1] = state.measured_mbar_z;
send_message(&reply);
break;
}
case MSG_GET_DESIRED_PRESSURE: {
- struct pressure_config conf;
+ struct pressure_config xy, z;
- get_pressure_config(&conf);
+ get_pressure_config(&xy, &z);
reply.id = MSG_DESIRED_PRESSURE;
- reply.pressure.mbar = conf.desired;
+ reply.pressure.mbar[0] = xy.desired;
+ reply.pressure.mbar[1] = z.desired;
send_message(&reply);
break;
}
case MSG_GET_HYSTERESIS: {
- struct pressure_config conf;
+ struct pressure_config xy, z;
- get_pressure_config(&conf);
+ get_pressure_config(&xy, &z);
reply.id = MSG_HYSTERESIS;
- reply.pressure.mbar = conf.hysteresis;
+ reply.pressure.mbar[0] = xy.hysteresis;
+ reply.pressure.mbar[1] = z.hysteresis;
send_message(&reply);
break;
}
case MSG_GET_CONFIG_FLAGS: {
- struct pressure_config conf;
+ struct pressure_config xy, z;
- get_pressure_config(&conf);
+ get_pressure_config(&xy, &z);
reply.id = MSG_CONFIG_FLAGS;
- if (conf.autoadjust_enable)
- reply.config.flags |= (1 << CFG_FLAG_AUTOADJUST_ENABLE);
+ if (xy.autoadjust_enable)
+ reply.config.flags[0] |= (1 << CFG_FLAG_AUTOADJUST_ENABLE);
+ if (z.autoadjust_enable)
+ reply.config.flags[1] |= (1 << CFG_FLAG_AUTOADJUST_ENABLE);
send_message(&reply);
break;
}
case MSG_SET_DESIRED_PRESSURE: {
- struct pressure_config conf;
+ struct pressure_config xy, z;
cli();
- get_pressure_config(&conf);
- conf.desired = rx_msg.pressure.mbar;
- set_pressure_config(&conf);
+ get_pressure_config(&xy, &z);
+ if (rx_msg.setpressure.island == 0)
+ xy.desired = rx_msg.setpressure.mbar;
+ else if (rx_msg.setpressure.island == 1)
+ z.desired = rx_msg.setpressure.mbar;
+ set_pressure_config(&xy, &z);
sei();
break;
}
case MSG_SET_HYSTERESIS: {
- struct pressure_config conf;
+ struct pressure_config xy, z;
cli();
- get_pressure_config(&conf);
- conf.hysteresis = rx_msg.pressure.mbar;
- set_pressure_config(&conf);
+ get_pressure_config(&xy, &z);
+ if (rx_msg.setpressure.island == 0)
+ xy.hysteresis = rx_msg.setpressure.mbar;
+ else if (rx_msg.setpressure.island == 1)
+ z.hysteresis = rx_msg.setpressure.mbar;
+ set_pressure_config(&xy, &z);
sei();
break;
}
case MSG_SET_CONFIG_FLAGS: {
- struct pressure_config conf;
+ struct pressure_config xy, z;
bool flag;
cli();
- get_pressure_config(&conf);
- flag = !!(rx_msg.config.flags & (1 << CFG_FLAG_AUTOADJUST_ENABLE));
- if (conf.autoadjust_enable != flag) {
- conf.autoadjust_enable = flag;
- /* Make sure the values are idle. */
- valves_global_switch(&xy_control_valves, VALVES_IDLE);
+ get_pressure_config(&xy, &z);
+ flag = !!(rx_msg.setconfig.flags & (1 << CFG_FLAG_AUTOADJUST_ENABLE));
+ if (rx_msg.setconfig.island == 0) {
+ if (xy.autoadjust_enable != flag) {
+ xy.autoadjust_enable = flag;
+ /* Make sure the values are idle. */
+ valves_global_switch(&xy_control_valves, VALVES_IDLE);
+ }
+ } else if (rx_msg.setconfig.island == 1) {
+ if (z.autoadjust_enable != flag) {
+ z.autoadjust_enable = flag;
+ /* Make sure the values are idle. */
+ valves_global_switch(&z_control_valves, VALVES_IDLE);
+ }
}
- set_pressure_config(&conf);
+ set_pressure_config(&xy, &z);
sei();
break;
}
case MSG_SET_VALVE: {
- struct pressure_config conf;
+ struct pressure_config xy, z;
+ struct valves *v;
- get_pressure_config(&conf);
- if (conf.autoadjust_enable) {
- err = MSG_ERR_BUSY;
- break;
+ get_pressure_config(&xy, &z);
+ if (rx_msg.valve.island == 0) {
+ if (xy.autoadjust_enable) {
+ err = MSG_ERR_BUSY;
+ break;
+ }
+ v = &xy_control_valves;
+ } else {
+ if (z.autoadjust_enable) {
+ err = MSG_ERR_BUSY;
+ break;
+ }
+ v = &z_control_valves;
}
if (rx_msg.valve.nr == 0) {
- valve0_switch(&xy_control_valves, rx_msg.valve.state == 0 ?
+ valve0_switch(v, rx_msg.valve.state == 0 ?
VALVE_STATE_CLOSE : VALVE_STATE_OPEN);
- valve_wait_toggle(&xy_control_valves);
- valve0_switch(&xy_control_valves, VALVE_STATE_IDLE);
+ valve_wait_toggle(v);
+ valve0_switch(v, VALVE_STATE_IDLE);
} else if (rx_msg.valve.nr == 1) {
- valve1_switch(&xy_control_valves, rx_msg.valve.state == 0 ?
+ valve1_switch(v, rx_msg.valve.state == 0 ?
VALVE_STATE_CLOSE : VALVE_STATE_OPEN);
- valve_wait_toggle(&xy_control_valves);
- valve0_switch(&xy_control_valves, VALVE_STATE_IDLE);
+ valve_wait_toggle(v);
+ valve0_switch(v, VALVE_STATE_IDLE);
} else
err = MSG_ERR_INVAL;
break;
@@ -215,6 +243,7 @@ static void handle_received_message(void)
case MSG_SHUTDOWN:
prepare_shutdown();
valves_shutdown(&xy_control_valves);
+ valves_shutdown(&z_control_valves);
break;
case MSG_TURNON:
prepare_turn_on();
@@ -383,13 +412,14 @@ void remote_work(void)
sei();
}
-void remote_pressure_change_notification(uint16_t mbar)
+void remote_pressure_change_notification(uint16_t xy_mbar, uint16_t z_mbar)
{
struct remote_message msg;
memset(&msg, 0, sizeof(msg));
msg.id = MSG_CURRENT_PRESSURE;
- msg.pressure.mbar = mbar;
+ msg.pressure.mbar[0] = xy_mbar;
+ msg.pressure.mbar[1] = z_mbar;
send_message(&msg);
}
@@ -418,8 +448,8 @@ static void usart_init(void)
#if USE_2X
UCSRA = (1 << U2X);
#endif
- /* 8 Data bits, 1 Stop bit, No parity */
- UCSRC = (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
+ /* 8 Data bits, 2 Stop bits, No parity */
+ UCSRC = (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1) | (1 << USBS);
/* Enable transceiver and RX IRQs */
UCSRB = (1 << RXEN) | (1 << TXEN) | (1 << RXCIE);
/* Drain the RX buffer */
diff --git a/pressure_control/firmware/remote.h b/pressure_control/firmware/remote.h
index 709a1f0..c587782 100644
--- a/pressure_control/firmware/remote.h
+++ b/pressure_control/firmware/remote.h
@@ -57,13 +57,22 @@ struct remote_message {
char str[8];
} __attribute__((packed)) logmessage;
struct {
- uint16_t mbar;
+ uint16_t mbar[2];
} __attribute__((packed)) pressure;
struct {
- uint32_t flags;
+ uint8_t island; /* Valve island */
+ uint16_t mbar;
+ } __attribute__((packed)) setpressure;
+ struct {
+ uint32_t flags[2];
} __attribute__((packed)) config;
struct {
- uint8_t nr; /* Valve ID */
+ uint8_t island; /* Valve island */
+ uint32_t flags;
+ } __attribute__((packed)) setconfig;
+ struct {
+ uint8_t island; /* Valve island */
+ uint8_t nr; /* Valve ID in the island */
uint8_t state;
} __attribute__((packed)) valve;
@@ -81,7 +90,7 @@ void print_dec(uint16_t number);
void print_dec_signed(int16_t number);
void print_hex(uint8_t number);
-void remote_pressure_change_notification(uint16_t mbar);
+void remote_pressure_change_notification(uint16_t xy_mbar, uint16_t z_mbar);
void remote_notify_restart(void);
void remote_work(void);
diff --git a/pressure_control/remote/pctl-remote b/pressure_control/remote/pctl-remote
index 57887bd..4a9989e 100755
--- a/pressure_control/remote/pctl-remote
+++ b/pressure_control/remote/pctl-remote
@@ -29,10 +29,10 @@ from PyQt4.QtGui import *
# Serial communication port configuration
-CONFIG_BAUDRATE = 38400
+CONFIG_BAUDRATE = 115200
CONFIG_BYTESIZE = 8
CONFIG_PARITY = PARITY_NONE
-CONFIG_STOPBITS = 1
+CONFIG_STOPBITS = 2
# The size of one message
MSG_SIZE = 12
@@ -74,7 +74,7 @@ CFG_FLAG_AUTOADJUST_ENABLE = 0
def usage():
print "Pressure control - remote configuration"
print ""
- print "Copyright (C) 2008 Michael Buesch <mb@bu3sch.de>"
+ print "Copyright (C) 2008-2009 Michael Buesch <mb@bu3sch.de>"
print "Licensed under the GNU/GPL version 3"
print ""
print "Usage: pctl-remote [OPTIONS] /dev/ttyS0"
@@ -184,10 +184,7 @@ class RemoteProtocol(QObject):
# Add the payload
msg += payload
# Pad the payload up to the constant size
- i = MSG_PAYLOAD_SIZE - len(payload)
- while i:
- msg += '\0'
- i -= 1
+ msg += '\0' * (MSG_PAYLOAD_SIZE - len(payload))
# Calculate the CRC
crc = self.__crc16_update_buffer(0xFFFF, msg)
crc ^= 0xFFFF
@@ -235,18 +232,20 @@ class RemoteProtocol(QObject):
if not reply:
return None
reply = remote.getPayload(reply)
- flags = ord(reply[0]) | (ord(reply[1]) << 8) | \
+ xy = ord(reply[0]) | (ord(reply[1]) << 8) | \
(ord(reply[2]) << 16) | (ord(reply[3]) << 24)
- return flags
+ z = ord(reply[4]) | (ord(reply[5]) << 8) | \
+ (ord(reply[6]) << 16) | (ord(reply[7]) << 24)
+ return (xy, z)
- def configFlagsSet(self, flags):
- data = "%c%c%c%c" % ((flags & 0xFF), ((flags >> 8) & 0xFF),
+ def configFlagsSet(self, island, flags):
+ data = "%c%c%c%c%c" % (island, (flags & 0xFF), ((flags >> 8) & 0xFF),
((flags >> 16) & 0xFF), ((flags >> 24) & 0xFF))
err = self.sendMessageSyncError(MSG_SET_CONFIG_FLAGS, 0, data)
return err
- def setValve(self, valveNr, state):
- data = "%c%c" % (valveNr, (state != 0))
+ def setValve(self, islandId, valveNr, state):
+ data = "%c%c%c" % (islandId, valveNr, (state != 0))
i = 5 # Retry a few times
while i != 0:
err = self.sendMessageSyncError(MSG_SET_VALVE, 0, data)
@@ -295,41 +294,65 @@ class LogBrowser(QTextEdit):
self.addText("Info: ")
self.addText(text)
-class MainWidget(QWidget):
- def __init__(self, parent=None):
+class PressureGauge(QWidget):
+ def __init__(self, name, min, max, units, parent):
QWidget.__init__(self, parent)
- self.initialized = False
-
- layout = QVBoxLayout()
+ self.min = min
+ self.max = max
+ self.units = units
+
+ self.setLayout(QVBoxLayout())
+
+ self.title = QLabel(name, self)
+ self.title.setAlignment(Qt.AlignHCenter)
+ self.layout().addWidget(self.title)
+
+ self.dial = QDial(self)
+ self.dial.setNotchesVisible(1)
+ self.dial.setEnabled(0)
+ self.dial.setSingleStep(100)
+ self.dial.setPageStep(1000)
+ self.dial.setNotchTarget(2)
+ self.dial.setMinimum(int(min * 1000))
+ self.dial.setMaximum(int(max * 1000))
+ self.dial.setFixedSize(100, 100)
+ self.layout().addWidget(self.dial)
+
+ self.num = QLabel(self)
+ self.num.setAlignment(Qt.AlignHCenter)
+ self.layout().addWidget(self.num)
+
+ self.layout().addStretch()
+ self.setValue(0)
+
+ def setValue(self, value):
+ if (value < self.min):
+ value = self.min
+ if (value > self.max):
+ value = self.max
+ self.num.setText("%.2f %s" % (float(value), self.units))
+ self.dial.setValue(int(value * 1000))
+
+class ValveIslandWidget(QGroupBox):
+ def __init__(self, name, islandId, parent):
+ QGroupBox.__init__(self, name, parent)
+ self.islandId = islandId
+
+ self.setLayout(QGridLayout())
+
+ self.gauge = PressureGauge("Current pressure", 0, 10, "Bar", self)
+ self.layout().addWidget(self.gauge, 0, 0, 3, 1)
h = QHBoxLayout()
- label = QLabel(self.tr("Current pressure:"), self)
- h.addWidget(label)
- self.curPressure = QLCDNumber(self)
- self.curPressure.setSegmentStyle(QLCDNumber.Flat)
- self.curPressure.setNumDigits(4)
- self.curPressure.display(QString("0.00"))
- h.addWidget(self.curPressure)
- label = QLabel(self.tr("Bar"), self)
- h.addWidget(label)
h.addStretch()
- layout.addLayout(h)
+ self.autoCheckbox = QCheckBox(self.tr("Automatically adjust pressure"), self)
+ self.connect(self.autoCheckbox, SIGNAL("stateChanged(int)"),
+ self.autoadjustChanged)
+ h.addWidget(self.autoCheckbox)
+ self.layout().addLayout(h, 0, 1)
h = QHBoxLayout()
- label = QLabel(self.tr("Hysteresis:"), self)
- h.addWidget(label)
- self.hystSpin = QDoubleSpinBox(self)
- self.hystSpin.setMinimum(0.1)
- self.hystSpin.setMaximum(8)
- self.hystSpin.setSingleStep(0.05)
- self.hystSpin.setSuffix(self.tr(" Bar"))
- self.connect(self.hystSpin, SIGNAL("valueChanged(double)"),
- self.desiredHysteresisChanged)
- h.addWidget(self.hystSpin)
h.addStretch()
- layout.addLayout(h)
-
- h = QHBoxLayout()
label = QLabel(self.tr("Desired pressure:"), self)
h.addWidget(label)
self.pressureSpin = QDoubleSpinBox(self)
@@ -340,12 +363,21 @@ class MainWidget(QWidget):
self.connect(self.pressureSpin, SIGNAL("valueChanged(double)"),
self.desiredPressureChanged)
h.addWidget(self.pressureSpin)
- self.autoCheckbox = QCheckBox(self.tr("Automatically adjust pressure"), self)
- self.connect(self.autoCheckbox, SIGNAL("stateChanged(int)"),
- self.autoadjustChanged)
- h.addWidget(self.autoCheckbox)
+ self.layout().addLayout(h, 1, 1)
+
+ h = QHBoxLayout()
h.addStretch()
- layout.addLayout(h)
+ label = QLabel(self.tr("Hysteresis:"), self)
+ h.addWidget(label)
+ self.hystSpin = QDoubleSpinBox(self)
+ self.hystSpin.setMinimum(0.1)
+ self.hystSpin.setMaximum(8)
+ self.hystSpin.setSingleStep(0.05)
+ self.hystSpin.setSuffix(self.tr(" Bar"))
+ self.connect(self.hystSpin, SIGNAL("valueChanged(double)"),
+ self.desiredHysteresisChanged)
+ h.addWidget(self.hystSpin)
+ self.layout().addLayout(h, 2, 1)
h = QHBoxLayout()
self.inButton = QPushButton(self.tr("IN-Valve"), self)
@@ -360,13 +392,80 @@ class MainWidget(QWidget):
self.outValvePressed)
self.connect(self.outButton, SIGNAL("released()"),
self.outValveReleased)
- layout.addLayout(h)
-
- self.log = LogBrowser(self)
- layout.addWidget(self.log)
+ self.layout().addLayout(h, 3, 0, 1, 2)
self.autoadjustChanged(Qt.Unchecked)
- self.setLayout(layout)
+
+ def desiredPressureChanged(self, value):
+ if not self.parent().initialized:
+ return
+ mbar = int(value * 1000)
+ data = "%c%c%c" % (self.islandId, (mbar & 0xFF), ((mbar >> 8) & 0xFF))
+ err = remote.sendMessageSyncError(MSG_SET_DESIRED_PRESSURE, 0, data)
+ if err != MSG_ERR_NONE:
+ self.parent().log.hostLog(self.tr("Failed to change pressure. Error=%u\n" % err))
+
+ def desiredHysteresisChanged(self, value):
+ if not self.parent().initialized:
+ return
+ mbar = int(value * 1000)
+ data = "%c%c%c" % (self.islandId, (mbar & 0xFF), ((mbar >> 8) & 0xFF))
+ err = remote.sendMessageSyncError(MSG_SET_HYSTERESIS, 0, data)
+ if err != MSG_ERR_NONE:
+ self.parent().log.hostLog(self.tr("Failed to change hysteresis. Error=%u\n" % err))
+
+ def autoadjustChanged(self, state):
+ self.inButton.setEnabled(state == Qt.Unchecked)
+ self.outButton.setEnabled(state == Qt.Unchecked)
+ if not self.parent().initialized:
+ return
+ flags = remote.configFlagsFetch()
+ if flags == None:
+ self.parent().log.hostLog(self.tr("Failed to fetch config flags\n"))
+ return
+ flags = flags[self.islandId]
+ if state == Qt.Checked:
+ flags |= (1 << CFG_FLAG_AUTOADJUST_ENABLE)
+ else:
+ flags &= ~(1 << CFG_FLAG_AUTOADJUST_ENABLE)
+ err = remote.configFlagsSet(self.islandId, flags)
+ if err != MSG_ERR_NONE:
+ self.parent().log.hostLog(self.tr("Failed to set config flags\n"))
+
+ def inValvePressed(self):
+ err = remote.setValve(self.islandId, 0, 1)
+ if err != MSG_ERR_NONE:
+ self.parent().log.hostLog(self.tr("Failed to switch valve 0 ON\n"))
+
+ def inValveReleased(self):
+ err = remote.setValve(self.islandId, 0, 0)
+ if err != MSG_ERR_NONE:
+ self.parent().log.hostLog(self.tr("Failed to switch valve 0 OFF\n"))
+
+ def outValvePressed(self):
+ err = remote.setValve(self.islandId, 1, 1)
+ if err != MSG_ERR_NONE:
+ self.parent().log.hostLog(self.tr("Failed to switch valve 1 ON\n"))
+
+ def outValveReleased(self):
+ err = remote.setValve(self.islandId, 1, 0)
+ if err != MSG_ERR_NONE:
+ self.parent().log.hostLog(self.tr("Failed to switch valve 1 OFF\n"))
+
+class MainWidget(QWidget):
+ def __init__(self, parent=None):
+ QWidget.__init__(self, parent)
+ self.initialized = False
+
+ self.setLayout(QVBoxLayout())
+
+ self.xy = ValveIslandWidget("X/Y joints", 0, self)
+ self.layout().addWidget(self.xy)
+ self.z = ValveIslandWidget("Z joint", 1, self)
+ self.layout().addWidget(self.z)
+
+ self.log = LogBrowser(self)
+ self.layout().addWidget(self.log)
def initializeState(self):
if not opt_nofetch:
@@ -408,8 +507,10 @@ class MainWidget(QWidget):
print "Failed to fetch desired pressure. No reply."
return False
reply = remote.getPayload(reply)
- mbar = ord(reply[0]) | (ord(reply[1]) << 8)
- self.pressureSpin.setValue(float(mbar) / 1000)
+ xy_mbar = ord(reply[0]) | (ord(reply[1]) << 8)
+ z_mbar = ord(reply[2]) | (ord(reply[3]) << 8)
+ self.xy.pressureSpin.setValue(float(xy_mbar) / 1000)
+ self.z.pressureSpin.setValue(float(z_mbar) / 1000)
# Get the hysteresis
reply = remote.sendMessageSyncReply(MSG_GET_HYSTERESIS, 0, "",
@@ -418,78 +519,29 @@ class MainWidget(QWidget):
print "Failed to fetch hysteresis. No reply."
return False
reply = remote.getPayload(reply)
- mbar = ord(reply[0]) | (ord(reply[1]) << 8)
- self.hystSpin.setValue(float(mbar) / 1000)
+ xy_mbar = ord(reply[0]) | (ord(reply[1]) << 8)
+ z_mbar = ord(reply[2]) | (ord(reply[3]) << 8)
+ self.xy.hystSpin.setValue(float(xy_mbar) / 1000)
+ self.z.hystSpin.setValue(float(z_mbar) / 1000)
# Get the config flags
flags = remote.configFlagsFetch()
if flags == None:
print "Failed to fetch config flags. No reply."
return False
- if flags & (1 << CFG_FLAG_AUTOADJUST_ENABLE):
- self.autoCheckbox.setCheckState(Qt.Checked)
+ if flags[0] & (1 << CFG_FLAG_AUTOADJUST_ENABLE):
+ self.xy.autoCheckbox.setCheckState(Qt.Checked)
+ if flags[1] & (1 << CFG_FLAG_AUTOADJUST_ENABLE):
+ self.z.autoCheckbox.setCheckState(Qt.Checked)
return True
def parseCurrentPressureMsg(self, msg):
msg = remote.getPayload(msg)
- mbar = ord(msg[0]) | (ord(msg[1]) << 8)
- self.curPressure.display(QString("%.2f" % (float(mbar) / 1000)))
-
- def desiredPressureChanged(self, value):
- if not self.initialized:
- return
- mbar = int(value * 1000)
- data = "%c%c" % ((mbar & 0xFF), ((mbar >> 8) & 0xFF))
- err = remote.sendMessageSyncError(MSG_SET_DESIRED_PRESSURE, 0, data)
- if err != MSG_ERR_NONE:
- self.log.hostLog(self.tr("Failed to change pressure. Error=%u\n" % err))
-
- def desiredHysteresisChanged(self, value):
- if not self.initialized:
- return
- mbar = int(value * 1000)
- data = "%c%c" % ((mbar & 0xFF), ((mbar >> 8) & 0xFF))
- err = remote.sendMessageSyncError(MSG_SET_HYSTERESIS, 0, data)
- if err != MSG_ERR_NONE:
- self.log.hostLog(self.tr("Failed to change hysteresis. Error=%u\n" % err))
-
- def autoadjustChanged(self, state):
- self.inButton.setEnabled(state == Qt.Unchecked)
- self.outButton.setEnabled(state == Qt.Unchecked)
- if not self.initialized:
- return
- flags = remote.configFlagsFetch()
- if flags == None:
- self.log.hostLog(self.tr("Failed to fetch config flags\n"))
- return
- if state == Qt.Checked:
- flags |= (1 << CFG_FLAG_AUTOADJUST_ENABLE)
- else:
- flags &= ~(1 << CFG_FLAG_AUTOADJUST_ENABLE)
- err = remote.configFlagsSet(flags)
- if err != MSG_ERR_NONE:
- self.log.hostLog(self.tr("Failed to set config flags\n"))
-
- def inValvePressed(self):
- err = remote.setValve(0, 1)
- if err != MSG_ERR_NONE:
- self.log.hostLog(self.tr("Failed to switch valve 0 ON\n"))
-
- def inValveReleased(self):
- err = remote.setValve(0, 0)
- if err != MSG_ERR_NONE:
- self.log.hostLog(self.tr("Failed to switch valve 0 OFF\n"))
-
- def outValvePressed(self):
- err = remote.setValve(1, 1)
- if err != MSG_ERR_NONE:
- self.log.hostLog(self.tr("Failed to switch valve 1 ON\n"))
-
- def outValveReleased(self):
- err = remote.setValve(1, 0)
- if err != MSG_ERR_NONE:
- self.log.hostLog(self.tr("Failed to switch valve 1 OFF\n"))
+ xy_mbar = ord(msg[0]) | (ord(msg[1]) << 8)
+ z_mbar = ord(msg[2]) | (ord(msg[3]) << 8)
+ self.xy.gauge.setValue(float(xy_mbar) / 1000)
+ self.z.gauge.setValue(float(z_mbar) / 1000)
class MainWindow(QMainWindow):
def __init__(self, parent=None):
@@ -519,7 +571,7 @@ class MainWindow(QMainWindow):
def about(self):
QMessageBox.information(self, self.tr("About"),
self.tr("Pneumatic pressure control\n"
- "Copyright (c) 2008 Michael Buesch"))
+ "Copyright (c) 2008-2009 Michael Buesch"))
def main():
global remote
bues.ch cgit interface