helper module

The helper module provides functions for all other modules, mainly for the calibration-modules.

cyberglove.helper.aspps_from_abduction_postures(sp, cc_obj)

Gets aspps-dictionary from a static-abduction-postures-dictionary. Aspps means: “angle-sensor_value pairs per sensor”. Measurements are taken with 0° abduction always for Ibanez, so the angle is not explicitly part of the dictionary. It holds the sensor value at the corresponding joint and as abduction is also evaluated with cross-coupling effects, the sensor value of the two neighboring MCP-sensors are also contained in the dictionary. The function basically restructures and simplifies the static-postures dictionary to be used in a more convenient way.

Structure of aspps-obj, if argument cc is CROSSCOUPLING.MCP_2_3:

{

‘MCP_2_3’: { ‘np_array’: numpy.ndarray((n,3)) (1st col: sensor_values_left (int), 2nd col: sensor-values_middle (int), 3rd col: sensor-values_right (int))}

}

Parameters
  • sp ([str, dict]) – static_abduction_postures-dictionary

  • cc_obj (obj) – information about neighboring sensor indices

Returns

aspps-dictionary

Return type

dict

cyberglove.helper.aspps_from_static_postures(sp, sensors)

Gets aspps-dictionary from a static-postures-dictionary. Aspps means: “angle-sensor_value pairs per sensor” and holds the pairs of an angle and the sensor value at the corresponding joint. The function basically restructures and simplifies the static-postures dictionary to be used in a more convenient way.

Structure of aspps-dictionary:

{

‘MCP2’: { ‘np_array’: numpy.ndarray((n,2)) (1st col: angles (float), 2nd col: sensor-values (int), n=amount of measurements)},

‘PIP2’: { ‘np_array… }, …

}

Parameters
  • sp ([str, dict]) – static_postures-dictionary

  • sensors (bidict.bidict) – bidict where sensor names and indices are defined

Returns

aspps-dictionary

Return type

dict

cyberglove.helper.aspps_from_static_postures_thumb(sp)

Gets aspps-dictionary from a static-postures-dictionary. Aspps means: angle-sensor_value pairs per sensor and holds the pairs of an angle and the sensor value at the corresponding joint. Additionally, for cross-coupling, the sensor value of the corresponding sensor is also contained in the dictionary (CMC1_A for CMC1_F and vice versa) (Ibanez only). The function basically restructures and simplifies the static-postures dictionary to be used in a more convenient way.

Structure of aspps-dictionary:

{

‘CMC1_A’: {‘np_array’: numpy.ndarray((22,3)) (1st col: angles (float), 2nd col: sensor-values_idx_0 (int), 3rd col: sensor-values_idx_3 (int))},

‘CMC1_F’: { ‘np_array… }

}

Parameters

sp ([str, dict]) – static_postures-dictionary

Returns

aspps-dictionary

Return type

dict

cyberglove.helper.capture(glove, callback, duration=None, input_str='', timestamp=False)

Repeatedly calls glove.get_one_dataset() for the duration if it is set or until the user stops the action again with an input. For each dataset, the callback-function is executed (callback must accept parameter ‘**kwargs’).

Parameters
  • glove (cyberglove.glove.Glove) – connected glove-object

  • callback (fun) – callback function that is executed for each received dataset (passed as kwargs-parameter dataset)

  • duration (float, optional) – duration how long to capture data (defaults to None, then asks the user to start/stop, otherwise starts immediately)

  • input_str (str, optional) – text to be added before default input-instruction

  • timestamp (bool, optional) – if set, callback will be called with a second keyword-argument timestamp

Returns

status, True if function was executed successfully, False if user typed in “exit”

Return type

bool

cyberglove.helper.cg_exit(msg='an error occurred', status=1)

Writes error-message to stderr and exits the program with the given status. :param msg: error message to print to the command line (stderr) :type msg: str, optional :param status: exit-status to exit the program with :type status: int, optional

Returns

None

cyberglove.helper.frmt(arr)

Formats an array of angle values to a nice string with same-width columns.

Parameters

numpy.ndarray – array of n float values

Returns

formatted string of n same-width columns with n values

Return type

str

cyberglove.helper.frmt_raw(arr)

Formats an array of raw sensor values to a nice string with same-width columns.

Parameters

numpy.ndarray – array of n positive int values (three digits maximum)

Returns

formatted string of n same-width columns with n values

Return type

str

cyberglove.helper.get_linear_relationship(sensor_value_1, sensor_value_2, angle_1, angle_2)

Calculates the gain for a sensor with a linear relationship between sensor value and angle. Returns the factor to calculate the angle from a sensor value.

Parameters
  • sensor_value_1 (int) – sensor value of the first measurement corresponding to angle_1

  • sensor_value_2 (int) – sensor value of the second measurement corresponding to angle_2

  • angle_1 (float) – angle of the first measurement

  • angle_2 (float) – angle of the second measurement

Returns

gain value

Return type

float

Raises

ZeroDivisionError – when sensor_values are identical

cyberglove.helper.get_linear_relationship_with_offset(sensor_value_1, sensor_value_2, angle_1, angle_2)

Calculates the gain and the offset for a sensor with a linear relationship between sensor value and angle. Returns the factor and offset to calculate the angle from a sensor value.

Parameters
  • sensor_value_1 (int) – sensor value of the first measurement corresponding to angle_1

  • sensor_value_2 (int) – sensor value of the second measurement corresponding to angle_2

  • angle_1 (float) – angle of the first measurement

  • angle_2 (float) – angle of the second measurement

Returns

(gain value, offset value)

Return type

(float, float)

Raises

ZeroDivisionError – when sensor_values are identical

cyberglove.helper.get_neutral_dataset_from_static_postures(sp)

Gets the neutral dataset from ‘static_postures’-dictionary.

Parameters

sp ([str, list]) – static_postures (for structure, see helper.read_static_postures())

Returns

numpy-array of 22 int values

Return type

numpy.ndarray

cyberglove.helper.get_now()

Gets a timestamp-string of current date and time.

Returns

iso-datetime-string (YYYY-mm-ddTHH-MM-SS)

Return type

str

cyberglove.helper.read_static_postures(filepath)

Reads a file into a static_postures-dictionary. Structure of this dictionary:

{ ‘CMC1_A’: [

{ ‘angle’: int, ‘dataset’: ndarray(22) },

{ ‘angle’: int, ‘dataset’: ndarray(22) },

],

‘MCP1’: […],

}

Parameters

filepath (str) – filepath to static_postures.txt-file

Returns

static_postures-dictionary

Return type

[str, list]

cyberglove.helper.read_static_postures_relative(filepath, neutral_dataset)

Reads file into static_postures-dict and subtracts the neutral_dataset to get relative sensor values. Structure of this dictionary:

{ ‘CMC1_A’: [

{ ‘angle’: int, ‘dataset’: ndarray(22) },

{ ‘angle’: int, ‘dataset’: ndarray(22) },

],

‘MCP1’: […],

}

Parameters
  • filepath (str) – filepath to static_postures.txt-file

  • neutral_dataset (numpy.ndarray) – neutral dataset as a dataset in numpy.ndarray(22)

Returns

static_postures-dictionary

Return type

[str, list]

cyberglove.helper.write_dataset_to_file(dataset, fd, pose='')

Appends one dataset of sensor values to an already opened file.

Parameters
  • dataset (numpy.ndarray) – 1D-numpy-array of int-values to be written to a new line in the file

  • fd (file) – already opened file-descriptor to write in

  • pose (str, optional) – short description for pose

Returns

None