Skip to content

Commit 7474e77

Browse files
authored
Merge pull request #53 from Fortiphyd/feature/plc-manual-mode
Feature/plc manual mode
2 parents 5eb8643 + 70ad08f commit 7474e77

39 files changed

Lines changed: 435 additions & 4318 deletions

plc/st_files/326339.st

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -155,47 +155,59 @@ PROGRAM main1
155155
VAR
156156
test_int AT %MW30 : UINT;
157157
run_bit AT %QX5.0 : BOOL := TRUE;
158+
manual_mode AT %QX0.0 : BOOL := FALSE;
159+
f1_manual_sp AT %QW10 : UINT := 0;
160+
f2_manual_sp AT %QW11 : UINT := 0;
161+
purge_manual_sp AT %QW12 : UINT := 65535;
162+
product_manual_sp AT %QW13 : UINT := 65535;
158163
END_VAR
159164

160165

161166

162-
f1_valve_sp := control(
163-
current_value := product_flow,
164-
setpoint := product_flow_setpoint,
165-
current_pos := f1_valve_pos,
166-
k := 20.0,
167-
rmax := 500.0,
168-
rmin := 0.0);
169-
170-
purge_valve_sp := control(
171-
current_value := pressure,
172-
setpoint := pressure_sp,
173-
current_pos := purge_valve_pos,
174-
k := -20.0,
175-
rmax := 3200.0,
176-
rmin := 0.0);
177-
178-
f2_valve_sp := control(
179-
current_value := a_in_purge,
180-
setpoint := a_setpoint,
181-
current_pos := f2_valve_pos,
182-
k := 1.0,
183-
rmax := 100.0,
184-
rmin := 0.0);
185-
186-
product_flow_setpoint := pressure_override(
187-
pressure_in := pressure,
188-
current_sp := product_flow_setpoint,
189-
override_sp := override_sp);
190-
191-
product_valve_sp := control(
192-
current_value := level,
193-
setpoint := level_sp,
194-
current_pos := product_valve_pos,
195-
k := -10.0,
196-
rmax := 100.0,
197-
rmin := 0.0);
198-
167+
IF manual_mode THEN
168+
f1_valve_sp := f1_manual_sp;
169+
f2_valve_sp := f2_manual_sp;
170+
purge_valve_sp := purge_manual_sp;
171+
product_valve_sp := product_manual_sp;
172+
ELSE
173+
f1_valve_sp := control(
174+
current_value := product_flow,
175+
setpoint := product_flow_setpoint,
176+
current_pos := f1_valve_pos,
177+
k := 20.0,
178+
rmax := 500.0,
179+
rmin := 0.0);
180+
181+
purge_valve_sp := control(
182+
current_value := pressure,
183+
setpoint := pressure_sp,
184+
current_pos := purge_valve_pos,
185+
k := -20.0,
186+
rmax := 3200.0,
187+
rmin := 0.0);
188+
189+
f2_valve_sp := control(
190+
current_value := a_in_purge,
191+
setpoint := a_setpoint,
192+
current_pos := f2_valve_pos,
193+
k := 1.0,
194+
rmax := 100.0,
195+
rmin := 0.0);
196+
197+
product_flow_setpoint := pressure_override(
198+
pressure_in := pressure,
199+
current_sp := product_flow_setpoint,
200+
override_sp := override_sp);
201+
202+
product_valve_sp := control(
203+
current_value := level,
204+
setpoint := level_sp,
205+
current_pos := product_valve_pos,
206+
k := -10.0,
207+
rmax := 100.0,
208+
rmin := 0.0);
209+
END_IF;
210+
199211
f1_valve_pos := LIMIT(0, f1_valve_pos, 65535);
200212
f1_flow := LIMIT(0, f1_flow, 65535);
201213
f2_valve_pos := LIMIT(0, f2_valve_pos, 65535);
@@ -215,10 +227,10 @@ PROGRAM main1
215227
product_flow_setpoint := 30000;
216228

217229
IF NOT run_bit THEN
218-
f1_valve_sp := 0;
219-
f2_valve_sp := 0;
220-
purge_valve_sp := 65535;
221-
product_valve_sp := 65535;
230+
f1_valve_sp := 0;
231+
f2_valve_sp := 0;
232+
purge_valve_sp := 65535;
233+
product_valve_sp := 65535;
222234
END_IF;
223235
END_PROGRAM
224236

scadalts/init.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,26 @@ mariadb -uscada -pscada scadalts <<-EOSQL
3939
4, 'admin', '0DPiKuNIrrVmD8IUCuw1hQxNqZc=', 'admin@example.com', '', 'N', 'Y', 0, 0, '/views.shtm#'
4040
WHERE NOT EXISTS (SELECT 1 FROM users WHERE username='admin');
4141
EOSQL
42+
43+
ip route add 192.168.95.0/24 via 192.168.90.200 || true
44+
45+
# Wait for ScadaLTS/Tomcat to finish starting so Flyway migrations have run
46+
# before we import seed data (migrations add columns the seed depends on).
47+
echo "[*] Waiting for ScadaLTS to be ready..."
48+
until curl -sf http://localhost:8080/ &>/dev/null; do
49+
sleep 5
50+
done
51+
4252
# Seed project
4353
VIEW_COUNT=$(mariadb -uscada -pscada scadalts -N -B -e "SELECT COUNT(*) FROM mangoViews;" 2>/dev/null || echo 0)
4454
if [ "$VIEW_COUNT" -eq 0 ] && [ -f /seed_project_data.sql ]; then
4555
echo "[*] Seeding project data..."
4656
mariadb -uscada -pscada scadalts < /seed_project_data.sql
4757
echo "[*] Project import complete."
58+
echo "[*] Restarting Tomcat to load seeded data..."
59+
supervisorctl restart tomcat
4860
else
4961
echo "[*] Skipping project seed (views table already has entries)."
5062
fi
5163

52-
ip route add 192.168.95.0/24 via 192.168.90.200 || true
53-
5464
exit 0

scadalts/seed_project_data.sql

Lines changed: 3 additions & 62 deletions
Large diffs are not rendered by default.

workstation/chemical.st

Lines changed: 88 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -155,47 +155,59 @@ PROGRAM main1
155155
VAR
156156
test_int AT %MW30 : UINT;
157157
run_bit AT %QX5.0 : BOOL := TRUE;
158+
manual_mode AT %QX0.0 : BOOL := FALSE;
159+
f1_manual_sp AT %QW10 : UINT := 0;
160+
f2_manual_sp AT %QW11 : UINT := 0;
161+
purge_manual_sp AT %QW12 : UINT := 65535;
162+
product_manual_sp AT %QW13 : UINT := 65535;
158163
END_VAR
159164

160165

161166

162-
f1_valve_sp := control(
163-
current_value := product_flow,
164-
setpoint := product_flow_setpoint,
165-
current_pos := f1_valve_pos,
166-
k := 20.0,
167-
rmax := 500.0,
168-
rmin := 0.0);
169-
170-
purge_valve_sp := control(
171-
current_value := pressure,
172-
setpoint := pressure_sp,
173-
current_pos := purge_valve_pos,
174-
k := -20.0,
175-
rmax := 3200.0,
176-
rmin := 0.0);
177-
178-
f2_valve_sp := control(
179-
current_value := a_in_purge,
180-
setpoint := a_setpoint,
181-
current_pos := f2_valve_pos,
182-
k := 1.0,
183-
rmax := 100.0,
184-
rmin := 0.0);
185-
186-
product_flow_setpoint := pressure_override(
187-
pressure_in := pressure,
188-
current_sp := product_flow_setpoint,
189-
override_sp := override_sp);
190-
191-
product_valve_sp := control(
192-
current_value := level,
193-
setpoint := level_sp,
194-
current_pos := product_valve_pos,
195-
k := -10.0,
196-
rmax := 100.0,
197-
rmin := 0.0);
198-
167+
IF manual_mode THEN
168+
f1_valve_sp := f1_manual_sp;
169+
f2_valve_sp := f2_manual_sp;
170+
purge_valve_sp := purge_manual_sp;
171+
product_valve_sp := product_manual_sp;
172+
ELSE
173+
f1_valve_sp := control(
174+
current_value := product_flow,
175+
setpoint := product_flow_setpoint,
176+
current_pos := f1_valve_pos,
177+
k := 20.0,
178+
rmax := 500.0,
179+
rmin := 0.0);
180+
181+
purge_valve_sp := control(
182+
current_value := pressure,
183+
setpoint := pressure_sp,
184+
current_pos := purge_valve_pos,
185+
k := -20.0,
186+
rmax := 3200.0,
187+
rmin := 0.0);
188+
189+
f2_valve_sp := control(
190+
current_value := a_in_purge,
191+
setpoint := a_setpoint,
192+
current_pos := f2_valve_pos,
193+
k := 1.0,
194+
rmax := 100.0,
195+
rmin := 0.0);
196+
197+
product_flow_setpoint := pressure_override(
198+
pressure_in := pressure,
199+
current_sp := product_flow_setpoint,
200+
override_sp := override_sp);
201+
202+
product_valve_sp := control(
203+
current_value := level,
204+
setpoint := level_sp,
205+
current_pos := product_valve_pos,
206+
k := -10.0,
207+
rmax := 100.0,
208+
rmin := 0.0);
209+
END_IF;
210+
199211
f1_valve_pos := LIMIT(0, f1_valve_pos, 65535);
200212
f1_flow := LIMIT(0, f1_flow, 65535);
201213
f2_valve_pos := LIMIT(0, f2_valve_pos, 65535);
@@ -215,10 +227,10 @@ PROGRAM main1
215227
product_flow_setpoint := 30000;
216228

217229
IF NOT run_bit THEN
218-
f1_valve_sp := 0;
219-
f2_valve_sp := 0;
220-
purge_valve_sp := 65535;
221-
product_valve_sp := 65535;
230+
f1_valve_sp := 0;
231+
f2_valve_sp := 0;
232+
purge_valve_sp := 65535;
233+
product_valve_sp := 65535;
222234
END_IF;
223235
END_PROGRAM
224236

@@ -275,7 +287,7 @@ CONFIGURATION Config0
275287
END_RESOURCE
276288
END_CONFIGURATION
277289

278-
(*DBG:char md5[] = "f0cccecd508a69d2b1e2a1d22a4054a7";*)
290+
(*DBG:char md5[] = "64ab1b4f1044a1e90e17da24eec6da5f";*)
279291
(*DBG:/**)
280292
(*DBG: * This file is part of OpenPLC Runtime*)
281293
(*DBG: **)
@@ -353,9 +365,14 @@ END_CONFIGURATION
353365
(*DBG: {&(RES0__INSTANCE0.TEST_REAL), REAL_ENUM},*)
354366
(*DBG: {&(RES0__INSTANCE0.TEST_INT), UINT_O_ENUM},*)
355367
(*DBG: {&(RES0__INSTANCE0.RUN_BIT), BOOL_O_ENUM},*)
368+
(*DBG: {&(RES0__INSTANCE0.MANUAL_MODE), BOOL_O_ENUM},*)
369+
(*DBG: {&(RES0__INSTANCE0.F1_MANUAL_SP), UINT_O_ENUM},*)
370+
(*DBG: {&(RES0__INSTANCE0.F2_MANUAL_SP), UINT_O_ENUM},*)
371+
(*DBG: {&(RES0__INSTANCE0.PURGE_MANUAL_SP), UINT_O_ENUM},*)
372+
(*DBG: {&(RES0__INSTANCE0.PRODUCT_MANUAL_SP), UINT_O_ENUM},*)
356373
(*DBG:};*)
357374
(*DBG:*)
358-
(*DBG:#define VAR_COUNT 39*)
375+
(*DBG:#define VAR_COUNT 44*)
359376
(*DBG:*)
360377
(*DBG:uint16_t get_var_count(void)*)
361378
(*DBG:{*)
@@ -369,16 +386,16 @@ END_CONFIGURATION
369386
(*DBG: return 0;*)
370387
(*DBG: }*)
371388
(*DBG: switch (debug_vars[idx].type) {*)
372-
(*DBG: case REAL_ENUM:*)
373-
(*DBG: return sizeof(REAL);*)
374-
(*DBG: case INT_O_ENUM:*)
375-
(*DBG: return sizeof(INT);*)
376389
(*DBG: case UINT_ENUM:*)
377390
(*DBG: case UINT_O_ENUM:*)
378391
(*DBG: case UINT_P_ENUM:*)
379392
(*DBG: return sizeof(UINT);*)
380393
(*DBG: case BOOL_O_ENUM:*)
381394
(*DBG: return sizeof(BOOL);*)
395+
(*DBG: case REAL_ENUM:*)
396+
(*DBG: return sizeof(REAL);*)
397+
(*DBG: case INT_O_ENUM:*)
398+
(*DBG: return sizeof(INT);*)
382399
(*DBG: default:*)
383400
(*DBG: return 0;*)
384401
(*DBG: }*)
@@ -389,12 +406,6 @@ END_CONFIGURATION
389406
(*DBG: void *ptr = debug_vars[idx].ptr;*)
390407
(*DBG:*)
391408
(*DBG: switch (debug_vars[idx].type) {*)
392-
(*DBG: case REAL_ENUM:*)
393-
(*DBG: return (void *)&((__IEC_REAL_t *) ptr)->value;*)
394-
(*DBG: case INT_O_ENUM:*)
395-
(*DBG: return (void *)((((__IEC_INT_p *) ptr)->flags & __IEC_FORCE_FLAG) *)
396-
(*DBG: ? &(((__IEC_INT_p *) ptr)->fvalue) *)
397-
(*DBG: : ((__IEC_INT_p *) ptr)->value);*)
398409
(*DBG: case UINT_ENUM:*)
399410
(*DBG: return (void *)&((__IEC_UINT_t *) ptr)->value;*)
400411
(*DBG: case UINT_O_ENUM:*)
@@ -406,6 +417,12 @@ END_CONFIGURATION
406417
(*DBG: return (void *)((((__IEC_BOOL_p *) ptr)->flags & __IEC_FORCE_FLAG) *)
407418
(*DBG: ? &(((__IEC_BOOL_p *) ptr)->fvalue) *)
408419
(*DBG: : ((__IEC_BOOL_p *) ptr)->value);*)
420+
(*DBG: case REAL_ENUM:*)
421+
(*DBG: return (void *)&((__IEC_REAL_t *) ptr)->value;*)
422+
(*DBG: case INT_O_ENUM:*)
423+
(*DBG: return (void *)((((__IEC_INT_p *) ptr)->flags & __IEC_FORCE_FLAG) *)
424+
(*DBG: ? &(((__IEC_INT_p *) ptr)->fvalue) *)
425+
(*DBG: : ((__IEC_INT_p *) ptr)->value);*)
409426
(*DBG: default:*)
410427
(*DBG: return 0;*)
411428
(*DBG: }*)
@@ -418,18 +435,6 @@ END_CONFIGURATION
418435
(*DBG: if (forced) {*)
419436
(*DBG: size_t var_size = get_var_size(idx);*)
420437
(*DBG: switch (debug_vars[idx].type) {*)
421-
(*DBG: case REAL_ENUM: {*)
422-
(*DBG: memcpy(&((__IEC_REAL_t *) ptr)->value, val, var_size);*)
423-
(*DBG: //((__IEC_REAL_t *) ptr)->value = *((REAL *) val);*)
424-
(*DBG: ((__IEC_REAL_t *) ptr)->flags |= __IEC_FORCE_FLAG;*)
425-
(*DBG: break;*)
426-
(*DBG: }*)
427-
(*DBG: case INT_O_ENUM: {*)
428-
(*DBG: memcpy((((__IEC_INT_p *) ptr)->value), val, var_size);*)
429-
(*DBG: //*(((__IEC_INT_p *) ptr)->value) = *((INT *) val);*)
430-
(*DBG: ((__IEC_INT_p *) ptr)->flags |= __IEC_FORCE_FLAG;*)
431-
(*DBG: break;*)
432-
(*DBG: }*)
433438
(*DBG: case UINT_ENUM: {*)
434439
(*DBG: memcpy(&((__IEC_UINT_t *) ptr)->value, val, var_size);*)
435440
(*DBG: //((__IEC_UINT_t *) ptr)->value = *((UINT *) val);*)
@@ -454,17 +459,23 @@ END_CONFIGURATION
454459
(*DBG: ((__IEC_BOOL_p *) ptr)->flags |= __IEC_FORCE_FLAG;*)
455460
(*DBG: break;*)
456461
(*DBG: }*)
462+
(*DBG: case REAL_ENUM: {*)
463+
(*DBG: memcpy(&((__IEC_REAL_t *) ptr)->value, val, var_size);*)
464+
(*DBG: //((__IEC_REAL_t *) ptr)->value = *((REAL *) val);*)
465+
(*DBG: ((__IEC_REAL_t *) ptr)->flags |= __IEC_FORCE_FLAG;*)
466+
(*DBG: break;*)
467+
(*DBG: }*)
468+
(*DBG: case INT_O_ENUM: {*)
469+
(*DBG: memcpy((((__IEC_INT_p *) ptr)->value), val, var_size);*)
470+
(*DBG: //*(((__IEC_INT_p *) ptr)->value) = *((INT *) val);*)
471+
(*DBG: ((__IEC_INT_p *) ptr)->flags |= __IEC_FORCE_FLAG;*)
472+
(*DBG: break;*)
473+
(*DBG: }*)
457474
(*DBG: default:*)
458475
(*DBG: break;*)
459476
(*DBG: }*)
460477
(*DBG: } else {*)
461478
(*DBG: switch (debug_vars[idx].type) {*)
462-
(*DBG: case REAL_ENUM:*)
463-
(*DBG: ((__IEC_REAL_t *) ptr)->flags &= ~__IEC_FORCE_FLAG;*)
464-
(*DBG: break;*)
465-
(*DBG: case INT_O_ENUM:*)
466-
(*DBG: ((__IEC_INT_p *) ptr)->flags &= ~__IEC_FORCE_FLAG;*)
467-
(*DBG: break;*)
468479
(*DBG: case UINT_ENUM:*)
469480
(*DBG: ((__IEC_UINT_t *) ptr)->flags &= ~__IEC_FORCE_FLAG;*)
470481
(*DBG: break;*)
@@ -475,6 +486,12 @@ END_CONFIGURATION
475486
(*DBG: case BOOL_O_ENUM:*)
476487
(*DBG: ((__IEC_BOOL_p *) ptr)->flags &= ~__IEC_FORCE_FLAG;*)
477488
(*DBG: break;*)
489+
(*DBG: case REAL_ENUM:*)
490+
(*DBG: ((__IEC_REAL_t *) ptr)->flags &= ~__IEC_FORCE_FLAG;*)
491+
(*DBG: break;*)
492+
(*DBG: case INT_O_ENUM:*)
493+
(*DBG: ((__IEC_INT_p *) ptr)->flags &= ~__IEC_FORCE_FLAG;*)
494+
(*DBG: break;*)
478495
(*DBG: default:*)
479496
(*DBG: break;*)
480497
(*DBG: }*)
0 Bytes
Binary file not shown.

workstation/chemical/build/LOCATED_VARIABLES.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ __LOCATED_VAR(INT,__MW28,M,W,28)
3232
__LOCATED_VAR(INT,__MW29,M,W,29)
3333
__LOCATED_VAR(UINT,__MW30,M,W,30)
3434
__LOCATED_VAR(BOOL,__QX5_0,Q,X,5,0)
35+
__LOCATED_VAR(BOOL,__QX0_0,Q,X,0,0)
36+
__LOCATED_VAR(UINT,__QW10,Q,W,10)
37+
__LOCATED_VAR(UINT,__QW11,Q,W,11)
38+
__LOCATED_VAR(UINT,__QW12,Q,W,12)
39+
__LOCATED_VAR(UINT,__QW13,Q,W,13)

0 commit comments

Comments
 (0)