opsoro.dof

class opsoro.dof.DOF(name, neutral=0.0, poly=None)[source]

Bases: object

__init__(name, neutral=0.0, poly=None)[source]

DOF class.

Parameters:
  • name (string) – name of the DOF.
  • neutral (float) – neutral dof position.
  • poly (list) – 20 dof values linked to emotions.
calc(r, phi, anim_time=-1)[source]

Calculate dof value with the polygon, according to the given r and phi.

Parameters:
  • r (float) – radius r, intensity of the emotion.
  • phi (float) – (radians) angle of the emotion in the circumplex.
  • anim_time (float) – time for the servo to move from previous dof to the new dof (-1: animation will be based on dof differences).
config(**args)[source]
reset_overlay(anim_time=-1)[source]

Clears the overlay value and resets the dof position to the last set value.

Parameters:anim_time (float) – time for the servo to move from previous dof to the new dof (-1: animation will be based on dof differences).
set_control_polygon(neutral=0.0, poly=None)[source]

Sets the control polygon, 20 dof values are linked to certain emotions.

Parameters:
  • neutral (float) – neutral dof position.
  • poly (list) – 20 dof values linked to emotions.
set_overlay_value(dof_value=0, anim_time=-1, update_last_set_time=True)[source]

Sets the overlay value and overwrites the dof position.

Parameters:
  • dof_value (float) – new overlay value of the dof.
  • anim_time (float) – time for the servo to move from previous dof to the new dof (-1: animation will be based on dof differences).
  • update_last_set_time (bool) – update the last set timer of the dof.
set_value(dof_value=0, anim_time=-1, is_overlay=False, update_last_set_time=True)[source]

Sets the dof value. If the dof value is 2 or larger, set it to a random value.

Parameters:
  • dof_value (float) – new value of the dof.
  • anim_time (float) – time for the servo to move from previous dof to the new dof (-1: animation will be based on dof differences).
  • is_overlay (bool) – used to determine what priority the dof value has (overlay > default).
  • update_last_set_time (bool) – update the last set timer of the dof.
update()[source]

Updates the dof value according to the animation.

Returns:True if dof value is updated, False if dof value did not change.
Return type:bool
opsoro.dof.constrain(n, minn, maxn)[source]

opsoro.dof.servo

class opsoro.dof.servo.Servo(name, neutral=0.0, poly=None)[source]

Bases: opsoro.dof.DOF

config(pin=None, min_range=0, mid_pos=1500, max_range=0)[source]

Helper class to turn DOF positions into pulse widths for the servo controller.

Parameters:
  • pin (int) – Servo pin number
  • min_range (int) – Minimum range of the servo, can be positive or negative. When dof_pos < 0, pulse width = mid_pos + dof_pos*min_range
  • mid_pos (int) – Pulse width when neutral (DOF position = 0).
  • max_range (int) – Maximum range of the servo, can be positive or negative. When dof_pos > 0, pulse width = mid_pos + dof_pos*max_range
to_us(dof_value=None)[source]

Converts DOF pos to microseconds.

Parameters:dof_value (float) – value to convert to us. If None; dof value of servo object is used
Returns:servo value (us)
Return type:int
update()[source]

Updates the servo with the setted dof value.

Returns:True if dof value is updated, False if dof value did not change
Return type:bool
opsoro.dof.servo.constrain(n, minn, maxn)[source]