From 330b87949682e736a913c729d9946a5db0ca99e7 Mon Sep 17 00:00:00 2001 From: cfry Date: Thu, 7 Apr 2022 18:20:08 -0400 Subject: [PATCH] relesae defaults.make_in processing --- core/dexter_defaults.js | 171 ++++++++++++++++++++++++++++++---------- core/index.js | 4 +- doc/guide.html | 4 +- doc/known_issues.html | 1 + doc/ref_man.html | 3 +- doc/release_notes.html | 13 +++ package.json | 4 +- 7 files changed, 150 insertions(+), 50 deletions(-) diff --git a/core/dexter_defaults.js b/core/dexter_defaults.js index cf470be6..ee1776cd 100644 --- a/core/dexter_defaults.js +++ b/core/dexter_defaults.js @@ -198,6 +198,10 @@ Dexter.dexter0.defaults_get("J1BoundryHigh") // "666000" Dexter.dexter0.defaults_lines */ Dexter.prototype.defaults_get = function(key){ + if(!Array.isArray(this.defaults_lines)) { + warning("No content for defaults_lines yet so all calls to defaults_get will return undefined.") + return undefined + } if(key === "whole_file_string") { return this.defaults_lines.join("\n") } @@ -300,17 +304,35 @@ Dexter.dexter0.defaults_set("S, RebootServo, 3", "X; a brand new comment") Dexter.dexter0.defaults_set("S, RebootServo", "Y") Dexter.dexter0.defaults_set("S, J1BoundryHigh", "ZZ") +Dexter.dexter0.defaults_set("JointDH", "1, 245656, 324100, 260, 323413") //note: + //that first arg is really the Joint number, and semantically belongs in the key, + //but then we can't use the s param name for the key, so keep the joint number in the value. + + Dexter.dexter0.defaults_lines //sets low level defaults_lines, then updates high level defaults */ Dexter.prototype.defaults_set = function(key, value){ + if(!Array.isArray(this.defaults_lines)) { + this.defaults_lines = [] //not great but at least the below clauses will work + if((key !== "whole_file_string") && (key !== "lines")) { + warning("No content for defaults_lines yet so initializing it to the empty array.") + } + } + if(typeof(this.defaults) !== "object") { + if((key !== "whole_file_string") && (key !== "lines")) { + this.defaults_init_defaults() + warning("No content for defaults yet so initializing it to the empty object.") + } + } if(key === "whole_file_string") { if(Array.isArray(value)) { this.defaults_lines = value } else if (typeof(value) === "string") { this.defaults_set_lines_from_string(value) } this.defaults_lines_to_high_level() + return this.defaults } else if(key === "lines") { if(typeof(value) === "string") { this.defaults_set_lines_from_string(value) } @@ -320,9 +342,13 @@ Dexter.prototype.defaults_set = function(key, value){ else { dde_error("Dexter defaults.set passed 'lines' with a value that isn't an array: " + value) } this.defaults_lines_to_high_level() + return this.defaults } - //now value_str is a string, and value is either a number or an array else if (Number.isInteger(key)) { // -1 means we're making a new last element. + if(typeof(value) !== "string") { + dde_error("Dexter." + this + ".defaults_set called with key of an integer
" + + "so value should be a string but its not: " + value) + } if(key < 0) { key = this.defaults_lines.length + key} if(key >= this.defaults_lines.length) { dde_error("Dexter." + this.name + ".defaults_set passed key: " + key + @@ -336,8 +362,14 @@ Dexter.prototype.defaults_set = function(key, value){ let clean_line = this.defaults_clean_line(value) this.defaults_lines[key] = clean_line this.defaults_line_to_high_level(clean_line, key) //key is line number + return value } } + else if (key.length === 1) { + dde_error("Dexter." + this.name + ".defaults_set passed key: " + key + + "
which looks like an oplet, but you can't use oplets as keys with defaults_set." + + "
Consider Dexter." + this.name + ".defaults_insert() instead.") + } else { let value_str if(typeof(value) === "string") { @@ -346,18 +378,29 @@ Dexter.prototype.defaults_set = function(key, value){ value = JSON.parse(value) } catch(err) { - value_str = value //hope this is ok - warning("In Dexter." + this.name + ".defaults_set passed key of: " + key + - "
could not convert: " + value + " into a number or an array." + - "
This *might* be ok.") + if (value.includes(Dexter.defaults_arg_sep)) { + value = value.split(Dexter.defaults_arg_sep) + for(let i = 0; i < value.length; i++){ + let item = value[i] + let num = parseFloat(item) + if(Number.isNaN(num)) { + value = value_str //assume user wanted just a string. + break; + } + else { value[i] = num} + } + } } } - else if (typeof(value) === "number") { - value_str = "" + value - } - else if (Array.isArray(value)) { - value_str = value.join(Dexter.defaults_arg_sep) + else { + if (Array.isArray(value)) { + value_str = value.join(Dexter.defaults_arg_sep) + } + else { + value_str = "" + value + } } + //now value_str is a string, and value is a num, an array, or possibly a string let result = this.set_coloned_prop_value(key, value_str) if(result !== undefined) { this.defaults[key] = value @@ -370,20 +413,44 @@ Dexter.prototype.defaults_set = function(key, value){ return result } else { - if(key.length === 1) { - dde_error("Dexter." + this.name + ".defaults_set passed key: " + key + - " which is probably an oplet, and thus can't be 'set'. Use Dexter." + - this.name + ".defaults_insert() instead.") - } //we've got an S param - result = this.defaults_set_S(key, value_str) //sets the line in defaults_lines - if(result !== undefined) { - this.defaults[key] = value - return result + this.defaults_set_S(key, value_str) //sets the line in defaults_lines + if(Dexter.defaults_is_j_key(key)) { + let [high_key, joint_number] = Dexter.defaults_j_key_to_high_key(key) + let ins_arr = [] + ins_arr[Instruction.INSTRUCTION_TYPE] = "S" + //ins_arr.push(parsed_line.key) //arg0, the param name + ins_arr[Instruction.INSTRUCTION_ARG0] = key //low key + if(Array.isArray(value)) { + ins_arr = ins_arr.concat(value) + } + else { ins_arr[Instruction.INSTRUCTION_ARG1] = value} + let dde_ins_arr = Socket.instruction_array_arcseconds_to_degrees_maybe(ins_arr, this) + let val_arr = dde_ins_arr.slice(Instruction.INSTRUCTION_ARG1) + let new_high_val = val_arr[0] + this.defaults[high_key][joint_number - 1] = new_high_val + return new_high_val + } + else if (key === "JointDH"){ + let high_key = "dh_mat" + if(!Array.isArray(this.defaults.dh_mat)) { + this.defaults.dh_mat = [] + } + let high_val = this.defaults[high_key] //at the very least, will be an empty array + let joint_number = value[0] + let ins_arr = [] + ins_arr[Instruction.INSTRUCTION_TYPE] = "S" + //ins_arr.push(parsed_line.key) //arg0, the param name + ins_arr[Instruction.INSTRUCTION_ARG0] = key //low key + ins_arr = ins_arr.concat(value) + let dde_ins_arr = Socket.instruction_array_arcseconds_to_degrees_maybe(ins_arr, this) + let val_arr = dde_ins_arr.slice(Instruction.INSTRUCTION_ARG2) + this.defaults[high_key][joint_number - 1] = val_arr + return val_arr } else { - warning("Dexter." + this.name + ".defaults_set could not find key: " + key) - return undefined + this.defaults[key] = value + return value } } } @@ -529,9 +596,11 @@ Dexter.prototype.defaults_set_S = function(key, value_str){ //warning("Dexter." + this.name + ".defaults_set attempted to set key: " + key + // " but that key not found.") let new_line = "S" - if(!value_str.startsWith(Dexter.defaults_arg_sep)) { + if(!key.startsWith(Dexter.defaults_arg_sep)) { new_line += Dexter.defaults_arg_sep } + new_line += key + new_line += Dexter.defaults_arg_sep new_line += value_str if(!value_str.includes(";")){ new_line += ";" @@ -787,18 +856,19 @@ Dexter.prototype.defaults_line_to_high_level = function(line, line_number="unkno } else if (parsed_line.kind === "whole_line_comment") {} //ignore else if (parsed_line.kind === "S_param") { + let low_key = parsed_line.key let ins_arr = [] ins_arr[Instruction.INSTRUCTION_TYPE] = "S" //ins_arr.push(parsed_line.key) //arg0, the param name - ins_arr[Instruction.INSTRUCTION_ARG0] = parsed_line.key + ins_arr[Instruction.INSTRUCTION_ARG0] = low_key ins_arr = ins_arr.concat(parsed_line.value_array) let dde_ins_arr = Socket.instruction_array_arcseconds_to_degrees_maybe(ins_arr, this) - let val_arr = dde_ins_arr.slice(Instruction.INSTRUCTION_ARG1) + let val_arr = dde_ins_arr.slice(Instruction.INSTRUCTION_ARG1) //the high_val array parsed_line.high_value_array = val_arr - if(low_key === "JointDH"){ //don't use high_value_array here. There's no arcseconds_to_degrees conversion. + if(low_key === "JointDH"){ let joint_number = parsed_line.value_array[0] //the low value_array if(!this.defaults.dh_mat) { this.defaults.dh_mat = [] } - let four_val_array = parsed_line.value_array.slice(1) + let four_val_array = val_arr.slice(1) //take off the joint_number on the beginning of the array this.defaults.dh_mat[joint_number - 1] = four_val_array } else if (low_key === "LinkLengths") { //array of 5, but needs to be reversed @@ -894,6 +964,8 @@ Dexter.defaults_j_key_suffixes = ["Force", "Friction", "BoundryHigh", "BoundryLo //if null is returned, key is not a j_key //Dexter.defaults_j_key_to_high_key("J1Force") //Dexter.defaults_j_key_to_high_key("J2_PID_P") +//J keys are above with suffixes of Dexter.defaults_j_key_suffixes . + Dexter.defaults_is_j_key = function(key){ if(key.startsWith("J")) { for(let suffix of Dexter.defaults_j_key_suffixes) { @@ -992,7 +1064,7 @@ Dexter.prototype.defaults_high_level_to_defaults_lines = function(){ if (low_key === "LinkLengths") { //array of 5, but needs to be reversed let high_key = low_key if(this.defaults.hasOwnProperty(high_key)) { //user didn't delete it - ins_arr[Instruction.INSTRUCTION_ARG0] = high_key + ins_arr[Instruction.INSTRUCTION_ARG0] = low_key let high_val = this.defaults[high_key].slice() //copy high_val.reverse() //copies in place ins_arr = ins_arr.concat(high_val) @@ -1006,15 +1078,21 @@ Dexter.prototype.defaults_high_level_to_defaults_lines = function(){ delete this.defaults[high_key] } } - else if(low_key === "JointDH"){ //no units conversion + else if(low_key === "JointDH"){ if(this.defaults.hasOwnProperty("dh_mat")) { //user didn't delete it let high_val = this.defaults.dh_mat let joint_number = parsed_line.value_array[0] - let high_val_joint_arr = high_val[joint_number - 1] let low_key = "JointDH" + ins_arr[Instruction.INSTRUCTION_ARG0] = low_key + ins_arr[Instruction.INSTRUCTION_ARG1] = joint_number + let high_val_for_one_joint = high_val[joint_number - 1] + ins_arr = ins_arr.concat(high_val_for_one_joint) + let dde_ins_arr = Socket.instruction_array_degrees_to_arcseconds_maybe(ins_arr, this) + let low_val_four_numbers = dde_ins_arr.slice(Instruction.INSTRUCTION_ARG2) //now in dexter units + let new_line = "S" + Dexter.defaults_arg_sep + low_key + Dexter.defaults_arg_sep + joint_number + Dexter.defaults_arg_sep + - high_val_joint_arr.join(Dexter.defaults_arg_sep) + + low_val_four_numbers.join(Dexter.defaults_arg_sep) + ";" + parsed_line.comment result_lines.push(new_line) delete high_val[joint_number - 1] @@ -1138,7 +1216,7 @@ Dexter.prototype.defaults_high_level_to_defaults_lines = function(){ this.defaults_lines = result_lines //update the low level //so recreate it in case uses wants to use it after "writing it out". Dexter.dexter0.defaults_lines_to_high_level() //fill in high level since the above deletes it all. - return result_lines + return this.defaults_lines } //At least for now, key can be either a high_key or a low_key (ie suffix of "s" or not, start with J-digit or not) @@ -1247,7 +1325,7 @@ Dexter.defaults_writeable_value = function(val){ } //loop thru remaining high level (after deleted the matching lines from low level) -//and write it out to low level +//and return an array of new lines Dexter.prototype.defaults_high_level_to_defaults_lines_new_high_level = function(){ let result_lines = [] for(let high_key of Object.keys(this.defaults)){ @@ -1259,7 +1337,6 @@ Dexter.prototype.defaults_high_level_to_defaults_lines_new_high_level = function high_val.reverse() //copies in place, but ok since we delete it below let ins_arr = [] ins_arr[Instruction.INSTRUCTION_TYPE] = "S" - //ins_arr.push(parsed_line.key) //arg0, the param name ins_arr[Instruction.INSTRUCTION_ARG0] = low_key ins_arr = ins_arr.concat(high_val) let dde_ins_arr = Socket.instruction_array_degrees_to_arcseconds_maybe(ins_arr, this) @@ -1267,22 +1344,30 @@ Dexter.prototype.defaults_high_level_to_defaults_lines_new_high_level = function let new_line = "S" + Dexter.defaults_arg_sep + low_key + Dexter.defaults_arg_sep + val_arr.join(Dexter.defaults_arg_sep) + - ";" + parsed_line.comment + ";" result_lines.push(new_line) delete this.defaults[high_key] } } else if(high_key === "dh_mat"){ - if(Dexter.defaults_writeable_value(high_val)) { //no units conversion - let joint_number = parsed_line.value_array[0] - let high_val_joint_arr = high_val[joint_number - 1] + for (let i = 0; i < high_val.length; i++) { + let joint_number = i + 1 + let high_val_joint_arr = high_val[i] let low_key = "JointDH" - let new_line = "S" + Dexter.defaults_arg_sep + low_key + Dexter.defaults_arg_sep + - joint_number + Dexter.defaults_arg_sep + - high_val_joint_arr.join(Dexter.defaults_arg_sep) + - ";" + parsed_line.comment + let ins_arr = [] + ins_arr[Instruction.INSTRUCTION_TYPE] = "S" + ins_arr[Instruction.INSTRUCTION_ARG0] = low_key + ins_arr[Instruction.INSTRUCTION_ARG1] = joint_number + ins_arr = ins_arr.concat(high_val_joint_arr) + let dde_ins_arr = Socket.instruction_array_degrees_to_arcseconds_maybe(ins_arr, this) + let low_val_arr = dde_ins_arr.slice(Instruction.INSTRUCTION_ARG2) + + let new_line = "S" + Dexter.defaults_arg_sep + low_key + Dexter.defaults_arg_sep + + joint_number + Dexter.defaults_arg_sep + + low_val_arr.join(Dexter.defaults_arg_sep) + + ";" result_lines.push(new_line) - delete high_val[joint_number - 1] + delete high_val[i] } } else if (high_key === "ServoSetup"){ //rebootServo and oplets under this. //no units conversion @@ -1389,7 +1474,7 @@ Dexter.dexter0.defaults.LinkLengths[0] = 0.2 Dexter.dexter0.defaults_high_level_to_defaults_lines() -// Dexter.dexter0.defaults.write() //warning: not ready for prime time. make a backup first. +// Dexter.dexter0.defaults_write() //warning: not ready for prime time. make a backup first. */ diff --git a/core/index.js b/core/index.js index e77c8d4d..40fb502a 100644 --- a/core/index.js +++ b/core/index.js @@ -1,5 +1,5 @@ -global.dde_version = "3.8.2" //require("../package.json").version -global.dde_release_date = "Apr 5, 2022" //require("../package.json").release_date +global.dde_version = "3.8.3" //require("../package.json").version +global.dde_release_date = "Apr 7, 2022" //require("../package.json").release_date console.log("dde_version: " + global.dde_version + " dde_release_date: " + global.dde_release_date + "\nRead electron_dde/core/job_engine_doc.txt for how to use the Job Engine.\n") diff --git a/doc/guide.html b/doc/guide.html index e1d8efc3..5906b93e 100644 --- a/doc/guide.html +++ b/doc/guide.html @@ -8,8 +8,8 @@
About This is Dexter Development Environment
- version: 3.8.2
- released: Apr 5, 2022 + version: 3.8.3
+ released: Apr 7, 2022

DDE helps you create, debug, and send software to a Dexter robot. You can use any JavaScript augmented with DDE-specific functions to help find out about, diff --git a/doc/known_issues.html b/doc/known_issues.html index 611e53f9..2483cb26 100644 --- a/doc/known_issues.html +++ b/doc/known_issues.html @@ -10,6 +10,7 @@ with this DDE release. All of them are on our "do list".

defaults_insert diff --git a/doc/release_notes.html b/doc/release_notes.html index 9f464153..6d4f4ff0 100644 --- a/doc/release_notes.html +++ b/doc/release_notes.html @@ -5,6 +5,19 @@ } .doc_details summary { font-weight: 600; } +
v 3.8.3, Apr 7, 2022 +Highlights: Bug fixes for Defaults.make_ins file processing. +
    +
  • Defaults.makeins processing: fixed bug in defaults_set("J1Boundry" ...) and friends.
  • +
  • Defaults.makeins processing: fixed bug in Dexter.dexter0.defaults_high_level_to_defaults_lines + related to dh_mat processing.
  • +
  • Defaults.makeins processing: now JointDH and dh_mat are doing proper units conversion. (instead of none)
  • +
  • Defaults.makeins processing: defaults_set working better.
  • +
  • Defaults.makeins processing: defaults_set now returns the new value for all cases.
  • +
  • Defaults.makeins processing: minor improvements to ref man doc examples
  • +
+
+
v 3.8.2, Apr 5, 2022 Highlights: New Defaults.make_ins file processing.
    diff --git a/package.json b/package.json index 8766f069..b9f98245 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "dexter_dev_env", "productName": "dexter_dev_env", - "version": "3.8.2", - "release_date": "Apr 5 2022", + "version": "3.8.3", + "release_date": "Apr 7 2022", "description": "Dexter Development Environment for programming the Dexter robot.", "author": "Fry", "license": "GPL-3.0",