From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- Master/Real-Time Systems/RTS_A8/.cproject | 986 +++++++++++++++++++++ Master/Real-Time Systems/RTS_A8/.project | 82 ++ .../RTS_A8/src/ApplicationWindow.cpp | 84 ++ .../RTS_A8/src/ApplicationWindow.h | 45 + Master/Real-Time Systems/RTS_A8/src/Display.cpp | 111 +++ Master/Real-Time Systems/RTS_A8/src/Display.h | 37 + Master/Real-Time Systems/RTS_A8/src/Fahren.cpp | 44 + Master/Real-Time Systems/RTS_A8/src/Fahren.h | 25 + Master/Real-Time Systems/RTS_A8/src/Notbremse.cpp | 34 + Master/Real-Time Systems/RTS_A8/src/Notbremse.h | 30 + Master/Real-Time Systems/RTS_A8/src/POS.h | 69 ++ Master/Real-Time Systems/RTS_A8/src/Task.cpp | 51 ++ Master/Real-Time Systems/RTS_A8/src/Task.h | 28 + Master/Real-Time Systems/RTS_A8/src/main.cpp | 78 ++ 14 files changed, 1704 insertions(+) create mode 100644 Master/Real-Time Systems/RTS_A8/.cproject create mode 100644 Master/Real-Time Systems/RTS_A8/.project create mode 100644 Master/Real-Time Systems/RTS_A8/src/ApplicationWindow.cpp create mode 100644 Master/Real-Time Systems/RTS_A8/src/ApplicationWindow.h create mode 100644 Master/Real-Time Systems/RTS_A8/src/Display.cpp create mode 100644 Master/Real-Time Systems/RTS_A8/src/Display.h create mode 100644 Master/Real-Time Systems/RTS_A8/src/Fahren.cpp create mode 100644 Master/Real-Time Systems/RTS_A8/src/Fahren.h create mode 100644 Master/Real-Time Systems/RTS_A8/src/Notbremse.cpp create mode 100644 Master/Real-Time Systems/RTS_A8/src/Notbremse.h create mode 100644 Master/Real-Time Systems/RTS_A8/src/POS.h create mode 100644 Master/Real-Time Systems/RTS_A8/src/Task.cpp create mode 100644 Master/Real-Time Systems/RTS_A8/src/Task.h create mode 100644 Master/Real-Time Systems/RTS_A8/src/main.cpp (limited to 'Master/Real-Time Systems/RTS_A8') diff --git a/Master/Real-Time Systems/RTS_A8/.cproject b/Master/Real-Time Systems/RTS_A8/.cproject new file mode 100644 index 0000000..37d01bd --- /dev/null +++ b/Master/Real-Time Systems/RTS_A8/.cproject @@ -0,0 +1,986 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +make + +all +true +true +true + + +make + +clean +true +true +true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +make + +all +true +true +true + + +make + +clean +true +true +true + + + + + + + + + diff --git a/Master/Real-Time Systems/RTS_A8/.project b/Master/Real-Time Systems/RTS_A8/.project new file mode 100644 index 0000000..337ca6f --- /dev/null +++ b/Master/Real-Time Systems/RTS_A8/.project @@ -0,0 +1,82 @@ + + + RTS_A8 + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + ?name? + + + + org.eclipse.cdt.make.core.append_environment + true + + + org.eclipse.cdt.make.core.autoBuildTarget + all + + + org.eclipse.cdt.make.core.buildArguments + + + + org.eclipse.cdt.make.core.buildCommand + make + + + org.eclipse.cdt.make.core.buildLocation + ${workspace_loc:/RTS_A8/Debug} + + + org.eclipse.cdt.make.core.cleanBuildTarget + clean + + + org.eclipse.cdt.make.core.contents + org.eclipse.cdt.make.core.activeConfigSettings + + + org.eclipse.cdt.make.core.enableAutoBuild + false + + + org.eclipse.cdt.make.core.enableCleanBuild + true + + + org.eclipse.cdt.make.core.enableFullBuild + true + + + org.eclipse.cdt.make.core.fullBuildTarget + all + + + org.eclipse.cdt.make.core.stopOnError + true + + + org.eclipse.cdt.make.core.useDefaultBuildCmd + true + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/Master/Real-Time Systems/RTS_A8/src/ApplicationWindow.cpp b/Master/Real-Time Systems/RTS_A8/src/ApplicationWindow.cpp new file mode 100644 index 0000000..4d7c027 --- /dev/null +++ b/Master/Real-Time Systems/RTS_A8/src/ApplicationWindow.cpp @@ -0,0 +1,84 @@ +/* + * ApplicationWindow.cpp + * + * Created on: 01.12.2010 + * Author: sven + */ +#include +#include +#include "ApplicationWindow.h" + +ApplicationWindow::ApplicationWindow(int width,int height,int bpp) +:mWidth(width),mHeight(height),mBpp(bpp),mCaption("RTS_A8"),mState(0) +{ +} + +ApplicationWindow::~ApplicationWindow() +{ + destroy(); +} + +bool ApplicationWindow::create() +{ + int a=0; + glutInit(&a, NULL); + glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE); + glutInitWindowSize(mWidth, mHeight); + glutCreateWindow(mCaption.c_str()); + + /* + * Now Initialize OpenGL (ES) + */ + glEnable(GL_LINE_SMOOTH); + glShadeModel(GL_SMOOTH); + glDisable(GL_ALPHA_TEST); + glAlphaFunc(GL_EQUAL, 1.0f); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glViewport(0, 0, mWidth, mHeight); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glClearColor(0.0f,0.0f,0.0f,1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // ist das hier notwendig? + glOrtho(0, mWidth, 0, mHeight, 0, 100); + + return true; +} + +//-------------------------------------------------------------------- +bool ApplicationWindow::destroy() +{ + return true; +} + +//-------------------------------------------------------------------- +void ApplicationWindow::setResolution( int width, int height ) +{ + mWidth = width; + mHeight = height; +} + +//-------------------------------------------------------------------- +void ApplicationWindow::setColorDepth( int bpp ) +{ + mBpp = bpp; +} + +//-------------------------------------------------------------------- +void ApplicationWindow::setCaption( const std::string& caption ) +{ + mCaption = caption; +} + +void ApplicationWindow::setFullscreen( bool enable ) +{ + if( enable ) + { + mState |= FULL_SCREEN; + } + else + { + mState &= ~FULL_SCREEN; + } +} diff --git a/Master/Real-Time Systems/RTS_A8/src/ApplicationWindow.h b/Master/Real-Time Systems/RTS_A8/src/ApplicationWindow.h new file mode 100644 index 0000000..e747e2b --- /dev/null +++ b/Master/Real-Time Systems/RTS_A8/src/ApplicationWindow.h @@ -0,0 +1,45 @@ +/* + * ApplicationWindow.h + * + * Created on: 01.12.2010 + * Author: sven + */ + +#ifndef APPLICATIONWINDOW_H_ +#define APPLICATIONWINDOW_H_ + +#include + +class ApplicationWindow { +public: + ApplicationWindow(int width,int height,int bpp); + virtual ~ApplicationWindow(); + bool create(); + bool destroy(); + void setResolution( int width, int height ); + void setColorDepth( int bpp ); + void setCaption( const std::string& caption ); + void setFullscreen( bool enable = true ); + + enum + { + OPENED_WINDOW = 0x0001, + FULL_SCREEN = 0x0002 + }; +private: + int mWidth; + int mHeight; + int mBpp; + + std::string mCaption; + char mState; + + //---------------------------------------------------------------- + /// + /// copy constructor and assign operator + /// set private + ApplicationWindow(const ApplicationWindow& src); + ApplicationWindow& operator=(const ApplicationWindow& src); +}; + +#endif /* APPLICATIONWINDOW_H_ */ diff --git a/Master/Real-Time Systems/RTS_A8/src/Display.cpp b/Master/Real-Time Systems/RTS_A8/src/Display.cpp new file mode 100644 index 0000000..7f8e925 --- /dev/null +++ b/Master/Real-Time Systems/RTS_A8/src/Display.cpp @@ -0,0 +1,111 @@ +/* + * Display.cpp + * + * Created on: 30.11.2010 + * Author: istsveise + */ + +#include "Display.h" +#ifndef POS_H_ + #include "POS.h" +#endif +#include +#include +#include +#include +#include +#include + +using namespace std; + +extern POS vehiclePosition; +extern double lineDir; +const int WIN_WIDTH = 600; +const int WIN_HEIGHT = 600; +const int WIN_BPP = 32; + +// because of static +Display* Display::msDispPtr = NULL; + +void* dispInit(void*) { + ApplicationWindow appWin(WIN_WIDTH,WIN_HEIGHT,WIN_BPP); + if(!appWin.create()) { + cout << "error creating app window. exiting" << endl; + exit(1); + } + Display::msDispPtr->mStarted = true; + glutDisplayFunc(displayFunc); + glutMainLoop(); + return NULL; +} + +Display::Display(int t) +:Task(t),mStarted(false) +{ + Display::msDispPtr = this; + sem_init(&dispSem,0,0); + pthread_create(&mDispThread,NULL,dispInit,NULL); +} + +Display::~Display() { +} + +void Display::execute() +{ + cout << "...Display::execute T="<< T < +using namespace std; + +extern POS vehiclePosition; +extern double lineDir; + +Fahren::Fahren(int t, int v, int d) +:Task(t),V(v),D(d) +{ +} + +Fahren::~Fahren() { +} +void Fahren::execute() +{ + cout << "...Fahren::execute T="<< T << endl; + while(true) { + pthread_mutex_lock(&vehicleMutex); + double realV = (T*V) / 1000; + vehiclePosition.move(realV,D); + double entf = Abstand(vehiclePosition,lineDir); + pthread_mutex_unlock(&vehicleMutex); +// cout << "entf: " << entf << endl; + const int deltha = 1; + if(entf < 0) + D += deltha; + else if (entf > 0) + D -= deltha; + + waitForNextCycle(); +// cout << "Fahren::execute next cycle" << endl; + } +} diff --git a/Master/Real-Time Systems/RTS_A8/src/Fahren.h b/Master/Real-Time Systems/RTS_A8/src/Fahren.h new file mode 100644 index 0000000..987f4f7 --- /dev/null +++ b/Master/Real-Time Systems/RTS_A8/src/Fahren.h @@ -0,0 +1,25 @@ +/* + * Fahren.h + * + * Created on: 30.11.2010 + * Author: istsveise + */ + +#ifndef FAHREN_H_ +#define FAHREN_H_ + +#include "Task.h" + +extern pthread_mutex_t vehicleMutex; + +class Fahren : public Task { +public: + Fahren(int,int,int); + virtual ~Fahren(); + virtual void execute(); +private: + int V; + int D; +}; + +#endif /* FAHREN_H_ */ diff --git a/Master/Real-Time Systems/RTS_A8/src/Notbremse.cpp b/Master/Real-Time Systems/RTS_A8/src/Notbremse.cpp new file mode 100644 index 0000000..dc7f02f --- /dev/null +++ b/Master/Real-Time Systems/RTS_A8/src/Notbremse.cpp @@ -0,0 +1,34 @@ +/* + * Notbremse.cpp + * + * Created on: 01.12.2010 + * Author: sven + */ + +#include "Notbremse.h" +#include +#include +#include +using namespace std; + +Notbremse::Notbremse(int t) +:Task(t),DIST_THRESHOLD(50) +{ +} + +Notbremse::~Notbremse() { + // TODO Auto-generated destructor stub +} +void Notbremse::execute() { + cout << "...Notbremse::executeT=" << T < DIST_THRESHOLD) { + cout << "NOTBREMSE" << endl; + exit(1); + } + pthread_mutex_unlock(&vehicleMutex); + waitForNextCycle(); + } +} diff --git a/Master/Real-Time Systems/RTS_A8/src/Notbremse.h b/Master/Real-Time Systems/RTS_A8/src/Notbremse.h new file mode 100644 index 0000000..86f092a --- /dev/null +++ b/Master/Real-Time Systems/RTS_A8/src/Notbremse.h @@ -0,0 +1,30 @@ +/* + * Notbremse.h + * + * Created on: 01.12.2010 + * Author: sven + */ + +#ifndef NOTBREMSE_H_ +#define NOTBREMSE_H_ + +#include "Task.h" +#ifndef POS_H_ + #include "POS.h" +#endif +#include + +extern pthread_mutex_t vehicleMutex; +extern POS vehiclePosition; +extern double lineDir; + +class Notbremse: public Task { +public: + Notbremse(int t); + virtual ~Notbremse(); + virtual void execute(); +private: + const double DIST_THRESHOLD; +}; + +#endif /* NOTBREMSE_H_ */ diff --git a/Master/Real-Time Systems/RTS_A8/src/POS.h b/Master/Real-Time Systems/RTS_A8/src/POS.h new file mode 100644 index 0000000..490838a --- /dev/null +++ b/Master/Real-Time Systems/RTS_A8/src/POS.h @@ -0,0 +1,69 @@ +/* + * POS.h + * + * Created on: 30.11.2010 + * Author: istsveise + */ + +#ifndef POS_H_ +#define POS_H_ + +#include +#include + +using namespace std; + +extern const double PI; + +struct vector3d { + double x; + double y; + double z; + vector3d(double px,double py):x(px),y(py),z(1) {}; + vector3d():x(0),y(0),z(1) {}; + double length() { + return sqrt( (x*x) + (y*y) ); + } + double scalarProduct(const vector3d& l) { + return (x*l.x)+(y*l.y)+(z*l.z); + } + void crossProduct(const vector3d& l,vector3d& res) + { + res.x = ( (y*l.z) - (z*l.y) ); + res.y = ( (z*l.x) - (x*l.z) ); + res.z = ( (x*l.y) - (y*l.x) ); + } + void normalize() + { + double len = length(); + x = x / len; + y = y / len; + z = z / len; + } +}; + +struct POS { + double x; + double y; + void move(double v, double dir) + { +// cout << "v: " << v << " dir: " << dir < +#include +#include +#include + +using namespace std; + +void* timer_main(void* task) { + Task* t = (Task*) task; + while(true) { + usleep(t->T*1000); + sem_post(&t->threadSem); + } + return NULL; +} + +void* execute_main(void* task) { + cout << "Start execution..." << endl; + Task* t = (Task*) task; + t->execute(); + + return NULL; +} + +Task::Task(int t=1000) +:T(t) +{ + sem_init(&this->threadSem,0,0); + + pthread_t timerthread; + pthread_t executethread; + + pthread_create(&timerthread,NULL,&timer_main,(void*) this); + pthread_create(&executethread,NULL,&execute_main,(void*) this); +} + +Task::~Task() { +} + +void Task::waitForNextCycle() +{ + sem_wait(&this->threadSem); +} diff --git a/Master/Real-Time Systems/RTS_A8/src/Task.h b/Master/Real-Time Systems/RTS_A8/src/Task.h new file mode 100644 index 0000000..be3b377 --- /dev/null +++ b/Master/Real-Time Systems/RTS_A8/src/Task.h @@ -0,0 +1,28 @@ +/* + * Task.h + * + * Created on: 30.11.2010 + * Author: istsveise + */ + +#ifndef TASK_H_ +#define TASK_H_ + +#include + +class Task { +public: + Task(int); + virtual ~Task(); +protected: + int T; // period in ms + sem_t threadSem; +public: + friend void* timer_main(void* task); + friend void* execute_main(void* task); + virtual void execute() = 0; +protected: + void waitForNextCycle(); +}; + +#endif /* TASK_H_ */ diff --git a/Master/Real-Time Systems/RTS_A8/src/main.cpp b/Master/Real-Time Systems/RTS_A8/src/main.cpp new file mode 100644 index 0000000..fc3feed --- /dev/null +++ b/Master/Real-Time Systems/RTS_A8/src/main.cpp @@ -0,0 +1,78 @@ +/* + * main.cpp + * + * Created on: 30.11.2010 + * Author: istsveise + */ +#include "Task.h" +#include "Display.h" +#include "Fahren.h" +#ifndef POS_H_ + #include "POS.h" +#endif +#ifndef NOTBREMSE_H_ + #include "Notbremse.h" +#endif + +#include +#include +#include +#include +#include + +using namespace std; + +// global mutex to protect vehicle +pthread_mutex_t vehicleMutex; + +POS vehiclePosition; +double lineDir; +const double PI = 3.14159265359; + +double Abstand(POS p,double Ldir) +{ + vector3d origin; + vector3d point(p.x,p.y); + double polx = 1.0; + double ldirRad = Ldir*PI/180; + double m = tan(ldirRad); + double poly = polx*m; + vector3d pointOnLine(polx,poly); + vector3d normVec; + origin.crossProduct(pointOnLine,normVec); + normVec.normalize(); + double d = normVec.scalarProduct(point); + return d; +} + +void InitAll(int x) +{ + pthread_mutex_init(&vehicleMutex,NULL); + pthread_mutex_lock(&vehicleMutex); + lineDir = x; + vehiclePosition.x = 0; + vehiclePosition.y = 0; + pthread_mutex_unlock(&vehicleMutex); +} + +int main(int argc,char* argv[]) +{ + InitAll(30); // direction of line [0, 90] + + sleep(1); + + Display D(100); + Notbremse N(100); + + cout << "Los geht's...!" << endl; + Fahren F(/* period in ms */ 100, + /* speed in pixels per second */ 20, + /* start direction [0, 90] */ 0); + + //sleep for ever + sem_t block; + sem_init(&block,0,0); + sem_wait(&block); + + return EXIT_SUCCESS; +} -- cgit v1.2.3