Skip to content

Commit 452ce65

Browse files
committed
Merge branch 'master' of https://github.com/robotical/ricjs
2 parents 45c391a + 67b95b6 commit 452ce65

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@robotical/ricjs",
3-
"version": "1.16.2",
3+
"version": "1.16.4",
44
"description": "Javascript/TS library for Robotical RIC",
55
"author": "Rob Dobson <rob@dobson.com>",
66
"repository": {

src/RICChannelWebSerial.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,17 @@ export default class RICChannelWebSerial implements RICChannel {
9292
this._port = port;
9393
}
9494
// Connect
95-
await this._port.open({ baudRate: 115200 });
95+
try {
96+
RICLog.info("opening port");
97+
await this._port.open({ baudRate: 115200 });
98+
} catch (err: any){
99+
if (err.name == "InvalidStateError"){
100+
RICLog.debug(`Opening port failed - already open ${err}`);
101+
} else {
102+
RICLog.error(`Opening port failed: ${err}`);
103+
throw err;
104+
}
105+
}
96106

97107
this._isConnected = true;
98108

src/RICSystem.ts

+25-3
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,22 @@ export default class RICSystem {
179179
async calibrate(
180180
cmd: string,
181181
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+
}
183194
) {
184195
let overallResult = true;
185196
if (cmd === "set") {
197+
const controllerArray: Array<string> = [];
186198
// Set calibration
187199
for (const jnt of jointList) {
188200
try {
@@ -194,8 +206,10 @@ export default class RICSystem {
194206
// saving the calibration... (For the new servo boards it is necessary
195207
// to send a "save" command after the calibration ones or any servo
196208
// 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])
199213
if (rsl.rslt != "ok") overallResult = false;
200214
} catch (error) {
201215
console.log(`calibrate failed on joint ${jnt}`, error);
@@ -206,6 +220,14 @@ export default class RICSystem {
206220
//await new Promise(resolve => setTimeout(resolve, 3000));
207221
}
208222

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+
209231
// ensure all joints are enabled
210232
for (const jnt in jointNames) {
211233
try {

0 commit comments

Comments
 (0)