summaryrefslogtreecommitdiffstats
path: root/Master/Real-Time Systems/RTS_A8/src/Fahren.cpp
blob: 12c77a0c5a28a30da752d1479362e5a5f65b10af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * Fahren.cpp
 *
 *  Created on: 30.11.2010
 *      Author: istsveise
 */

#include "Fahren.h"
#ifndef POS_H_
	#include "POS.h"
#endif
#include <iostream>
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;
	}
}