@@ -60,7 +60,7 @@ void SmartServoClass::writeCmd(uint8_t const id, SmartServoOperation const instr
60
60
void SmartServoClass::writeByteCmd (uint8_t const id, uint8_t const address, uint8_t const data) {
61
61
_txPacket.id = id;
62
62
_txPacket.length = 2 +2 ;
63
- _txPacket.instruction = toVal (SmartServoOperation::WRITE);
63
+ _txPacket.instruction = CMD (SmartServoOperation::WRITE);
64
64
_txPacket.payload [0 ]=address;
65
65
_txPacket.payload [1 ]=data;
66
66
sendPacket ();
@@ -69,7 +69,7 @@ void SmartServoClass::writeByteCmd(uint8_t const id, uint8_t const address, uint
69
69
void SmartServoClass::writeWordCmd (uint8_t const id, uint8_t const address, uint16_t const data) {
70
70
_txPacket.id = id;
71
71
_txPacket.length = 2 +3 ;
72
- _txPacket.instruction = toVal (SmartServoOperation::WRITE);
72
+ _txPacket.instruction = CMD (SmartServoOperation::WRITE);
73
73
_txPacket.payload [0 ]=address;
74
74
_txPacket.payload [1 ]=data>>8 ;
75
75
_txPacket.payload [2 ]=data;
@@ -93,7 +93,7 @@ void SmartServoClass::receiveResponse(int const howMany) {
93
93
int SmartServoClass::readBuffer (uint8_t const id, uint8_t const address,uint8_t const len) {
94
94
_txPacket.id = id;
95
95
_txPacket.length = 2 +2 ;
96
- _txPacket.instruction = toVal (SmartServoOperation::READ);
96
+ _txPacket.instruction = CMD (SmartServoOperation::READ);
97
97
_txPacket.payload [0 ]=address;
98
98
_txPacket.payload [1 ]=len;
99
99
sendPacket ();
@@ -171,8 +171,8 @@ int SmartServoClass::begin() {
171
171
_txPacket.header [1 ] = 0xff ;
172
172
_RS485.begin (115200 , 0 , 90 );
173
173
_RS485.receive ();
174
- writeByteCmd (BROADCAST, toVal (SmartServoRegister::SERVO_MOTOR_MODE), 1 );
175
- writeByteCmd (BROADCAST, toVal (SmartServoRegister::TORQUE_SWITCH) ,1 );
174
+ writeByteCmd (BROADCAST, REG (SmartServoRegister::SERVO_MOTOR_MODE), 1 );
175
+ writeByteCmd (BROADCAST, REG (SmartServoRegister::TORQUE_SWITCH) ,1 );
176
176
_positionMode = PositionMode::IMMEDIATE;
177
177
return 0 ;
178
178
} else {
@@ -186,7 +186,7 @@ void SmartServoClass::setPosition(uint8_t const id, float const angle, uint16_t
186
186
_targetPosition[id] = angleToPosition (angle);
187
187
_targetSpeed[id] = speed;
188
188
if (_positionMode==PositionMode::IMMEDIATE) {
189
- writeWordCmd (id, toVal (SmartServoRegister::TARGET_POSITION_H), angleToPosition (angle));
189
+ writeWordCmd (id, REG (SmartServoRegister::TARGET_POSITION_H), angleToPosition (angle));
190
190
}
191
191
}
192
192
mutex.unlock ();
@@ -196,24 +196,24 @@ float SmartServoClass::getPosition(uint8_t const id) {
196
196
mutex.lock ();
197
197
float ret = -1 ;
198
198
if (id<MAX_MOTORS) {
199
- ret = positionToAngle (readWordCmd (id, toVal (SmartServoRegister::POSITION_H)));
199
+ ret = positionToAngle (readWordCmd (id, REG (SmartServoRegister::POSITION_H)));
200
200
}
201
201
mutex.unlock ();
202
202
return ret;
203
203
}
204
204
205
205
void SmartServoClass::center (uint8_t const id, uint16_t const position) {
206
206
mutex.lock ();
207
- writeWordCmd (id, toVal (SmartServoRegister::CENTER_POINT_ADJ_H), position);
207
+ writeWordCmd (id, REG (SmartServoRegister::CENTER_POINT_ADJ_H), position);
208
208
mutex.unlock ();
209
209
}
210
210
211
211
void SmartServoClass::synchronize () {
212
212
mutex.lock ();
213
213
_txPacket.id = 0xFE ;
214
214
_txPacket.length = (4 +1 )*MAX_MOTORS +4 ;
215
- _txPacket.instruction = toVal (SmartServoOperation::SYNC_WRITE);
216
- _txPacket.payload [0 ] = toVal (SmartServoRegister::TARGET_POSITION_H);
215
+ _txPacket.instruction = CMD (SmartServoOperation::SYNC_WRITE);
216
+ _txPacket.payload [0 ] = REG (SmartServoRegister::TARGET_POSITION_H);
217
217
_txPacket.payload [1 ] = 4 ;
218
218
int index = 2 ;
219
219
@@ -230,92 +230,92 @@ void SmartServoClass::synchronize() {
230
230
231
231
void SmartServoClass::setTorque (bool const torque) {
232
232
mutex.lock ();
233
- writeByteCmd (BROADCAST, toVal (SmartServoRegister::TORQUE_SWITCH), torque ? 1 : 0 );
233
+ writeByteCmd (BROADCAST, REG (SmartServoRegister::TORQUE_SWITCH), torque ? 1 : 0 );
234
234
mutex.unlock ();
235
235
}
236
236
237
237
void SmartServoClass::setTorque (uint8_t const id, bool const torque) {
238
238
mutex.lock ();
239
- writeByteCmd (id, toVal (SmartServoRegister::TORQUE_SWITCH), torque ? 1 : 0 );
239
+ writeByteCmd (id, REG (SmartServoRegister::TORQUE_SWITCH), torque ? 1 : 0 );
240
240
mutex.unlock ();
241
241
}
242
242
243
243
void SmartServoClass::setTime (uint8_t const id, uint16_t const time) {
244
244
mutex.lock ();
245
- writeWordCmd (id, toVal (SmartServoRegister::RUN_TIME_H), time);
245
+ writeWordCmd (id, REG (SmartServoRegister::RUN_TIME_H), time);
246
246
mutex.unlock ();
247
247
}
248
248
249
249
void SmartServoClass::setMaxTorque (uint16_t const torque) {
250
250
mutex.lock ();
251
- writeWordCmd (BROADCAST, toVal (SmartServoRegister::MAX_TORQUE_H), torque);
251
+ writeWordCmd (BROADCAST, REG (SmartServoRegister::MAX_TORQUE_H), torque);
252
252
mutex.unlock ();
253
253
}
254
254
255
255
void SmartServoClass::setMaxTorque (uint8_t const id, uint16_t const torque) {
256
256
mutex.lock ();
257
- writeWordCmd (id+1 , toVal (SmartServoRegister::MAX_TORQUE_H), torque);
257
+ writeWordCmd (id+1 , REG (SmartServoRegister::MAX_TORQUE_H), torque);
258
258
mutex.unlock ();
259
259
}
260
260
261
261
void SmartServoClass::setID (uint8_t const id) {
262
262
mutex.lock ();
263
- writeByteCmd (BROADCAST, toVal (SmartServoRegister::ID), id);
263
+ writeByteCmd (BROADCAST, REG (SmartServoRegister::ID), id);
264
264
mutex.unlock ();
265
265
}
266
266
267
267
void SmartServoClass::engage (uint8_t const id) {
268
268
mutex.lock ();
269
- writeByteCmd (id, toVal (SmartServoRegister::TORQUE_SWITCH), 0x1 );
269
+ writeByteCmd (id, REG (SmartServoRegister::TORQUE_SWITCH), 0x1 );
270
270
mutex.unlock ();
271
271
}
272
272
273
273
void SmartServoClass::disengage (uint8_t const id) {
274
274
mutex.lock ();
275
- writeByteCmd (id, toVal (SmartServoRegister::TORQUE_SWITCH), 0 );
275
+ writeByteCmd (id, REG (SmartServoRegister::TORQUE_SWITCH), 0 );
276
276
mutex.unlock ();
277
277
}
278
278
279
279
bool SmartServoClass::isEngaged (uint8_t const id) {
280
280
mutex.lock ();
281
- int ret = readByteCmd (id, toVal (SmartServoRegister::TORQUE_SWITCH));
281
+ int ret = readByteCmd (id, REG (SmartServoRegister::TORQUE_SWITCH));
282
282
mutex.unlock ();
283
283
return ret != 0 ;
284
284
}
285
285
286
286
void SmartServoClass::setStallProtectionTime (uint8_t const time) {
287
287
mutex.lock ();
288
- writeByteCmd (BROADCAST, toVal (SmartServoRegister::STALL_PROTECTION_TIME), time);
288
+ writeByteCmd (BROADCAST, REG (SmartServoRegister::STALL_PROTECTION_TIME), time);
289
289
mutex.unlock ();
290
290
}
291
291
292
292
void SmartServoClass::setStallProtectionTime (uint8_t const id, uint8_t const time) {
293
293
mutex.lock ();
294
- writeByteCmd (id, toVal (SmartServoRegister::STALL_PROTECTION_TIME), time);
294
+ writeByteCmd (id, REG (SmartServoRegister::STALL_PROTECTION_TIME), time);
295
295
mutex.unlock ();
296
296
}
297
297
298
298
void SmartServoClass::setMinAngle (float const angle) {
299
299
mutex.lock ();
300
- writeByteCmd (BROADCAST, toVal (SmartServoRegister::MIN_ANGLE_LIMIT_H), angleToPosition (angle));
300
+ writeByteCmd (BROADCAST, REG (SmartServoRegister::MIN_ANGLE_LIMIT_H), angleToPosition (angle));
301
301
mutex.unlock ();
302
302
}
303
303
304
304
void SmartServoClass::setMinAngle (uint8_t const id, float const angle) {
305
305
mutex.lock ();
306
- writeByteCmd (id, toVal (SmartServoRegister::MIN_ANGLE_LIMIT_H), angleToPosition (angle));
306
+ writeByteCmd (id, REG (SmartServoRegister::MIN_ANGLE_LIMIT_H), angleToPosition (angle));
307
307
mutex.unlock ();
308
308
}
309
309
310
310
void SmartServoClass::setMaxAngle (float const angle) {
311
311
mutex.lock ();
312
- writeByteCmd (BROADCAST, toVal (SmartServoRegister::MAX_ANGLE_LIMIT_H), angleToPosition (angle));
312
+ writeByteCmd (BROADCAST, REG (SmartServoRegister::MAX_ANGLE_LIMIT_H), angleToPosition (angle));
313
313
mutex.unlock ();
314
314
}
315
315
316
316
void SmartServoClass::setMaxAngle (uint8_t const id, float const angle) {
317
317
mutex.lock ();
318
- writeByteCmd (id, toVal (SmartServoRegister::MAX_ANGLE_LIMIT_H), angleToPosition (angle));
318
+ writeByteCmd (id, REG (SmartServoRegister::MAX_ANGLE_LIMIT_H), angleToPosition (angle));
319
319
mutex.unlock ();
320
320
}
321
321
0 commit comments