Skip to content

Commit bbe1e17

Browse files
committed
fix: update YAML handling to support negative values and ensure float normalization
1 parent 2a0843d commit bbe1e17

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/api/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,9 @@ router.get('/nav-params', (req, res) => {
424424
fs.mkdirSync(dir, { recursive: true });
425425
}
426426

427-
fs.writeFileSync(profilePath, yaml.dump(defaultData));
427+
let defaultYaml = yaml.dump(defaultData, yamlOptions);
428+
defaultYaml = defaultYaml.replace(/(max_linear_velocity|max_angular_velocity): (-?\d+)$/gm, '$1: $2.0');
429+
fs.writeFileSync(profilePath, defaultYaml);
428430
console.log(`Created default ${profile} profile with linear=${defaultLinear}, angular=${defaultAngular}`);
429431

430432
return res.json({
@@ -810,9 +812,9 @@ const ROBOT_CONFIG_PARAM_KEYS = [
810812
'cursor_tolerance',
811813
];
812814

813-
/** js-yaml prints integer 0,2 as 0,2; ROS param files use x.0. Match indented lines, all supported keys. */
815+
/** js-yaml prints integer 0,2,-1 as 0,2,-1; ROS param files use x.0. Match indented lines, all supported keys, including negative values. */
814816
const ROBOT_CONFIG_INT_TO_FLOAT_RE = new RegExp(
815-
`^(\\s*)(${ROBOT_CONFIG_PARAM_KEYS.join('|')}): (\\d+)$`,
817+
`^(\\s*)(${ROBOT_CONFIG_PARAM_KEYS.join('|')}): (-?\\d+)$`,
816818
'gm',
817819
);
818820

src/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const API_SERVER_PORT = process.env.API_SERVER_PORT || 3001;
1414
// Data directory
1515
const dataDir = '/home/share/data';
1616

17-
// Match robot_config.yaml param lines: js-yaml may emit 0,2; normalize to 0.0,2.0 (see api/index.js)
17+
// Match robot_config.yaml param lines: js-yaml may emit 0,2,-1; normalize to 0.0,2.0,-1.0 (see api/index.js)
1818
const ROBOT_CONFIG_INT_TO_FLOAT_RE = new RegExp(
19-
'^(\\s*)(pantry_aggressiveness|pantry_sensitivity|pantry_rival_sigma|pantry_rival_distance_threshold|collection_aggressiveness|collection_sensitivity|collection_rival_sigma|collection_rival_distance_threshold|flip_distance_threshold|cursor_tolerance): (\\d+)$',
19+
'^(\\s*)(pantry_aggressiveness|pantry_sensitivity|pantry_rival_sigma|pantry_rival_distance_threshold|collection_aggressiveness|collection_sensitivity|collection_rival_sigma|collection_rival_distance_threshold|flip_distance_threshold|cursor_tolerance): (-?\\d+)$',
2020
'gm',
2121
);
2222

0 commit comments

Comments
 (0)