Commit 07d43d35 authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

examples: update some cs through ugly xml manipulation

parent a557abe2
Pipeline #17359 failed with stage
in 6 minutes and 41 seconds
No preview for this file type
#!/usr/bin/env python
convert objects xml-exported with pinocchio < 2.6.0
into objects xml-importables with pinocchio >= 2.6.0
then import that from multicontact-api
and re-export as binary
from pathlib import Path
import multicontact_api
DEL_ROWS = DEL_BOTH + ['contact_points_positions']
def update_xml(f: Path) -> Path:
prev = ""
updated = f.parent / f"updated_{}"
with as f_in,"w") as f_out:
for line in f_in:
if line.strip().startswith("<rows>"):
if prev in DEL_ROWS:
elif line.strip().startswith("<cols>"):
if prev in DEL_COLS:
if strip := line.strip(" \t\n<>"):
prev = strip.split()[0]
print(line, end="", file=f_out)
return updated
def xml_to_bin(f: Path) -> Path:
updated = f.parent / f"{f.stem}.cs"
cs = multicontact_api.ContactSequence()
cs.loadFromXML(str(f), "nimp")
return updated
if __name__ == '__main__':
for f in Path().glob("*.xml"):
print(f"updtaing {f}...")
new_xml = update_xml(f)
new_bin = xml_to_bin(new_xml)
print(f"{f} updated into {new_bin}")
except RuntimeError as e:
print(f"ERROR on {f}: {e}")
No preview for this file type
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment