-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
108 lines (87 loc) · 2.66 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "DynamixelHandler.h"
char * serialPort;
void getArgs(const std::string&, char, std::vector<std::string>&);
int main(int argc, char *argv[])
{
if(argc != 2)
{
std::cout << "USAGE : " << argv[0] << " <serialPort>" << std::endl;
return 1;
}
serialPort = argv[1];
DynamixelInterface *interface=createSerialInterface(serialPort);
interface->begin(9600);
char orderC[100];
std::string order = "";
std::vector<std::string> args = std::vector<std::string>();
while(order.compare("exit"))
{
std::cout << std::endl << "CosmOS Dynamixel Console : ";
std::cin.getline(orderC, sizeof(orderC));
order = std::string(orderC);
std::cout << std::endl;
if(!order.compare("exit")) continue;
args.clear();
getArgs(order, ' ', args);
if(!args[0].compare("setid"))
{
if(args.size() != 2)
{
std::cout << "USAGE : setid <id> ; Sends a broadcast packet to set the id" << std::endl;
continue;
}
int id;
try
{
id = std::stoi(args[1]);
}
catch (std::exception const &e)
{
std::cout << "BAD ID ; id must be between 0 and 253" << std::endl;
continue;
}
if(id < 0 || id > 253)
{
std::cout << "BAD ID ; id must be between 0 and 253" << std::endl;
continue;
}
DynamixelMotor broadcaster = DynamixelMotor(*interface, 0xFE);
broadcaster.setID((uint8_t)id);
continue;
}
else if(!args[0].compare("select"))
{
if(args.size() != 2)
{
std::cout << "USAGE : select <id> ; Selects the specified device" << std::endl;
continue;
}
int id;
try
{
id = std::stoi(args[1]);
}
catch (std::exception const &e)
{
std::cout << "BAD ID ; id must be between 0 and 254 (254 is broadcast)" << std::endl;
continue;
}
if(id < 0 || id > 254)
{
std::cout << "BAD ID ; id must be between 0 and 254 (254 is broadcast)" << std::endl;
continue;
}
if(dynamixelHandle((DynamixelID)id, interface) == 1)
{
return 1;
}
continue;
}
else
{
std::cout << "No such command" << std::endl;
}
}
delete(interface);
return 0;
}