Verified button transitions and can sdo read
This commit is contained in:
parent
5a910e0705
commit
94cc1a5d1e
|
|
@ -20,7 +20,7 @@ class CANBackend:
|
|||
self.network = canopen.Network()
|
||||
self.network.connect(channel='can0', bustype='socketcan')
|
||||
|
||||
# PU mapping: PU1->0x02, PU2->0x03, PU3->0x04
|
||||
# PU mapping: PU1->0x02, PU2->0x04, PU3->0x127
|
||||
node_map = {
|
||||
1: 0x02,
|
||||
2: 0x04,
|
||||
|
|
@ -59,7 +59,7 @@ class CANBackend:
|
|||
with self.lock:
|
||||
try:
|
||||
# Poll only PU1 (node ID 0x02) for live monitor values
|
||||
node = self.nodes.get(1)
|
||||
node = self.nodes.get(2)
|
||||
if node:
|
||||
fm1 = node.sdo[0x2004][1].raw
|
||||
fm2 = node.sdo[0x2004][2].raw
|
||||
|
|
@ -147,7 +147,7 @@ class CANBackend:
|
|||
raise ValueError(f"PU{pu_number} not connected")
|
||||
|
||||
print(f"[DEBUG] Writing state {state_map[state]} to 0x2024:{pu_number}")
|
||||
node.sdo[0x2024][pu_number].raw = state_map[state]
|
||||
node.sdo[0x2024][0x01].raw = state_map[state]
|
||||
|
||||
print(f"[DEBUG] Writing ploop_setpoint {ploop_setpoint} to 0x2007")
|
||||
node.sdo[0x2007].raw = int(ploop_setpoint * 100)
|
||||
|
|
|
|||
50
main.py
50
main.py
|
|
@ -151,71 +151,95 @@ def get_monitor_data():
|
|||
print(f"[MONITOR] Latest SDO: {data}")
|
||||
return {
|
||||
"PU_1": {
|
||||
"Qperm": data.get("FM2", 0.0),
|
||||
"Qdilute": data.get("FM3", 0.0),
|
||||
"Qdrain": data.get("FM4", 0.0),
|
||||
"Qrecirc": data.get("FM5", 0.0),
|
||||
"Qperm": data.get("FM1", 0.0),
|
||||
"Qdilute": data.get("FM2", 0.0),
|
||||
"Qdrain": data.get("FM3", 0.0),
|
||||
"Qrecirc": data.get("FM4", 0.0),
|
||||
|
||||
"Pro": data.get("PS1", 0.0),
|
||||
"Pdilute": data.get("PS2", 0.0),
|
||||
"Prentate": data.get("PS3", 0.0),
|
||||
|
||||
"Conductivity": data.get("Cond", 0.0),
|
||||
|
||||
"MV02": data.get("MV02", 0.0),
|
||||
"MV02_sp": data.get("MV02_sp", 0.0),
|
||||
|
||||
"MV03": data.get("MV03", 0.0),
|
||||
"MV03_sp": data.get("MV03_sp", 0.0),
|
||||
|
||||
"MV05": data.get("MV05", 0.0),
|
||||
"MV05_sp": data.get("MV05_sp", 0.0),
|
||||
|
||||
"MV06": data.get("MV06", 0.0),
|
||||
"MV06_sp": data.get("MV06_sp", 0.0),
|
||||
|
||||
"MV07": data.get("MV07", 0.0),
|
||||
"MV07_sp": data.get("MV07_sp", 0.0),
|
||||
|
||||
"MV08": data.get("MV08", 0.0),
|
||||
"MV08_sp": data.get("MV08_sp", 0.0)
|
||||
},
|
||||
"PU_2": {
|
||||
"Qperm": data.get("FM2", 0.0),
|
||||
"Qdilute": data.get("FM3", 0.0),
|
||||
"Qdrain": data.get("FM4", 0.0),
|
||||
"Qrecirc": data.get("FM5", 0.0),
|
||||
"Qperm": data.get("FM1", 0.0),
|
||||
"Qdilute": data.get("FM2", 0.0),
|
||||
"Qdrain": data.get("FM3", 0.0),
|
||||
"Qrecirc": data.get("FM4", 0.0),
|
||||
|
||||
"Pro": data.get("PS1", 0.0),
|
||||
"Pdilute": data.get("PS2", 0.0),
|
||||
"Prentate": data.get("PS3", 0.0),
|
||||
|
||||
"Conductivity": data.get("Cond", 0.0),
|
||||
|
||||
"MV02": data.get("MV02", 0.0),
|
||||
"MV02_sp": data.get("MV02_sp", 0.0),
|
||||
|
||||
"MV03": data.get("MV03", 0.0),
|
||||
"MV03_sp": data.get("MV03_sp", 0.0),
|
||||
|
||||
"MV05": data.get("MV05", 0.0),
|
||||
"MV05_sp": data.get("MV05_sp", 0.0),
|
||||
|
||||
"MV06": data.get("MV06", 0.0),
|
||||
"MV06_sp": data.get("MV06_sp", 0.0),
|
||||
|
||||
"MV07": data.get("MV07", 0.0),
|
||||
"MV07_sp": data.get("MV07_sp", 0.0),
|
||||
|
||||
"MV08": data.get("MV08", 0.0),
|
||||
"MV08_sp": data.get("MV08_sp", 0.0)
|
||||
},
|
||||
"PU_3": {
|
||||
"Qperm": data.get("FM2", 0.0),
|
||||
"Qdilute": data.get("FM3", 0.0),
|
||||
"Qdrain": data.get("FM4", 0.0),
|
||||
"Qrecirc": data.get("FM5", 0.0),
|
||||
"Qperm": data.get("FM1", 0.0),
|
||||
"Qdilute": data.get("FM2", 0.0),
|
||||
"Qdrain": data.get("FM3", 0.0),
|
||||
"Qrecirc": data.get("FM4", 0.0),
|
||||
|
||||
"Pro": data.get("PS1", 0.0),
|
||||
"Pdilute": data.get("PS2", 0.0),
|
||||
"Prentate": data.get("PS3", 0.0),
|
||||
|
||||
"Conductivity": data.get("Cond", 0.0),
|
||||
|
||||
"MV02": data.get("MV02", 0.0),
|
||||
"MV02_sp": data.get("MV02_sp", 0.0),
|
||||
|
||||
"MV03": data.get("MV03", 0.0),
|
||||
"MV03_sp": data.get("MV03_sp", 0.0),
|
||||
|
||||
"MV05": data.get("MV05", 0.0),
|
||||
"MV05_sp": data.get("MV05_sp", 0.0),
|
||||
|
||||
"MV06": data.get("MV06", 0.0),
|
||||
"MV06_sp": data.get("MV06_sp", 0.0),
|
||||
|
||||
"MV07": data.get("MV07", 0.0),
|
||||
"MV07_sp": data.get("MV07_sp", 0.0),
|
||||
|
||||
"MV08": data.get("MV08", 0.0),
|
||||
"MV08_sp": data.get("MV08_sp", 0.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@app.get("/can_status")
|
||||
|
|
|
|||
|
|
@ -84,6 +84,21 @@
|
|||
.mode-block button.in-progress { background-color: #ffcc00; color: #000; }
|
||||
.mode-block button.ready { background-color: #00C851; color: #fff; }
|
||||
.mode-block button.disabled { background-color: #777; cursor: not-allowed; }
|
||||
.in-progress {
|
||||
background-color: yellow !important;
|
||||
color: black !important;
|
||||
}
|
||||
|
||||
.ready {
|
||||
background-color: orange !important;
|
||||
color: black !important;
|
||||
}
|
||||
|
||||
.production {
|
||||
background-color: green !important;
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.pu-status { margin-top: 20px; }
|
||||
.pu-item {
|
||||
background-color: #333;
|
||||
|
|
@ -179,23 +194,23 @@
|
|||
<div class="left-panel">
|
||||
<div class="mode-block">
|
||||
<div class="pu-buttons">
|
||||
<button onclick="sendCommand('IDLE', 1, this)"><i class="fas fa-power-off"></i> IDLE PU 1</button>
|
||||
<button onclick="sendCommand('IDLE', 2, this)"><i class="fas fa-power-off"></i> IDLE PU 2</button>
|
||||
<button onclick="sendCommand('IDLE', 3, this)"><i class="fas fa-power-off"></i> IDLE PU 3</button>
|
||||
<button onclick="sendCommand('IDLE', 1, this)" data-action="IDLE" data-pu="1"><i class="fas fa-power-off"></i> IDLE PU 1</button>
|
||||
<button onclick="sendCommand('IDLE', 2, this)" data-action="IDLE" data-pu="2"><i class="fas fa-power-off"></i> IDLE PU 2</button>
|
||||
<button onclick="sendCommand('IDLE', 3, this)" data-action="IDLE" data-pu="3"><i class="fas fa-power-off"></i> IDLE PU 3</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mode-block">
|
||||
<div class="pu-buttons">
|
||||
<button data-action="PRE-PRODUCTION" data-pu="1"><i class="fas fa-play"></i> PRE-PROD PU 1</button>
|
||||
<button data-action="PRE-PRODUCTION" data-pu="2"><i class="fas fa-play"></i> PRE-PROD PU 2</button>
|
||||
<button data-action="PRE-PRODUCTION" data-pu="3"><i class="fas fa-play"></i> PRE-PROD PU 3</button>
|
||||
<button onclick="sendCommand('PRE-PRODUCTION', 1, this)" data-action="PRE-PRODUCTION" data-pu="1"><i class="fas fa-play"></i> PRE-PROD PU 1</button>
|
||||
<button onclick="sendCommand('PRE-PRODUCTION', 2, this)" data-action="PRE-PRODUCTION" data-pu="2"><i class="fas fa-play"></i> PRE-PROD PU 2</button>
|
||||
<button onclick="sendCommand('PRE-PRODUCTION', 3, this)" data-action="PRE-PRODUCTION" data-pu="3"><i class="fas fa-play"></i> PRE-PROD PU 3</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mode-block">
|
||||
<div class="pu-buttons">
|
||||
<button onclick="sendCommand('FIRST_START', 1, this)"><i class="fas fa-power-off"></i> FIRST START PU 1</button>
|
||||
<button onclick="sendCommand('FIRST_START', 2, this)"><i class="fas fa-power-off"></i> FIRST START PU 2</button>
|
||||
<button onclick="sendCommand('FIRST_START', 3, this)"><i class="fas fa-power-off"></i> FIRST START PU 3</button>
|
||||
<button onclick="sendCommand('FIRST_START', 1, this)" data-action="FIRST_START" data-pu="1"><i class="fas fa-power-off"></i> FIRST START PU 1</button>
|
||||
<button onclick="sendCommand('FIRST_START', 2, this)" data-action="FIRST_START" data-pu="2"><i class="fas fa-power-off"></i> FIRST START PU 2</button>
|
||||
<button onclick="sendCommand('FIRST_START', 3, this)" data-action="FIRST_START" data-pu="3"><i class="fas fa-power-off"></i> FIRST START PU 3</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="slider-container">
|
||||
|
|
@ -266,27 +281,85 @@ function updatePloopSetpoint(value) {
|
|||
}
|
||||
|
||||
async function sendCommand(state, puNumber, buttonEl) {
|
||||
const ploopSetpoint = document.getElementById('ploopSetpoint').value;
|
||||
const response = await fetch(`/command/${state}/pu/${puNumber}?ploop_setpoint=${ploopSetpoint}`, { method: 'POST' });
|
||||
if (!response.ok) return;
|
||||
const ploopSetpoint = document.getElementById('ploopSetpoint').value;
|
||||
|
||||
// Send command to backend
|
||||
await fetch(`/command/${state}/pu/${puNumber}?ploop_setpoint=${ploopSetpoint}`, { method: 'POST' });
|
||||
|
||||
// Reset button styles
|
||||
document.querySelectorAll('button').forEach(btn => {
|
||||
btn.classList.remove('in-progress', 'ready', 'production');
|
||||
});
|
||||
|
||||
// Handle PRE-PRODUCTION sequence
|
||||
if (state === 'PRE-PRODUCTION') {
|
||||
buttonEl.classList.add('in-progress');
|
||||
buttonEl.textContent = `Waiting... PU ${puNumber}`;
|
||||
buttonEl.disabled = true;
|
||||
|
||||
async function checkReady() {
|
||||
const checkReady = async () => {
|
||||
const res = await fetch(`/api/pu_status`);
|
||||
const states = await res.json();
|
||||
const currentState = states[`PU${puNumber}`];
|
||||
|
||||
if (currentState === 'SYSTEM_MODE_READY') {
|
||||
buttonEl.classList.remove('in-progress');
|
||||
buttonEl.classList.add('ready');
|
||||
buttonEl.textContent = `START PRODUCTION PU ${puNumber}`;
|
||||
buttonEl.onclick = () => sendCommand("PRODUCTION", puNumber, buttonEl);
|
||||
buttonEl.disabled = false;
|
||||
|
||||
buttonEl.onclick = async () => {
|
||||
await sendCommand("PRODUCTION", puNumber, buttonEl);
|
||||
buttonEl.classList.remove('ready');
|
||||
buttonEl.classList.add('production');
|
||||
buttonEl.textContent = `PRODUCTION ON PU ${puNumber}`;
|
||||
buttonEl.disabled = true;
|
||||
};
|
||||
} else {
|
||||
setTimeout(checkReady, 1000);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
checkReady();
|
||||
|
||||
} else if (state === 'PRODUCTION') {
|
||||
buttonEl.classList.add('production');
|
||||
buttonEl.textContent = `PRODUCTION ON PU ${puNumber}`;
|
||||
|
||||
} else if (state === 'IDLE' || state === 'FIRST_START') {
|
||||
buttonEl.classList.remove('in-progress', 'ready', 'production');
|
||||
buttonEl.classList.add('production');
|
||||
buttonEl.textContent = `${state.replace('_', ' ')} PU ${puNumber}`;
|
||||
|
||||
// === Reset PRE-PROD button ===
|
||||
const preProdBtn = document.querySelector(`button[data-action="PRE-PRODUCTION"][data-pu="${puNumber}"]`);
|
||||
if (preProdBtn) {
|
||||
preProdBtn.classList.remove('in-progress', 'ready', 'production');
|
||||
preProdBtn.innerHTML = `<i class="fas fa-play"></i> PRE-PROD PU ${puNumber}`;
|
||||
preProdBtn.disabled = false;
|
||||
preProdBtn.onclick = () => sendCommand("PRE-PRODUCTION", puNumber, preProdBtn);
|
||||
}
|
||||
|
||||
// === Reset IDLE button ===
|
||||
const idleBtn = document.querySelector(`button[data-action="IDLE"][data-pu="${puNumber}"]`);
|
||||
if (idleBtn && idleBtn !== buttonEl) {
|
||||
idleBtn.classList.remove('in-progress', 'ready', 'production');
|
||||
idleBtn.innerHTML = `<i class="fas fa-power-off"></i> IDLE PU ${puNumber}`;
|
||||
idleBtn.disabled = false;
|
||||
idleBtn.onclick = () => sendCommand("IDLE", puNumber, idleBtn);
|
||||
}
|
||||
|
||||
// === Reset FIRST START button ===
|
||||
const firstStartBtn = document.querySelector(`button[data-action="FIRST_START"][data-pu="${puNumber}"]`);
|
||||
if (firstStartBtn && firstStartBtn !== buttonEl) {
|
||||
firstStartBtn.classList.remove('in-progress', 'ready', 'production');
|
||||
firstStartBtn.innerHTML = `<i class="fas fa-power-off"></i> FIRST START PU ${puNumber}`;
|
||||
firstStartBtn.disabled = false;
|
||||
firstStartBtn.onclick = () => sendCommand("FIRST_START", puNumber, firstStartBtn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function fetchPUStatus() {
|
||||
const response = await fetch("/api/pu_status");
|
||||
|
|
@ -362,7 +435,7 @@ function updatePloopSetpoint(value) {
|
|||
if (!container) continue;
|
||||
|
||||
container.innerHTML = keys.map((pu, i) => {
|
||||
const value = data[pu][field] ?? 0.0;
|
||||
const value = data[pu]?.[field] ?? 0.0;
|
||||
return `<div class="monitor-value">#${i + 1}<br>${value.toFixed(1)} ${fields[field]}</div>`;
|
||||
}).join('');
|
||||
}
|
||||
|
|
@ -373,8 +446,7 @@ function updatePloopSetpoint(value) {
|
|||
}
|
||||
|
||||
setInterval(fetchMonitorData, 1000);
|
||||
fetchMonitorData(); // Premier appel immédiat
|
||||
fetchMonitorData(); // First call
|
||||
</script>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user