cellUview 1.0.0
A real-time image processing and analysis suite for digital microscopy.
Loading...
Searching...
No Matches
motorDriver.h
1#ifndef MOTOR_DRIVER_H
2#define MOTOR_DRIVER_H
3
4#include <iostream>
5#include <stdlib.h>
6#include <thread>
7
8#include <wiringSerial.h>
9#include <unistd.h>
10
11#include <condition_variable>
12#include <mutex>
13#include <chrono>
14using namespace std::chrono_literals;
15
16
17// class MotorCallback {
18// public:
19// virtual void returnPosition(int x, int y, int z) = 0;
20// };
21
22
27
28public:
29 MotorDriver() = default; // constructor
30
31 // void registerCallback(MotorCallback* cb);
32
33 //void start(std::string device = "/dev/ttyUSB0", int baud = 115200);
34 void start(const char* device = "/dev/ttyUSB0", int baud = 115200);
35 void stop();
36
37 int* getPosition();
38 bool getRunning();
39 bool getConnected();
40
41 void mov(char axis, int inc);
42
43
44private:
45
46 //void movThread();
47
48 void run();
49
50 void resetToZero();
51 void updatePosition();
52
53 // MotorCallback* motorCb = nullptr;
54 bool enabled = false; // motor thread enable
55 bool connected = false; // motor board connection established
56
57 int fd = 0;
58 int positionArray[3] = {0, 0, 0};
59 int bytesToRead;
60
61 char commandAxis;
62 int commandInc;
63
64 bool running = false; // indicates motors currently moving
65 bool update = false; // indicates new move to make
66
67 std::thread motorThread;
68
69 std::mutex mut;
70 std::condition_variable cond_var;
71
72 char firmwareVer[26];
73 char dataRead[30];
74
75
76};
77
78
79// class MotorPrintCallback : public MotorCallback {
80// virtual void returnPosition(int x, int y, int z){
81// std::cout << "Motor current position: " << "x: " << x << " y: " << y << " z: " << z << std::endl;
82// }
83// };
84
85
86#endif //MOTOR_DRIVER_H
Definition: motorDriver.h:26
void mov(char axis, int inc)
Definition: motorDriver.cpp:227
void start(const char *device="/dev/ttyUSB0", int baud=115200)
Definition: motorDriver.cpp:14
void stop()
Definition: motorDriver.cpp:60
bool getConnected()
Definition: motorDriver.cpp:218
bool getRunning()
Definition: motorDriver.cpp:210
int * getPosition()
Definition: motorDriver.cpp:202