Welcome to OPSORO’s documentation!¶
Development¶
Commenting¶
"""
Explanation about the function.
:param bool A: bool input parameter
:param int B: int input parameter
:return: what is the function returning?
:rtype: return type
"""
OPSORO OS¶
Modules¶
Internal Modules¶
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).
-
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.
-
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
-
opsoro.hardware¶
This module defines the interface for communicating with the shield.
opsoro.hardware.analog¶
opsoro.hardware.capacitive¶
-
class
opsoro.hardware.capacitive.
Capacitive
[source]¶ Bases:
object
-
get_baseline_data
()[source]¶ Get list of electrode baseline data. Result is 10 bits, but the 2 least significant bits are set to 0.
Returns: electrode baseline data (10 bits). Return type: list
-
get_filtered_data
()[source]¶ Get list of electrode filtered data (10 bits per electrode).
Returns: electrode filtered data (10 bits per electrode). Return type: list
-
get_touched
()[source]¶ Returns the values of the touch registers, each bit corresponds to one electrode.
Returns: values of the touch registers, Return type: list
-
init
(electrodes, gpios=0, autoconfig=True)[source]¶ Initialize the MPR121 capacitive touch sensor.
Parameters: - electrodes (int) – amount of electrodes
- gpios (int) – amount of gpios
- autoconfig (bool) –
-
read_gpio
()[source]¶ Returns the status of all GPIO channels, each bit corresponds to one gpio channel.
Returns: status of all GPIO channels. Return type: list
-
set_gpio_pinmode
(gpio, pinmode)[source]¶ Sets a GPIO channel’s pin mode.
Parameters: - gpio (int) – gpio channel
- pinmode (int) – pinmode to set
-
opsoro.hardware.dummy_spidev¶
opsoro.hardware.i2c¶
-
class
opsoro.hardware.i2c.
I2C
[source]¶ Bases:
object
-
detect
(addr)[source]¶ Returns True if an I2C device is found at a particular address.
Parameters: addr (int) – address of the I2C device. Returns: I2C device detected Return type: bool
-
read16
(addr, reg)[source]¶ Read 2 bytes from an I2C device.
Parameters: - addr (int) – address of the I2C device.
- reg (int) – register address in the I2C device
Returns: 2 Bytes
Return type: var
-
read8
(addr, reg)[source]¶ Read a Byte from an I2C device.
Parameters: - addr (int) – address of the I2C device.
- reg (int) – register address in the I2C device
Returns: what is the function returning?
Return type: var
-
opsoro.hardware.neopixel¶
-
class
opsoro.hardware.neopixel.
Neopixel
[source]¶ Bases:
object
-
disable
()[source]¶ Turns off the NeoPixel MOSFET, disabling the NeoPixels. Data is lost when pixels are disabled.
-
enable
()[source]¶ Turns on the NeoPixel MOSFET, enabling the NeoPixels. Data is lost when pixels are disabled, so call show() again afterwards.
-
init
(num_leds)[source]¶ Initialize the NeoPixel library.
Parameters: num_leds (int) – number of neopixel leds.
-
set_all
(r, g, b)[source]¶ Set the color of the entire strip.
Parameters: - r (int) – red color value (0-255)
- g (int) – green color value (0-255)
- b (int) – blue color value (0-255)
-
set_all_hsv
(h, s, v)[source]¶ Set the HSV color of the entire strip.
Parameters: - h (int) – hue color value (0-255)
- s (int) – saturation color value (0-255)
- v (int) – value color value (0-255)
-
set_brightness
(brightness)[source]¶ Set the NeoPixel’s global brightness, 0-255.
Parameters: brightness (int) – brightness to set (0-255)
-
set_pixel
(pixel, r, g, b)[source]¶ Set the color of a single pixel.
Parameters: - pixel (int) – pixel index
- r (int) – red color value (0-255)
- g (int) – green color value (0-255)
- b (int) – blue color value (0-255)
-
set_pixel_hsv
(pixel, h, s, v)[source]¶ Set the HSV color of a single pixel.
Parameters: - pixel (int) – pixel index
- h (int) – hue color value (0-255)
- s (int) – saturation color value (0-255)
- v (int) – value color value (0-255)
-
set_range
(start, end, r, g, b)[source]¶ Set the color of a range of pixels.
Parameters: - start (int) – start index of led range
- end (int) – end index of led range
- r (int) – red color value (0-255)
- g (int) – green color value (0-255)
- b (int) – blue color value (0-255)
-
opsoro.hardware.servo¶
-
class
opsoro.hardware.servo.
Servo
[source]¶ Bases:
object
-
set
(channel, pos)[source]¶ Set the position of one servo. Pos in us, 500 to 2500
Parameters: - channel (int) – channel of the servo
- pos (int) – position of the servo (500 to 2500)
-
opsoro.hardware.spi¶
This module defines the interface for communicating with SPI.
-
class
opsoro.hardware.spi.
_SPI
[source]¶ Bases:
object
-
command
(cmd, params=None, returned=0, delay=0)[source]¶ - Send a command over the SPI bus to the ATmega328. Optionally reads the result buffer and returns those Bytes.
Parameters: - cmd (string) – spi command
- params (strin) – parameters for the command
- returned (int) – size of result reading
- delay (int) – delay between sending the command and reading the result
Returns: result buffer (Bytes)
Return type: list
-
opsoro.hardware.usb_serial¶
-
opsoro.hardware.
usb_serial
¶ alias of
opsoro.hardware.usb_serial
opsoro.module¶
-
class
opsoro.module.
Module
(data=None)[source]¶ Bases:
object
-
__init__
(data=None)[source]¶ Module default class. Custom modules should inherit this class and can override functions.
Parameters: data (dict) – configuration data to setup the module
-
alive_trigger
(count_seed=1)[source]¶ This is triggered frequently, when the aliveness is turned on.
Parameters: count_seed (float) – seed value for randomization Returns: True if the module updated something Return type: bool
-
apply_poly
(r, phi, anim_time=-1)[source]¶ Apply poly values r and phi to the module and calculate dof values
Parameters: - r (float) – r radius value
- phi (float) – phi angle value
- anim_time (int) – animation time in ms
-
load_module
(data)[source]¶ Setup modules with given configuration data
Parameters: data (dict) – configuration data to setup the module
-
set_dof
(tags=[], value=0, anim_time=-1)[source]¶ Set the value of a dof with the given tags. If no tags are provided, all dofs are set with the given value.
Parameters: - tags (list) – name of the DOF
- value (float) – value to set the DOF
- anim_time (int) – animation time in ms
-
opsoro.module.eye¶
-
class
opsoro.module.eye.
Eye
(data=None)[source]¶ Bases:
opsoro.module.Module
-
__init__
(data=None)[source]¶ Eye module class inherits default module class.
Parameters: data (dict) – configuration data to setup the module
-
alive_trigger
(count_seed)[source]¶ This is triggered frequently, when the aliveness is turned on.
Parameters: count_seed (float) – seed value for randomization Returns: True if the module updated something Return type: bool
-
opsoro.module.eyebrow¶
-
class
opsoro.module.eyebrow.
Eyebrow
(data=None)[source]¶ Bases:
opsoro.module.Module
opsoro.module.mouth¶
-
class
opsoro.module.mouth.
Mouth
(data=None)[source]¶ Bases:
opsoro.module.Module
opsoro.module.turn¶
-
class
opsoro.module.turn.
Turn
(data=None)[source]¶ Bases:
opsoro.module.Module
opsoro.preferences¶
This module defines the interface for communicating with the settings of the robot.
-
class
opsoro.preferences.
_Preferences
[source]¶ Bases:
object
-
apply_prefs
(update_audio=False, update_wireless=False, restart_wireless=False, update_dns=False)[source]¶ Apply preferences to the system.
Parameters: - update_audio (bool) – True if audio settings have changed and needs to update.
- update_wireless (bool) – True if wireless settings have changed and the wireless interface needs to update.
- restart_wireless (bool) – True if wireless settings have changed and the wireless interface needs to restart.
- update_dns (bool) – True if DNS settings have changed and needs to update.
-
-
opsoro.preferences.
constrain
(n, minn, maxn)¶
opsoro.server¶
This module defines the interface for the Server.
opsoro.server.request_handlers¶
This module defines the interface for the request handling.
-
class
opsoro.server.request_handlers.
RHandler
(server)[source] Bases:
object
-
__init__
(server)[source]
-
inject_opsoro_vars
()[source]
-
page_blockly
()[source]
-
page_closeapp
(appname)[source]
-
page_file_list
()[source]
-
page_index
()[source]
-
page_login
()[source]
-
page_logout
()[source]
-
page_openapp
(appname)[source]
-
page_restart
()[source]
-
page_shutdown
()[source]
-
page_sockjstoken
()[source]
-
page_virtual
()[source]
-
render_template
(template, **kwargs)[source]
-
set_urls
()[source]
-
show_errormessage
(error)[source]
-
sound_data
()[source]
-
opsoro.server.request_handlers.opsoro_data_requests¶
opsoro.sound¶
This module defines the interface for communicating with the sound module.
-
class
opsoro.sound.
_Sound
[source]¶ Bases:
object
-
get_file
(filename, tts=False)[source]¶ Returns audio file data according to the given filename.
Parameters: filename (string) – file to return the data from Returns: Soundfile data. Return type: var
-
play_file
(filename)[source]¶ Plays an audio file according to the given filename.
Parameters: filename (string) – file to play Returns: True if sound is playing. Return type: bool
-
opsoro.sound.tts¶
This module defines the interface for communicating with the TTS libraries.
-
class
opsoro.sound.tts.
_TTS
[source]¶ Bases:
object
-
create
(text)[source]¶ Takes a string of text, converts it using the PicoTTS engine, and plays it. Wave files are buffered in /tmp/OnoTTS/<text>.wav. First call blocks while PicoTTS generates the .wav, this may take about a second. Subsequent calls of the same text return immediately. If you wish to avoid this, sound files can be generated on beforehand by using generate_only=True.
Parameters: text (string) – text to convert to speech Returns: path to the sound file Return type: string
-
create_espeak
(text, file_path, language, gender, delay, speed)[source]¶ Convert text to speech using the espeak TTS library.
Parameters: - text (string) – text to convert to speech
- file_path (string) – file path to store the speech soundfile
- language (string) – language initials
- gender (string) – specify gender (m for male, f for female)
- delay (int) – delay between words in ms
- speed (int) – speed in words-per-minute
-
opsoro.animate¶
This module defines the interface for animating an expression.
-
class
opsoro.animate.
Animate
(times, values)[source]¶ Bases:
object
-
__init__
(times, values)[source]¶ Class to facilitate the tweening of values in time. The animation starts when the object is created. Once ended, the call method will return the last item in values.
Parameters: - times (list) – A list of timestamps in seconds, in increasing order. Timestamp 0 is the moment the Animate object was created.
- values (list) – A list of numerical values associated with timestamps. First element should be 0.
-
-
class
opsoro.animate.
Animate
(times, values)[source] Bases:
object
-
__init__
(times, values)[source] Class to facilitate the tweening of values in time. The animation starts when the object is created. Once ended, the call method will return the last item in values.
Parameters: - times (list) – A list of timestamps in seconds, in increasing order. Timestamp 0 is the moment the Animate object was created.
- values (list) – A list of numerical values associated with timestamps. First element should be 0.
-
has_ended
()[source] Returns true if the animation has ended.
-
-
class
opsoro.animate.
AnimatePeriodic
(times, values)[source]¶ Bases:
object
-
__init__
(times, values)[source]¶ Class to facilitate the tweening of values in time. The animation starts when the object is created. This class is a variant of the Animate class that does not end, but instead repeats its pattern indefinitely.
Parameters: - times (list) – A list of timestamps in seconds, in increasing order. Timestamp 0 is the moment the Animate object was created.
- values (list) – A list of numerical values associated with timestamps. First element should be 0.
-
opsoro.console_msg¶
opsoro.expression¶
This module defines the interface for communicating with the expression.
-
class
opsoro.expression.
_Expression
[source]¶ Bases:
object
-
get_emotion_complex
()[source]¶ Returns current emotion as a complex number
Returns: current emotion Return type: complex
-
load_config
(file_name='robot_expressions.conf')[source]¶ Load expressions from a expressions configurations file
Parameters: file_name (string) – name of the config file Returns: True if file is successfully loaded Return type: bool
-
save_config
(file_name='robot_expressions.conf')[source]¶ Save the current expressions configurations
Parameters: file_name (string) – name of the config file Returns: True if file is successfully saved Return type: bool
-
set_emotion_e
(e=0j, anim_time=-1)[source]¶ Set an emotion with complex number e, within a certain time.
Parameters: - e (complex) – complex number e
- anim_time (float) – time to set the emotion
-
set_emotion_icon
(icon, anim_time=-1)[source]¶ Set an emotion with icon if defined in expression list, within a certain time.
Parameters: - icon (string) – name of the icon to set
- anim_time (float) – time to set the emotion
-
set_emotion_index
(index, anim_time=-1)[source]¶ Set an emotion with index in defined expression list, within a certain time.
Parameters: - index (integer) – index of the emotion in the list of emotions
- anim_time (float) – time to set the emotion
-
set_emotion_name
(name, anim_time=-1)[source]¶ Set an emotion with name if defined in expression list, within a certain time.
Parameters: - name (string) – name of the emotion to set
- anim_time (float) – time to set the emotion
-
set_emotion_r_phi
(r, phi, degrees=False, anim_time=-1)[source]¶ Set an emotion with r and phi, within a certain time.
Parameters: - r (float) – radius of the circumplex
- phi (float) – angle of the circumplex
- degrees (bool) – is convertion to radians needed?
- anim_time (float) – time to set the emotion
-
set_emotion_random
(all_random=True, anim_time=-1)[source]¶ Set an emotion with random index in defined expression list, within a certain time. Or set all dofs to a random position between -1 and 1.
Parameters: - all_random (bool) – all dofs random or not
- anim_time (float) – time to set the emotion
-
opsoro.robot¶
This module defines the interface for communicating with the robot.