-
Notifications
You must be signed in to change notification settings - Fork 0
/
motor.cpp
executable file
·58 lines (45 loc) · 1.06 KB
/
motor.cpp
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
57
58
#include "motor.hpp"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
MotorManager::MotorManager(const char* filename,speed_t rate){
fd=serialOpen("/dev/ttyS0",115200);
if(fd<0){
printf("can not open serialport\n");
exit(1);
}else{
printf("success open serialport\n");
}
}
MotorManager::~MotorManager(){
if (fd>=0){
//swap config
serialClose(fd);
printf("serial port closed");
}
}
std::unique_ptr<Motor> MotorManager::GenerateMotor(address_t addr){
return nullptr;//TODO STUB
}
void MotorManager::Write(const char*send){
serialPrintf(fd,*send);
}
void dtm(int id,float dt){
std::string word("sel %d\r",id);
void MotorManager::Write(&word);
std::string word("dt %4.2f\r",dt);
void MotorManager::Write(&word);
delay(1);
}
void mcm(int id,int mc){
std::string word("sel %d\r",id);
void MotorManager::Write(&word);
std::string word("dt %4.2f\r",mc);
void MotorManager::Write(&word);
if(id==tirelb){
std::string word("go\r");
void MotorManager::Write(&word);
}
}