@@ -123,9 +123,10 @@ public void PowerOff()
123
123
/// <param name="jointNo">joint number: 1 ~ 6</param>
124
124
/// <param name="angle">angle value: -180 ~ 180 </param>
125
125
/// <param name="speed">speed value: 0 ~ 100</param>
126
- public void SendOneAngle ( int jointNo , int angle , int speed )
126
+ public void SendOneAngle ( int jointNo , double angle , int speed )
127
127
{
128
- int _angle = angle * 100 , idx = 0 ;
128
+ int _angle = ( int ) angle * 100 ;
129
+ int idx = 0 ;
129
130
var command = new byte [ 9 ] ;
130
131
// set header
131
132
command [ idx ++ ] = 0xfe ;
@@ -147,19 +148,22 @@ public void SendOneAngle(int jointNo, int angle, int speed)
147
148
/// </summary>
148
149
/// <param name="angles">angles[], length: 6</param>
149
150
/// <param name="speed">speed value: 0 ~ 100</param>
150
- public void SendAngles ( int [ ] angles , int speed )
151
+ public void SendAngles ( double [ ] angles , int speed )
151
152
{
152
153
var command = new byte [ 18 ] ;
153
154
var idx = 0 ;
155
+ int [ ] angles1 = { 0 , 0 , 0 , 0 , 0 , 0 } ;
154
156
command [ idx ++ ] = 0xfe ;
155
157
command [ idx ++ ] = 0xfe ;
156
158
command [ idx ++ ] = 0x0f ;
157
159
command [ idx ++ ] = 0x22 ;
158
160
for ( var j = 0 ; j < angles . Length ; ++ j )
159
161
{
160
162
angles [ j ] *= 100 ;
163
+ angles1 [ j ] = ( int ) ( angles [ j ] ) ;
164
+ //angles1[j] = (int)(angles[j]*100);
161
165
}
162
- var a = Int16ArrToBytes ( angles ) ;
166
+ var a = Int16ArrToBytes ( angles1 ) ;
163
167
foreach ( var t in a )
164
168
{
165
169
command [ idx ++ ] = t ;
@@ -174,7 +178,7 @@ public void SendAngles(int[] angles, int speed)
174
178
/// Get all angles
175
179
/// </summary>
176
180
/// <returns>int[], length: 6</returns>
177
- public int [ ] GetAngles ( )
181
+ public float [ ] GetAngles ( )
178
182
{
179
183
byte [ ] command = { 0xfe , 0xfe , 0x02 , 0x20 , 0xfa } ;
180
184
Write ( command , 0 , command . Length ) ;
@@ -186,16 +190,16 @@ public int[] GetAngles()
186
190
var m_recvBytes = new byte [ _serialPort . BytesToRead ] ;
187
191
var result = _serialPort . Read ( m_recvBytes , 0 , m_recvBytes . Length ) ;
188
192
if ( result <= 0 )
189
- return Array . Empty < int > ( ) ;
193
+ return Array . Empty < float > ( ) ;
190
194
191
195
// get valid index
192
196
var idx = getValidIndex ( m_recvBytes ) ;
193
197
if ( idx == - 1 )
194
- return Array . Empty < int > ( ) ;
198
+ return Array . Empty < float > ( ) ;
195
199
196
200
// process data
197
- var len = ( int ) m_recvBytes [ idx ] - 1 ;
198
- var res = new int [ 6 ] ;
201
+ var len = ( float ) m_recvBytes [ idx ] - 1 ;
202
+ var res = new float [ 6 ] ;
199
203
var resIdx = 0 ;
200
204
for ( var i = idx + 1 ; i < idx + len ; i += 2 )
201
205
{
@@ -211,9 +215,11 @@ public int[] GetAngles()
211
215
/// <param name="coord">coord No: 1 - 6</param>
212
216
/// <param name="value">coord value</param>
213
217
/// <param name="speed">speed: 0 ~ 100</param>
214
- public void SendOneCoord ( int coord , int value , int speed )
218
+ public void SendOneCoord ( double coord , int value , int speed )
215
219
{
216
- int idx = 0 , _value = coord < 4 ? coord * 10 : coord * 100 ;
220
+ int idx = 0 ;
221
+ int _value = ( int ) ( coord < 4 ? value * 10 : value * 100 ) ;
222
+
217
223
var command = new byte [ 9 ] ;
218
224
// set header
219
225
command [ idx ++ ] = 0xfe ;
@@ -238,10 +244,11 @@ public void SendOneCoord(int coord, int value, int speed)
238
244
/// <param name="coords">int[], length: 6</param>
239
245
/// <param name="speed">speed: int, value: 0 ~ 100</param>
240
246
/// <param name="mode">mode: 0 - angular, 1 - linear</param>
241
- public void SendCoords ( int [ ] coords , int speed , int mode )
247
+ public void SendCoords ( double [ ] coords , int speed , int mode )
242
248
{
243
249
var command = new byte [ 19 ] ;
244
250
var idx = 0 ;
251
+ int [ ] coords1 = { 0 , 0 , 0 , 0 , 0 , 0 } ;
245
252
// set header
246
253
command [ idx ++ ] = 0xfe ;
247
254
command [ idx ++ ] = 0xfe ;
@@ -251,13 +258,15 @@ public void SendCoords(int[] coords, int speed, int mode)
251
258
for ( var i = 0 ; i < 3 ; ++ i )
252
259
{
253
260
coords [ i ] *= 10 ;
261
+ coords1 [ i ] = ( int ) coords [ i ] ;
254
262
}
255
263
for ( var i = 3 ; i < 6 ; ++ i )
256
264
{
257
265
coords [ i ] *= 100 ;
266
+ coords1 [ i ] = ( int ) coords [ i ] ;
258
267
}
259
268
// append to command
260
- var a = Int16ArrToBytes ( coords ) ;
269
+ var a = Int16ArrToBytes ( coords1 ) ;
261
270
foreach ( var t in a )
262
271
{
263
272
command [ idx ++ ] = t ;
0 commit comments