@@ -164,20 +164,15 @@ void SmartServoClass::action(uint8_t const id)
164164 writeCmd (id, SmartServoOperation::ACTION);
165165}
166166
167- int SmartServoClass::begin ()
167+ void SmartServoClass::begin ()
168168{
169- if (_RS485) {
170- _txPacket.header [0 ] = 0xff ;
171- _txPacket.header [1 ] = 0xff ;
172- _RS485.begin (115200 , 0 , 90 );
173- _RS485.receive ();
174- writeByteCmd (BROADCAST, REG (SmartServoRegister::SERVO_MOTOR_MODE), 1 );
175- writeByteCmd (BROADCAST, REG (SmartServoRegister::TORQUE_SWITCH) ,1 );
176- _positionMode = PositionMode::IMMEDIATE;
177- return 0 ;
178- } else {
179- return -1 ;
180- }
169+ _txPacket.header [0 ] = 0xff ;
170+ _txPacket.header [1 ] = 0xff ;
171+ _RS485.begin (115200 , 0 , 90 );
172+ _RS485.receive ();
173+ writeByteCmd (BROADCAST, REG (SmartServoRegister::SERVO_MOTOR_MODE), 1 );
174+ writeByteCmd (BROADCAST, REG (SmartServoRegister::TORQUE_SWITCH) ,1 );
175+ _positionMode = PositionMode::IMMEDIATE;
181176}
182177
183178void SmartServoClass::setPosition (uint8_t const id, float const angle, uint16_t const speed)
@@ -188,8 +183,8 @@ void SmartServoClass::setPosition(uint8_t const id, float const angle, uint16_t
188183 mbed::ScopedLock<rtos::Mutex> lock (_mtx);
189184 if (isValidId (id))
190185 {
191- _targetPosition[id- 1 ] = angleToPosition (angle);
192- _targetSpeed[id- 1 ] = speed;
186+ _targetPosition[idToArrayIndex (id) ] = angleToPosition (angle);
187+ _targetSpeed[idToArrayIndex (id) ] = speed;
193188 if (_positionMode==PositionMode::IMMEDIATE) {
194189 writeWordCmd (id, REG (SmartServoRegister::TARGET_POSITION_H), angleToPosition (angle));
195190 }
0 commit comments