@@ -179,10 +179,22 @@ export default class RICSystem {
179
179
async calibrate (
180
180
cmd : string ,
181
181
jointList : Array < string > ,
182
- jointNames : { [ key : string ] : string }
182
+ jointNames : { [ key : string ] : string } ,
183
+ servoControllers : { [ key : string ] : string } = {
184
+ "LeftHip" : "LeftHip" ,
185
+ "LeftTwist" : "LeftHip" ,
186
+ "LeftKnee" : "LeftHip" ,
187
+ "RightHip" : "RightHip" ,
188
+ "RightTwist" : "RightHip" ,
189
+ "RightKnee" : "RightHip" ,
190
+ "LeftArm" : "LeftArm" ,
191
+ "RightArm" : "LeftArm" ,
192
+ "Eyes" : "LeftArm"
193
+ }
183
194
) {
184
195
let overallResult = true ;
185
196
if ( cmd === "set" ) {
197
+ const controllerArray : Array < string > = [ ] ;
186
198
// Set calibration
187
199
for ( const jnt of jointList ) {
188
200
try {
@@ -194,8 +206,10 @@ export default class RICSystem {
194
206
// saving the calibration... (For the new servo boards it is necessary
195
207
// to send a "save" command after the calibration ones or any servo
196
208
// parameter changes in order to save any changes made into nonvolatile storage)
197
- const saveCalibCmd = `elem/${ jnt } /saveparams` ;
198
- await this . _ricMsgHandler . sendRICRESTURL < RICOKFail > ( saveCalibCmd ) ;
209
+ // log it now, and we'll do the saveparams commands once we've updated all the joints
210
+ // the saveparams function is not instant as the flash write takes a few ms
211
+ if ( jnt in servoControllers && ! controllerArray . includes ( servoControllers [ jnt ] ) )
212
+ controllerArray . push ( servoControllers [ jnt ] )
199
213
if ( rsl . rslt != "ok" ) overallResult = false ;
200
214
} catch ( error ) {
201
215
console . log ( `calibrate failed on joint ${ jnt } ` , error ) ;
@@ -206,6 +220,14 @@ export default class RICSystem {
206
220
//await new Promise(resolve => setTimeout(resolve, 3000));
207
221
}
208
222
223
+ // on newer (batch4+) robots with stm32 servo controllers it is necessary to send a saveparams command once per servo controller
224
+ for ( const cID in controllerArray ) {
225
+ const saveCalibCmd = `elem/${ controllerArray [ cID ] } /saveparams` ;
226
+ const rslt = await this . _ricMsgHandler . sendRICRESTURL < RICOKFail > ( saveCalibCmd ) ;
227
+ if ( rslt . rslt != "ok" ) overallResult = false ;
228
+ await new Promise ( resolve => setTimeout ( resolve , 200 ) ) ;
229
+ }
230
+
209
231
// ensure all joints are enabled
210
232
for ( const jnt in jointNames ) {
211
233
try {
0 commit comments