~ diagram update

~ Vereinfachungen
This commit is contained in:
Johannes Theiner 2020-10-28 14:30:09 +01:00
parent 05ce7df364
commit 810311fabb
Signed by: joethei
GPG Key ID: 9D2B9A00FDA85BCD
2 changed files with 29 additions and 34 deletions

View File

@ -3,6 +3,7 @@
#include <uint128.h> #include <uint128.h>
#include <sys/rtai_modbus.h> #include <sys/rtai_modbus.h>
#include <stdbool.h>
#include "include/rtai_lxrt.h" #include "include/rtai_lxrt.h"
#include "include/rtai_modbus.h" #include "include/rtai_modbus.h"
#include "include/rtai_sem.h" #include "include/rtai_sem.h"
@ -35,7 +36,7 @@ int connection;
char node[] = "modbus-node"; char node[] = "modbus-node";
void fail() { void end(bool fail) {
rt_modbus_disconnect(connection); rt_modbus_disconnect(connection);
rt_task_delete(&turntable_task); rt_task_delete(&turntable_task);
rt_task_delete(&tester_task); rt_task_delete(&tester_task);
@ -48,8 +49,10 @@ void fail() {
stop_rt_timer(); stop_rt_timer();
if(fail) {
rt_printk("failed to read/send Modbus message.\n"); rt_printk("failed to read/send Modbus message.\n");
rt_printk("module needs to be restarted.\n"); rt_printk("module needs to be restarted.\n");
}
} }
/** /**
@ -72,13 +75,15 @@ int readAll(int type, int *result) {
* @param result value to write the result to * @param result value to write the result to
* @return status code(0: success, 1: failure) * @return status code(0: success, 1: failure)
*/ */
int readData(int part, int *result) { int readData(int part) {
rt_sem_wait(&semaphore); rt_sem_wait(&semaphore);
int value; int value;
int * result;
int code = readAll(DIGITAL_IN, &value); int code = readAll(DIGITAL_IN, &value);
*result = (value & part) != 0; *result = (value & part) != 0;
rt_sem_signal(&semaphore); rt_sem_signal(&semaphore);
return code; if(code) end(true);
return *result;
} }
/** /**
@ -91,10 +96,10 @@ void disable(int actor) {
rt_sem_wait(&semaphore); rt_sem_wait(&semaphore);
int value; int value;
int code = readAll(DIGITAL_OUT, &value); int code = readAll(DIGITAL_OUT, &value);
if(code) fail(); if(code) end(true);
int result = rt_modbus_set(connection, DIGITAL_OUT, value &= ~actor) int result = rt_modbus_set(connection, DIGITAL_OUT, value &= ~actor)
rt_sem_signal(&semaphore); rt_sem_signal(&semaphore);
if (result) fail(); if (result) end(true);
} }
/** /**
@ -107,10 +112,10 @@ void enable(int actor) {
rt_sem_wait(&semaphore); rt_sem_wait(&semaphore);
int output; int output;
int code = readAll(DIGITAL_OUT, &output); int code = readAll(DIGITAL_OUT, &output);
if (code) fail(); if (code) end(true);
int result = rt_modbus_set(connection, DIGITAL_OUT, output |= actor) int result = rt_modbus_set(connection, DIGITAL_OUT, output |= actor)
rt_sem_signal(&semaphore); rt_sem_signal(&semaphore);
if(result) fail(); if(result) end(true);
} }
void sleepStuff() { void sleepStuff() {
@ -123,8 +128,7 @@ static void turntable(long x) {
disable(ACTOR_TURNTABLE); disable(ACTOR_TURNTABLE);
while (1) { while (1) {
int partOnTable; int partOnTable = readData(SENSOR_PART_TURNTABLE);
readData(SENSOR_PART_TURNTABLE, &partOnTable);
if (partOnTable) { if (partOnTable) {
enable(ACTOR_TURNTABLE); enable(ACTOR_TURNTABLE);
@ -148,12 +152,10 @@ static void drill(long x) {
enable(ACTOR_DRILL_UP); enable(ACTOR_DRILL_UP);
rt_sem_wait(&semaphore); rt_sem_wait(&semaphore);
int drill_up = 0;
readData(SENSOR_DRILL_UP, drill_up); if (!readData(SENSOR_DRILL_UP)) {
if (!drill_up) {
do { do {
readData(SENSOR_DRILL_UP, drill_up); } while (readData(SENSOR_DRILL_UP) == 0);
} while (drill_up == 0);
} }
rt_sem_signal(&semaphore); rt_sem_signal(&semaphore);
disable(ACTOR_DRILL_UP); disable(ACTOR_DRILL_UP);
@ -185,7 +187,6 @@ example_init(void) {
start_rt_timer(0); start_rt_timer(0);
modbus_init(); modbus_init();
rt_printk("init: task started\n"); rt_printk("init: task started\n");
if ((connection = rt_modbus_connect(node)) == -1) { if ((connection = rt_modbus_connect(node)) == -1) {
rt_printk("init: could not connect to %s\n", node); rt_printk("init: could not connect to %s\n", node);
@ -216,18 +217,13 @@ example_init(void) {
return (0); return (0);
fail: fail:
stop_rt_timer(); end(true);
return (1); return (1);
} }
static void __exit static void __exit
example_exit(void) { example_exit(void) {
rt_task_delete(&turntable_task); end(false);
rt_task_delete(&drill_task);
rt_task_delete(&tester_task);
rt_task_delete(&output_task);
stop_rt_timer();
rt_sem_delete(&semaphore);
printk("module Bearbeiten2 unloaded\n"); printk("module Bearbeiten2 unloaded\n");
} }

View File

@ -25,9 +25,9 @@ while(Dauerschleife) is (true)
if(Werkstück vorhanden ?) then (true) if(Werkstück vorhanden ?) then (true)
:Prüfer ausfahren; :Prüfer ausfahren;
if(Werkstück Normallage ?) then (true) if(Werkstück Normallage ?) then (true)
:Bohrer(on)> :Sende Bohrer(on)>
else (false) else (false)
:Bohrer(off)> :Sende Bohrer(off)>
endif endif
:Prüfer einfahren; :Prüfer einfahren;
else (false) else (false)
@ -46,16 +46,15 @@ start
while(Dauerschleife) is (true) while(Dauerschleife) is (true)
if(Werkstück vorhanden?) then(true) if(Werkstück vorhanden?) then(true)
:Bohrer< :Empfange Lage des Werkstücks<
:Auswerfer> :Sende Auswerfer>
if(Teil in Normallage) then(true) if(Teil in Normallage?) then(true)
:Werkstück festhalten; :Werkstück festhalten;
:Bohrer anschalten; :Bohrer anschalten;
:Bohrer herunterfahren; :Bohrer herunterfahren;
:sleep 500ms; :Warte bis Bohrer unten;
:Bohrer hochfahren; :Bohrer hochfahren;
:Warte bis Bohrer oben;
:Bohrer ausschalten; :Bohrer ausschalten;
:Werkstück loslassen; :Werkstück loslassen;
else(false) else(false)