Using echo to write segmented values
-
Hi all, I've been working on a macro to try and write the results from the PID tuning process automatically to a file, so that you wouldn't be required to amend your config.g manually
In this, the one piece I can't figure out is how to write a segmented value
The results from the PID tune in my case were:
M307 H0 R2.009 K0.289:0.080 D4.65 E1.35 S1.00 B0 V23.9
This is the code I use to write the file:
echo >"0:/sys/config_PID_tune_E0.g" "M307 H0 R"^{heat.heaters[0].model.heatingRate}, "K"^{heat.heaters[0].model.coolingRate}, {heat.heaters[0].model.fanCoolingRate}, "D"^{heat.heaters[0].model.deadTime}, "E"^{heat.heaters[0].model.coolingExp} echo >>"0:/sys/config_PID_tune_E0.g" "M307 H0 B0 S1.0 V"^{heat.heaters[0].model.standardVoltage}
Due to the character limit, it had to be executed in 2 lines rather than one, as the full string is around 290 characters long. It can be made into one line using variables, but that's not an issue in my eyes.
With the K as written in the code snippet it results in the following config_PID_tune_E0.g
M307 H0 R2.009 K0.289 0.080 D4.7 E1.4
M307 H0 B0 S1.0 V23.9As you can see, there is a space between the two K values (it should be K0.289:0.080
The K value is the one I can't figure out. With the way the echo command works, it expects either a , or a } at the end of any variable, so I'm not able to write it like I would expect it to need to work:
"K"^{heat.heaters[0].model.coolingRate, heat.heaters[0].model.fanCoolingRate}
With that code, I get the following error:
Error: in file macro line 7 column 124: meta command: expected '}'Does anyone have insight on how to properly write the code?
-
@comediantf2 said in Using echo to write segmented values:
"K"^{heat.heaters[0].model.coolingRate}, {heat.heaters[0].model.fanCoolingRate}
Try:
"K"^{heat.heaters[0].model.coolingRate},":", {heat.heaters[0].model.fanCoolingRate}
There will be spaces around the ":" but I don't think that will matter.
Give it a try and let us know.
-
@alankilian Sadly it looks like the spaces matter.
The first M307 H0 was with the spaces (so K0.289 : 0.080), the second one without
-
@comediantf2 Don't use a comma, use the caret to concatenate the values:
"K"^{heat.heaters[0].model.coolingRate}^":"^{heat.heaters[0].model.fanCoolingRate}
-
-
Where did you find that in the documentation?
In GCode Meta Commands under Binary infix operators - there, the caret is the last entry in the table.
-
@infiniteloop That did the trick. Much appreciated for that insight.
Final code:
echo >"0:/sys/config_PID_tune_E0.g" "M307 H0 R"^{heat.heaters[0].model.heatingRate}, "K"^{heat.heaters[0].model.coolingRate}^":"^{heat.heaters[0].model.fanCoolingRate}, "D"^{heat.heaters[0].model.deadTime}, "E"^{heat.heaters[0].model.coolingExp} echo >>"0:/sys/config_PID_tune_E0.g" "M307 H0 B0 S1.0 V"^{heat.heaters[0].model.standardVoltage}
That macro resulted in this config_PID_tune_E0.g
M307 H0 R1.990 K0.292:0.075 D4.7 E1.4 M307 H0 B0 S1.0 V23.9
-
-