forked from ozkryn/EPOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEpos3ReadWriteLib.cpp
executable file
·169 lines (142 loc) · 5.89 KB
/
Epos3ReadWriteLib.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include "Epos3ReadWriteLib.h"
/****************************************************************************/
/**
* Added by Oscar Caravaca 14/05/2015.
* This method is for ESPO3 initializtion. It takes the ESPOS to the Operation Mode state
* @param NUll
* @return void
*/
void Epos3ReadWriteLib::initEPOS3()
{
int val=0;
cout<<"Initializing ESPO3"<<endl;
sendDownloadCommand("0", "0x6040", "0", "uint16","0x00ff");
sendUploadCommand("0", "0x6041", "0", "uint16");
sendDownloadCommand("0", "0x6040", "0", "uint16","0x0006");
sendUploadCommand("0", "0x6041", "0", "uint16");
sendDownloadCommand("0", "0x6040", "0", "uint16","0x0007");
sendUploadCommand("0", "0x6041", "0", "uint16");
sendDownloadCommand("0", "0x6040", "0", "uint16","0x000f");
val = sendUploadCommand("0", "0x6041", "0", "uint16");
cout<<"Val:"<<val<<endl;
}
/****************************************************************************/
/**
* Added by Oscar Caravaca 14/05/2015.
* This method send an upload command in order to read a register values
* @param string positionStr: string parameter to indicate the slave position, example: "0"
* @param string regStr: string parameter to indicate the register to be read, example: "0x6041"
* @param string indexStr: string parameter to indicate the subindex of the register to be read, example: "0"
* @param string dataTypeStr: string parameter to indicate the data type of the value is expected to read, example: "tuint16", see ESPOS3 documentation.
* @return integer value of the read register.
*/
int Epos3ReadWriteLib::sendUploadCommand(string positionStr, string regStr, string indexStr, string dataTypeStr)
{
int retval = 0;
commandArgs.clear();
commandName = "upload";
commandArgs.push_back(regStr);
commandArgs.push_back(indexStr);
cout<<"sending Upload command..."<<endl;
CommandUpload *cmd;
cmd = new CommandUpload();
cout<<"ckeck1"<< positions<<endl;
try {
cout<<"ckeck2:"<< positions<<endl;
cmd->setMasters(masters);
cout<<"cmd->setMasters(masters):"<< masters<<endl;
cmd->setVerbosity(verbosity);
cout<<"cmd->setVerbosity(verbosity):"<< verbosity<<endl;
cmd->setAliases(aliases);
cout<<"cmd->setAliases(aliases):"<< aliases<<endl;
cout<<"ckeck3"<<endl;
cmd->setPositions(positions);
cout<<"cmd->setPositions(positions):"<< positions<<endl;
cmd->setDomains(domains);
cout<<"cmd->setDomains(domains):"<< domains<<endl;
cmd->setDataType(dataTypeStr);
cout<<"cmd->setDataType(dataTypeStr):"<< dataTypeStr<<endl;
cmd->setOutputFile(outputFile);
cout<<"cmd->setOutputFile(outputFile):"<< outputFile<<endl;
cmd->setSkin(skin);
cout<<"cmd->setSkin(skin):"<< skin<<endl;
force=true;
cmd->setForce(force);
cout<<"cmd->setForce(force):"<< force<<endl;
cmd->execute(commandArgs);
retval = cmd->getRegValue();
} catch (InvalidUsageException &e) {
cerr << e.what() << endl << endl;
if(e.what()=="Failed to download SDO: Input/output error")
{
cout<<"Catch!!!!!!!!!!!!!!"<<endl;
}
retval = -1;
}
return retval;
}
/****************************************************************************/
/**
* Added by Oscar Caravaca 14/05/2015.
* This method send an upload command in order to read a register values
* @param string positionStr: string parameter to indicate the slave position, example: "0"
* @param string regStr: string parameter to indicate the register to be read, example: "0x6041"
* @param string indexStr: string parameter to indicate the subindex of the register to be read, example: "0"
* @param string dataTypeStr: string parameter to indicate the data type of the value is expected to read, example: "tuint16", see ESPOS3 documentation.
* @param string valuesStr: string parameter to indicate the value to written in the require register.
* @return void: no return.
*/
int Epos3ReadWriteLib::sendDownloadCommand(string positionStr, string regStr, string indexStr, string dataTypeStr, string valuesStr)
{
int retval = 0;
commandArgs.clear();
commandName = "download";
commandArgs.push_back(regStr);
commandArgs.push_back(indexStr);
commandArgs.push_back(valuesStr);
cout<<"sending download command..."<<endl;
Command *cmd;
cmd = new CommandDownload();
try {
cout<<"ckeck2"<< positions<<endl;
cmd->setMasters(masters);
cout<<"cmd->setMasters(masters)"<< masters<<endl;
cmd->setVerbosity(verbosity);
cout<<"cmd->setVerbosity(verbosity)"<< verbosity<<endl;
cmd->setAliases(aliases);
cout<<"cmd->setAliases(aliases)"<< aliases<<endl;
cout<<"ckeck3"<<endl;
cmd->setPositions(positions);
cout<<"cmd->setPositions(positions)"<< positions<<endl;
cmd->setDomains(domains);
cout<<"cmd->setDomains(domains)"<< domains<<endl;
cmd->setDataType(dataTypeStr);
cout<<"cmd->setDataType(dataTypeStr)"<< dataTypeStr<<endl;
cmd->setOutputFile(outputFile);
cout<<"cmd->setOutputFile(outputFile)"<< outputFile<<endl;
cmd->setSkin(skin);
cout<<"cmd->setSkin(skin)"<< skin<<endl;
force=true;
cmd->setForce(force);
cout<<"cmd->setForce(force)"<< force<<endl;
cmd->execute(commandArgs);
} catch (InvalidUsageException &e) {
cerr << e.what() << endl << endl;
retval = 1;
}
return retval;
}
void moveMotor( int newtargerPosition, int profileVelocity )
{
char temp[11];
string pos;
string newVel;
sprintf(temp,"%x",newtargerPosition);
pos = "0x" + string(temp);
sprintf(temp,"%x",profileVelocity);
newVel = "0x" + string(temp);
sendDownloadCommand("0", "0x607A", "0", "uint32",pos);
sendDownloadCommand("0", "0x6081", "0", "uint32",newVel);
sendDownloadCommand("0", "0x6040", "0", "uint16","0x006f");
sendDownloadCommand("0", "0x6040", "0", "uint16","0x007f");
}