jhu-dvrk / sawIntuitiveResearchKit

cisst/SAW stack for the da Vinci Research Kit (dVRK)
https://github.com/jhu-dvrk/sawIntuitiveResearchKit/wiki
117 stars 68 forks source link

Updated python-based config generator #145

Closed brendanburkhart closed 2 years ago

brendanburkhart commented 2 years ago

Replace existing Matlab GUI config generator with a console-only Python config generator. Supports both XML and JSON output. calParser.py is used to parse the Matlab .cal files, and dvrk-config-generator.py does the actual config generator. Can be invoked as ./dvrk-config-generator.py -a <arm-name> -c <cal-file> -f <JSON|XML>, for example, ./dvrk-config-generator.py -a MTML -c ./jhu-dVRK/cal-files/jhu-mtml-m22723.cal -f XML.

adeguet1 commented 2 years ago

I'd like to keep the MATLAB based config generator for at least one minor revision to avoid a rough transition for some users. Can you undo that commit? I should be able to test the config generator in the comming days.

brendanburkhart commented 2 years ago

Good idea, sorry about that.

adeguet1 commented 2 years ago

Sorry for the delay reviewing your PR. Config generation worked fine for MTM and PSM, very nice job overall.

adeguet1 commented 2 years ago

Thank you for the update. There is a few things you can probably fix on your own:

The following issues might be a bit harder to fix since we need to figure out where the numbers should be coming from:.

adeguet1 commented 2 years ago

I tried to generate a couple of config files for Si PSMs today and ran into some issues. I'm using Ubuntu 20.04, default Python 3 with the command line:

> pwd 
/home/adeguet1/catkin_ws/src/cisst-saw/sawIntuitiveResearchKit/applications/config-generator
> ./dvrk-config-generator.py -a PSM1 -g Si -c ../../share/jhu-dVRK-S/cal-files/jhu-psm-s-334809.cal

The first issue I ran into was related to pad and I applied the following patch (though not sure it's the way to proceed):

         # Zero-pad numeric arrays, None-pad object arrays
         numeric_array = isinstance(value, np.ndarray) and value.dtype != np.dtype(object)
         if numeric_array:
-            return np.pad(data, ((0, padRows), (0, padColumns)))
+           return np.pad(data, ((0, padRows), (0, padColumns)), mode='constant')
         else:
             data = data.astype(object)
-            return np.pad(data, ((0, padRows), (0, padColumns)), constant_values=None)
+           return np.pad(data, ((0, padRows), (0, padColumns)), constant_values=None, mode='constant')

With that "fix", I now get the following error/stack:

Traceback (most recent call last):
  File "./dvrk-config-generator.py", line 1060, in <module>
    generateConfig(args.cal, args.arm, args.generation, outputFormat)
  File "./dvrk-config-generator.py", line 1008, in generateConfig
    calData = parser.parseFile(calFileName)
  File "/home/adeguet1/catkin_ws/src/cisst-saw/sawIntuitiveResearchKit/applications/config-generator/calParser.py", line 386, in parseFile
    assignmentPath.assignTo(data, value)
  File "/home/adeguet1/catkin_ws/src/cisst-saw/sawIntuitiveResearchKit/applications/config-generator/calParser.py", line 187, in assignTo
    self.parent.assignTo(variables, data)
  File "/home/adeguet1/catkin_ws/src/cisst-saw/sawIntuitiveResearchKit/applications/config-generator/calParser.py", line 220, in assignTo
    data = self._padToFit(data, value)
  File "/home/adeguet1/catkin_ws/src/cisst-saw/sawIntuitiveResearchKit/applications/config-generator/calParser.py", line 263, in _padToFit
    return np.pad(data, ((0, padRows), (0, padColumns)), constant_values=None, mode='constant')
  File "/usr/lib/python3/dist-packages/numpy/lib/arraypad.py", line 1371, in pad
    newmat = _append_const(newmat, pad_after, after_val, axis)
  File "/usr/lib/python3/dist-packages/numpy/lib/arraypad.py", line 142, in _append_const
    (arr, (np.zeros(padshape) + val).astype(arr.dtype)), axis=axis)
TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'

Thoughts?

brendanburkhart commented 2 years ago

It looks like versions of NumPy older than v1.14 don't let you pad an array with None. I tested the fix with NumPy 1.13 and Python 3.6.9, let me know if it works for you.