-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdc_motor.cpp
More file actions
executable file
·56 lines (41 loc) · 1.39 KB
/
dc_motor.cpp
File metadata and controls
executable file
·56 lines (41 loc) · 1.39 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
// Created by Oleksandra Baga
#include "dc_motor.h"
#include "QDebug"
#include <math.h>
#include <QTimer>
#include <map>
std::map<MotorType, const char *> MOTOR_TYPE_NAMES = {
{MOTOR_SUGAR, "SUGAR MOTOR"},
{MOTOR_COFFEE, "COFFEE POWDER MOTOR"},
{MOTOR_MILK, "MILK MOTOR"},
{MOTOR_CACAO, "CACAO POWDER MOTOR"}
};
DC_Motor::DC_Motor() {
actuatorState = UNDEFINED;
actuatorType = DC_MOTOR;
isRotating = false;
}
DC_Motor::~DC_Motor() {
}
void DC_Motor::rotate(int componentAmount) {
qDebug() << "DC MOTOR: Starting motor rotation:" << MOTOR_TYPE_NAMES[motorType];
int time = calculateRotatingTime(componentAmount);
qDebug() << "DC MOTOR: Realtime motor simulation started:" << MOTOR_TYPE_NAMES[motorType] << "...";
isRotating = true;
QTimer::singleShot(time, this, &DC_Motor::rotatingDone);
}
int DC_Motor::calculateRotatingTime(int componentAmount) {
int time = componentAmount * ROTATING_TIME_MS;
qDebug() << "DC MOTOR:" << MOTOR_TYPE_NAMES[motorType] << "Component is set:" << componentAmount << "Rotating will last" << time << " ms";
return time;
}
bool DC_Motor::getIsRotating() const {
return isRotating;
}
void DC_Motor::rotatingDone() {
isRotating = false;
qDebug() << "DC MOTOR:: Realtime motor simulation done:" << MOTOR_TYPE_NAMES[motorType];
}
void DC_Motor::setMotorType(MotorType motorType) {
this->motorType = motorType;
}