-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
128 lines (119 loc) · 3.17 KB
/
test.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "test.h"
#include "motorscontroller.h"
#include <stdio.h>
#include <iostream>
TestDemo::TestDemo() : m_bHasLaunched(false)
{
}
TestDemo::~TestDemo()
{
}
void TestDemo::operationFinished(uint8_t id, uint8_t type)
{
switch (type)
{
case MotorsController::Recognize_Finished:
{
vector<uint8_t> idArray = controllerInst->getMotorIdArray();
for(int i=0;i<idArray.size();++i)
{
if(controllerInst->getMotorAttribute(idArray.at(i),MotorData::MOTOR_SWITCH)
!= UserDefine::MOTOR_SWITCH_ON)
{
controllerInst->launchMotor(idArray.at(i));
//controllerInst->switchAutoRefresh(idArray.at(i),true);
//controllerInst->setAutoRefreshInterval(idArray.at(i),1000);
}
else
{
m_bHasLaunched = true;
}
}
}
break;
case MotorsController::Launch_Finished:
{
m_bHasLaunched = true;
// vector<uint8_t> idArray;
// idArray.push_back(id);
// controllerInst->activeMotorsMode(idArray, MotorData::Mode_Profile_Pos);
}
break;
default:
break;
}
}
void TestDemo::cmdOperation(uint8_t directive, double value)
{
if (!m_bHasLaunched)
return;
vector<uint8_t> idArray = controllerInst->getMotorIdArray();
switch (directive)
{
case 'a':
controllerInst->activeMotorsMode(idArray, MotorData::Motor_Mode(value));
break;
case 's':
controllerInst->closeAllMotors();
break;
case 'p':
for (int i = 0; i < idArray.size(); ++i)
{
controllerInst->setPosition(idArray.at(i), value);
}
break;
case 'c':
for (int i = 0; i < idArray.size(); ++i)
{
controllerInst->setCurrent(idArray.at(i), value);
}
break;
case 'v':
for (int i = 0; i < idArray.size(); ++i)
{
controllerInst->setVelocity(idArray.at(i), value);
}
break;
case 'r':
{
int nTag = (int)value;
MotorData::Motor_Data_Id dataId = MotorData::CUR_ACTURAL;
if (nTag == 2)
{
dataId = MotorData::VEL_ACTURAL;
}
else if (nTag == 3)
{
dataId = MotorData::POS_ACTURAL;
}
for (int i = 0; i < idArray.size(); ++i)
{
controllerInst->regainAttrbute(idArray.at(i), dataId);
}
}
break;
default:
break;
}
}
void TestDemo::motorAttrChanged(uint8_t id, uint8_t attrId, double value)
{
switch (attrId)
{
case MotorData::CUR_ACTURAL:
cout << "motor " << (int)id << " current:" << value << endl;
break;
case MotorData::VEL_ACTURAL:
cout << "motor " << (int)id << " velocity:" << value <<endl;
break;
case MotorData::POS_ACTURAL:
cout << "motor " << (int)id << " position:" << value <<endl;
break;
default:
break;
}
}
void TestDemo::errorOccur(uint8_t id,uint16_t errorId, string errorInfo)
{
cout << id << " error " << errorId << " " << errorInfo.c_str() << endl;
}